Print Page | Close Window

File LISP

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DXF formats, Design Review, AutoCAD web, Drive, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=13848
Printed Date: 05.Sep.2026 at 00:45


Topic: File LISP
Posted By: SAGGIAAAA
Subject: File LISP
Date Posted: 24.May.2023 at 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.



Replies:
Posted By: Kent Cooper
Date Posted: 24.May.2023 at 14:29
Originally posted by SAGGIAAAA SAGGIAAAA wrote:

.... it should be placed on the "Defpoint" layer. ....

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.



Print Page | Close Window