Nikon Posted Wednesday at 06:40 PM Posted Wednesday at 06:40 PM (edited) There are several fields with 1 decimal place. Is there a way to convert selected fields with 1 decimal place into fields with 2 decimal places without losing the connection of fields with objects? The field is 1 decimal place %<\AcExpr (3.1416*%<\_FldPtr 1317270971888>%^2/4*0.0785*%<\_FldPtr 1317270971632>%*%<\_FldPtr 1317270971472>%/10000) \f "%lu2%pr1">% The field is 2 decimal places %<\AcExpr (3.1416*%<\_FldPtr 1317157078864>%^2/4*0.0785*%<\_FldPtr 1317157078096>%/10000) \f "%lu2%pr2">% fields.dwg Edited 18 hours ago by Nikon Quote
Steven P Posted Wednesday at 10:30 PM Posted Wednesday at 10:30 PM "pr2" is precision - here 2 places, "pr1" at the end of the first expression is 1 decimal place 1 Quote
Nikon Posted yesterday at 06:37 AM Author Posted yesterday at 06:37 AM (edited) 15 hours ago, Steven P said: "pr2" is precision - here 2 places, "pr1" at the end of the first expression is 1 decimal place I have dozens of fields that need to be changed the precision. It will take a long time to edit each field... Edited 18 hours ago by Nikon Quote
BIGAL Posted 23 hours ago Posted 23 hours ago (edited) If you can identify where the field strings are then you could update them, you can look for say "AcExpr" in the string then replace pr1. Maybe use Bedit and Attsync to update blocks. Similar for Mtext. So where are they ? Provide a sample dwg, You should be able to do something by now look at (Vlax-get obj 'textstring) Edited 23 hours ago by BIGAL Quote
Nikon Posted 23 hours ago Author Posted 23 hours ago 23 minutes ago, BIGAL said: So where are they ? Provide a sample dwg, The fields are in the text, not in the block. The sample fields.dwg is attached in the first post. The problem is that you need to change the accuracy of several fields at the same time. Quote
Tsuky Posted 20 hours ago Posted 20 hours ago You can try this. (vl-load-com) (defun c:change_prec ( / ss AcDoc Space n ename Obj value_string nbs tmp_nbs) (princ "\nSelect MText.") (while (null (setq ss (ssget (list '(0 . "*TEXT") (cons 67 (if (eq (getvar "CVPORT") 1) 1 0)) (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model")) ) ) ) ) (princ "\nAren't MText or Text!") ) (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)) Space (if (= 1 (getvar "CVPORT")) (vla-get-PaperSpace AcDoc) (vla-get-ModelSpace AcDoc) ) ) (vla-startundomark AcDoc) (repeat (setq n (sslength ss)) (setq ename (ssname ss (setq n (1- n))) Obj (vlax-ename->vla-object ename) ) (setq value_string (vla-FieldCode Obj) nbs 0) (cond ((eq (substr (vla-FieldCode Obj) 1 3) "%<\\") (while nbs (if (setq nbs (vl-string-search "%pr2" value_string (setq tmp_nbs nbs))) (setq value_string (vl-string-subst "%pr1" "%pr2" value_string tmp_nbs) nbs (1+ nbs) ) ) ) (vlax-put Obj 'TextString value_string) ) ) ) (vla-endundomark AcDoc) (prin1) ) 2 Quote
Nikon Posted 19 hours ago Author Posted 19 hours ago (edited) 8 hours ago, Tsuky said: You can try this. (vl-load-com) (defun c:change_prec @Tsuky thank you very much, your code changes the precision of the fields from 2 to 1. I replaced 2 lines in the code to change the precision from 1 to 2. (if (setq nbs (vl-string-search "%pr2" value_string (setq tmp_nbs nbs))) (setq value_string (vl-string-subst "%pr1" "%pr2" value_string tmp_nbs) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * (if (setq nbs (vl-string-search "%pr1" value_string (setq tmp_nbs nbs))) (setq value_string (vl-string-subst "%pr2" "%pr1" value_string tmp_nbs) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * You've been very helpful! Edited 12 hours ago by Nikon 1 Quote
Nikon Posted 17 hours ago Author Posted 17 hours ago 2 hours ago, Tsuky said: You can try this. (vl-load-com) (defun c:change_prec I have made several versions of the change_prec.lsp code. Maybe it will be useful to someone. Changing the precision of several fields =========================================================== change_prec_1-2.lsp === changing the precision of the fields from 1 to 2 change_prec_1-3.lsp === changing the precision of the fields from 1 to 3 change_prec_2-1.lsp === changing the precision of the fields from 2 to 1 change_prec_2-3.lsp === changing the precision of the fields from 2 to 3 change_prec_3-1.lsp === changing the precision of the fields from 3 to 1 change_prec_3-2.lsp === changing the precision of the fields from 3 to 2 =========================================================== change_prec_fields.lsp 1 Quote
mhupp Posted 16 hours ago Posted 16 hours ago (edited) Added a little on the front end to wrap it all in one command with user input options. Should display something like this Change_Prec or CP Enter "C" for Custom Values Choose Percision From:To : [1:2 1:3 2:1 2:3 3:1 3:2]: 3:2 Changing Select MText Precision From [3] to [2] ... Change_Prec or CP Enter "C" for Custom Values Choose Percision From:To : [1:2 1:3 2:1 2:3 3:1 3:2]: C Existing Precision: 1 Precision Change to: 4 Changing Select MText Precision From [1] to [4] ... Change_Prec 2 1 Changing Select MText Precision From [2] to [1] ... -Edit Updated it so you can just type "Change_Prec 3 2" and skip all that and just start asking you to make a selection. Edited 9 hours ago by mhupp 1 Quote
Nikon Posted 16 hours ago Author Posted 16 hours ago (edited) 2 hours ago, mhupp said: Added a little on the front end to wrap it all in one command with user input options. Should display something like this Thanks, that's a good idea, but this code doesn't work for me. Edited 14 hours ago by Nikon Quote
mhupp Posted 16 hours ago Posted 16 hours ago (edited) I'll have to debug it when i get home just typed it up in note pad. -Edit Well if i took two seconds to look at the code. was using integers and needs to be strings. because Tusky is calling vl-string-subst. if its still bugged ill fix it tonight. Edited 15 hours ago by mhupp 1 1 Quote
Tsuky Posted 10 hours ago Posted 10 hours ago (edited) With (initget) and (getkword) for choice precision... (vl-load-com) (defun c:change_prec ( / ss AcDoc Space prec_source ktarget n ename Obj value_string nbs tmp_nbs) (princ "\nSelect MText.") (while (null (setq ss (ssget (list '(0 . "*TEXT") (cons 67 (if (eq (getvar "CVPORT") 1) 1 0)) (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model")) ) ) ) ) (princ "\nAren't MText or Text!") ) (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)) Space (if (= 1 (getvar "CVPORT")) (vla-get-PaperSpace AcDoc) (vla-get-ModelSpace AcDoc) ) ) (vla-startundomark AcDoc) (initget 1 "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Current") (setq ktarget (getkword "\nPrecision of target number [0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/Current]?: ")) (repeat (setq n (sslength ss)) (setq ename (ssname ss (setq n (1- n))) Obj (vlax-ename->vla-object ename) ) (setq value_string (vla-FieldCode Obj) nbs 0) (cond ((vl-string-search "%<\\" value_string nbs) (while nbs (if (setq nbs (vl-string-search "%pr" value_string (setq tmp_nbs nbs))) (setq prec_source (itoa (atoi (substr value_string (+ nbs 4) 2))) value_string (vl-string-subst (if (eq ktarget "Current") (strcat "%pr" (itoa (getvar "LUPREC"))) (strcat "%pr" ktarget) ) (strcat "%pr" prec_source) value_string tmp_nbs ) nbs (1+ nbs) ) ) ) (vlax-put Obj 'TextString value_string) ) ) ) (vla-endundomark AcDoc) (prin1) ) Edited 9 hours ago by Tsuky Introduces current accuracy and search in mtext 1 1 Quote
Nikon Posted 10 hours ago Author Posted 10 hours ago (edited) 45 minutes ago, Tsuky said: With (initget) and (getkword) for choice precision... (vl-load-com) (defun c:change_prec ( / ss AcDoc Space ksource ktarget n ename Obj value_string nbs tmp_nbs) For some reason, the code only works in Text. When selecting MText, the precision does not change... Is it possible to assign the same precision or current precision to fields with different precision? Edited 10 hours ago by Nikon Quote
Tsuky Posted 9 hours ago Posted 9 hours ago I've modified my latest code to introduce current precision and search in the Mtext 1 Quote
mhupp Posted 8 hours ago Posted 8 hours ago K updated my code as well. tho this seems to not work well with BricsCAD. moved the vlax-put to only update when the if statment is true. change_prec_fields_update.lsp 1 Quote
BIGAL Posted 8 hours ago Posted 8 hours ago (edited) @mhupp this may be useful, it captures command errors so after loading your lisp. You type say p2-3 on command line. Can do say p1-2, Pr3-2, prec1-0 and so on. ; test trap a command used as variable input ; BY Alan H 2019 ; now 2025 ( (lambda nil (vl-load-com) (foreach obj (cdar (vlr-reactors :vlr-command-reactor)) (if (= "fillet-reactor" (vlr-data obj)) (vlr-remove obj) ) ) (vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback))) ) ) (defun fillet-reactor-callback ( obj com ) (setq com (car com)) (alert com) ; do the split com into ; (Change_Prec X X)) ) ; defun (or fillet-reactor-acdoc (setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object))) ) Thinking more maybe only check p12, prec10 Edited 8 hours ago by BIGAL 1 Quote
Nikon Posted 57 minutes ago Author Posted 57 minutes ago (edited) 8 hours ago, Tsuky said: I've modified my latest code to introduce current precision and search in the Mtext Thanks, the code works perfectly with the Texts, I didn't even think it was possible. But nothing works with the MText. I choose the MText, I choose "Precision of target number", but the precision does not change. If the code is applied to the MText, then after that the MText cannot be copied and pasted into another drawing. change_prec_fields.dwg Edited 48 minutes ago by Nikon Quote
Nikon Posted 50 minutes ago Author Posted 50 minutes ago 8 hours ago, mhupp said: K updated my code as well. tho this seems to not work well with BricsCAD. moved the vlax-put to only update when the if statment is true. Thanks, the code works with the Texts. I changed the selection line a bit. (setq choice (getkword "\nChoose Percision From:To : [1:2/1:3/2:1/2:3/3:1/3:2]: ")) But nothing works with the MText. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.