Does anyone know if LISP can be used to edit a diesel expression in a field inserted in dtext? I need to adjust the last number in $(+, $(GETVAR, USERI2),1) .
I just tried it and I would have to say no. When I pullout the assoc for the text, I get the final expression and not the code text. If the code text was able to retreived I would imagine the diesel expression could be changed.
You could use something like this to retrieve the field code:
(defun LM:FieldString ( en / fl id ) (cond ( (and (wcmatch (cdr (assoc 0 (setq en (entget en)))) "TEXT,MTEXT,ATTRIB") (setq en (cdr (assoc 360 en))) (setq en (dictsearch en "ACAD_FIELD")) (setq en (dictsearch (cdr (assoc -1 en)) "TEXT")) (setq fl (entget (cdr (assoc 360 en)))) ) (if (vl-string-search "\\_FldIdx " (cdr (assoc 2 en))) (vl-string-subst (if (setq id (cdr (assoc 331 fl))) (vl-string-subst (strcat "ObjId " (itoa (vla-get-objectid (vlax-ename->vla-object id)))) "ObjIdx 0" (cdr (assoc 2 fl)) ) (cdr (assoc 2 fl)) ) "\\_FldIdx 0" (cdr (assoc 2 en)) ) (cdr (assoc 2 en)) ) ) ) )
(vl-load-com)
Supply it with the Entity name of the Text/MText/Attrib containing the field, e.g.:
(LM:FieldString <EntityName>)
Thanks! That works great. Next question: How do use entmod to revise the original expression? I see that the variable fl contains the diesel expression under both assoc 2 and 1. Do both need to be modified! I can manage to replace those values in fl, but how do you modify the original string entity? (Sorry, new programmer here.)
Here's what I have so far:
!fl
((-1 . <Entity name: 7efab1b8>) (0 . "FIELD") (330 . <Entity name: 7efab1b0>)
(5 . "1BC7") (100 . "AcDbField") (1 . "AcDiesel") (2 . "\\AcDiesel $(+,
$(GETVAR, USERI2), 0)") (90 . 0) (97 . 0) (4 . "") (91 . 63) (92 . 0) (94 . 59)
(95 . 2) (96 . 0) (300 . "") (93 . 1) (6 . "DieselExpression") (90 . 4) (1 .
"$(+, $(GETVAR, USERI2), 0)") (7 . "ACFD_FIELD_VALUE") (90 . 4) (1 . "29") (301
. "29") (98 . 2))
(setq d (assoc 2 fl))
(setq d1 (cons 2 dm)); dm=modified diesel expression
(setq fm (subst d1 d fl))
(entmod fm)
!fm
((-1 . <Entity name: 7efab1b8>) (0 . "FIELD") (330 . <Entity name: 7efab1b0>)
(5 . "1BC7") (100 . "AcDbField") (1 . "AcDiesel") (2 . "%<\\AcDiesel $(+,
$(GETVAR, USERI2), 1)>%") (90 . 0) (97 . 0) (4 . "") (91 . 63) (92 . 0) (94 .
59) (95 . 2) (96 . 0) (300 . "") (93 . 1) (6 . "DieselExpression") (90 . 4) (1
. "$(+, $(GETVAR, USERI2), 0)") (7 . "ACFD_FIELD_VALUE") (90 . 4) (1 . "29")
(301 . "29") (98 . 2))
Thanks for your help.
More accurately, here's what I have so far:
(setq run 1)
(setq i 0)
(setq delta (getint "\nEnter delta value for each sheet number: "))
(prompt "\nSelect sheet numbers to revise: ")
(setq nset (ssget '((0 . "TEXT")(8 . "SHEET-VIEW"))))
(if nset
(setq nn (sslength nset))
(setq run nil)
); end if
(while (< i nn)
(setq ntxt (entget (ssname nset i)))
(setq en (cdr (assoc -1 ntxt)))
(lm:fieldstring en)
(setq d (assoc 2 fl))
;next line not complete
(setq dm ( )); replace "), *)" with "), *+delta)"
(setq d1 (cons 2 dm)); dm=modified diesel expression
(setq fm (subst d1 d fl))
(entmod fm)