Display full version of the post: File LISP

SAGGIAAAA
24.05.2023, 10:25
Hello, I wrote a .lsp code to make my work easier, but unfortunately I'm unable to get it to work properly. Does anyone know how to resolve this? I'm attaching the code.(defun c:ComandName(/ sel ss blk obj)  (defun ename->vla-object (ename)    (if (not (vlax-dump-object ename))      (vlax-ename->vla-object ename)      (vl-catch-all-error-p nil        (vl-catch-all-apply 'vla-get-object          (list (vlax-ename->vla-object ename))        )      )    )  )  (setq sel (ssget "_X" '((0 . "INSERT"))))  (if sel    (progn      (setq blk (ename->vla-object (ssname sel 0)))      (vla-put-layer blk "0")      (vla-put-color blk (vla-get-property blk 'Color))      (vla-put-linetype blk (vla-get-property blk 'Linetype))      (setq sel (ssget "_X" '((0 . "TEXT")) (list (cons 2 (strcat "\\A" "\\*U")))))      (if sel        (command "._CHPROP" sel "" "c" "" "Yellow" "")      )      (setq sel (ssget "_X" '((0 . "TEXT")) (list (cons 2 "A"))))      (if sel        (command "._CHPROP" sel "" "la" "" "Defpoint" "")      )      (setq sel (ssget "_X" '((0 . "POINT"))))      (if sel        (command "._CHPROP" sel "" "la" "" "Defpoint" "")      )      (command "SCALE" "All" "" "0,0" "1:1" "mm" "" "No" "")      (command "._EXPLODE" sel)    )  )  (princ))The code must: open the selected block(s), move all objects to layer 0 with the color "DaBlocco," thickness "DaBlocco," and line type "DaBlocco." Then, select only the text/annotations within the block and set their color to yellow. If the text is an "A," it should be placed on the "Defpoint" layer. Additionally, select the points contained within the block and move them to the "Defpoint" layer. Finally, set the block's scale to "millimeters" and allow for exploding the block. As a final step, automatically close the block. All of this should be done without any action required from you except for activating the command after selecting the blocks to be edited. thanks to all who will help me.

Kent Cooper
24.05.2023, 14:29
[QUOTE=SAGGIAAAA].... it should be placed on the "Defpoint" layer. ....
[/QUOTE]
The Layer name has an s on the end, which may explain your problem [I did not analyze other things -- there may be more issues].  BUT DON'T USE THAT LAYER FOR THIS PURPOSE!  It has a special purpose in AutoCAD, and is not for Users to involve themselves with.  The use of it for things to not Plot dates back to the days [very long ago now] when that was the only Layer that didn't Plot.  But for many years now you can designate any Layer to not Plot.  So make a non-Plotting Layer for the purpose, and give it a name that has some meaning in relation to what it's for.