Code Red > AutoLISP (Vanilla / Visual)
Should I be using "IF"
jlogan02:
My thinking is flawed here, somehow.
Using this...
--- Code - Auto/Visual Lisp: ---(if (this is true) (then do this) (else do this when false))
(If
dimscale is 8
and
objects exist at this location
and
on any layer starting with "TEXT"
do change)
(objects exist at this location
and
on any layer starting with "TEXT"
do change)
)
--- Code - Auto/Visual Lisp: ---(if (= (getvar 'dimscale) 8) (setq ref1 (ssget "c" '(268.5 171.0) '(254.25 42.125) '((8 . "Text*")))) (command "._change" ref1 "" "p" "la" "Text2" "")) (setq ref1 (ssget "c" '(33.375 21.375) '(31.875 5.375) '((8 . "Text*")))) ) (command "._change" ref1 "" "p" "la" "TBLK_TBLK_REFTEXT" "")
My problem is, what if it nothing exists? There is more code after this that runs fine, but I get...
--- Quote ---Command: STA_STD
STA_STD
Working, please wait... Regenerating model.
Unknown command "P". Press F1 for help.
Unknown command "LA". Press F1 for help.
Unknown command "TBLK_TBLK_REFTEXT". Press F1 for help.
Unknown command "STA_STD". Press F1 for help.
Unknown command "STA_STD". Press F1 for help.
--- End quote ---
when I change everything from Layer TEXT* to Layer TBLK_TBLK_REFTEXT
Am, I using "IF" properly (clearly not, you say) and how do I account for nothing being found?
J. Logan
JohnK:
Use COND.
http://www.theswamp.org/Sources/doc/avlisp/#cond
ronjonp:
You can also do something like this:
--- Code - Auto/Visual Lisp: ---(if (and (= (getvar 'dimscale) 8) (setq ref1 (ssget "c" '(268.5 171.0) '(254.25 42.125) '((8 . "Text*")))) ) (command "._change" ref1 "" "p" "la" "Text2" "") (and (setq ref1 (ssget "c" '(33.375 21.375) '(31.875 5.375) '((8 . "Text*")))) (command "._change" ref1 "" "p" "la" "TBLK_TBLK_REFTEXT" "") ))
MP:
If I understood correctly and assuming there's no need to ensure layers exist perhaps this --
--- Code: ---(if
(or
(and
(eq 8 (getvar 'dimscale))
(setq ss (ssget "c" '(268.5 171.0) '(254.25 42.125) '((8 . "Text*"))))
(setq layer "Text2")
)
(and
(setq ss (ssget "c" '(33.375 21.375) '(31.875 5.375) '((8 . "Text*"))))
(setq layer "TBLK_TBLK_REFTEXT")
)
)
(command "._change" ss "" "p" "la" layer "")
)
--- End code ---
Cheers.
MP:
A different variant exploiting setq's behavior (return last value assigned):
--- Code: ---(if
(or
(and
(eq 8 (getvar 'dimscale))
(setq
layer "Text2"
ss (ssget "c" '(268.5 171.0) '(254.25 42.125) '((8 . "Text*")))
)
)
(setq
layer "TBLK_TBLK_REFTEXT"
ss (ssget "c" '(33.375 21.375) '(31.875 5.375) '((8 . "Text*")))
)
)
(command "._change" ss "" "p" "la" layer "")
)
--- End code ---
Fixed via mobile so may still be fubar’d.
Navigation
[0] Message Index
[#] Next page
Go to full version