Print Page | Close Window

Help With Lisp

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=10621
Printed Date: 25.May.2026 at 13:54


Topic: Help With Lisp
Posted By: mfkozlow
Subject: Help With Lisp
Date Posted: 13.Aug.2014 at 20:23
Hello everyone!

I found some code (lisp) that will return a variable with the attribute value of a block. Everything works great, the block only has one attribute so it does not cause complications in this rather simple code. My problem is with the user input portion. After the code lisp is initiated, AutoCAD asks me to select the block I wish to extract the attribute value form. Ideally I would like this to happen automatically. I want the lisp to always check the same exact block that will be located in the same exact spot. If anyone knows a way please let me know! I have been working on this for way too long. Here is the lisp:

(defun C:get_att_now ()

(if (setq ent(entsel "\n Select a Block: "))

(progn                                                  

  (setq en(car ent))                                                       

  (setq enlist(entget en))                                        

  (setq blkType(cdr(assoc 0 enlist)))                

  (if (= blkType "INSERT")                                         

   (progn

    (if(= (cdr(assoc 66 enlist)) 1)   

    (progn

      (setq en2(entnext en))                                   

      (setq enlist2(entget en2))                          
   
      (setq enlist3(cdr(assoc 1 enlist2)))

      (while (/= (cdr(assoc 0 enlist2)) "SEQEND") 

        (princ "\n ")                                               

        (princ enlist2)                                              

        (setq en2(entnext en2))                            

        (setq enlist2(entget en2))                     

      )

     )

    ) 
   )

  )  

)

)  

)


Note: This is the code that causes user input...

(if (setq ent(entsel "\n Select a Block: "))

I have tried the "ssget" function, but haven't had any luck. Please help!




Replies:
Posted By: Vladimir Michl
Date Posted: 13.Aug.2014 at 20:34
Try to replace the lines:
 
(if (setq ent(entsel "\n Select a Block: "))
(progn
(setq en(car ent))  
 
with:
 
(if (setq ss (ssget "_X" '((0 . "INSERT")(2 . "MYBLOCKNAME"))))
(progn  
(setq en (ssname ss 0))


-------------
Vladimir Michl (moderator)
ARKANCE - https://arkance.world" rel="nofollow - https://arkance.world - Autodesk Platinum Partner


Posted By: mfkozlow
Date Posted: 13.Aug.2014 at 20:52
Thank you for the quick reply! Smile

Unfortunately this did not seem to work. When I run the command it returns "nil". If you need any other information let me know.


Also, how did you get the dotted lines for the code...just for future reference. I know this is a dumb question, but I'm new to forums. Thanks.


Posted By: mfkozlow
Date Posted: 14.Aug.2014 at 16:09
I solved this with help from Vladimir. Instead of using:
(2 . "MYBLOCKNAME")
I used this:
(8 . "LAYERNAME")
I simply put the block that I was extracting the attribute from on its own layer called "QSP".
Thank you again, you pointed me in the right direction!
Big smile


Posted By: Vladimir Michl
Date Posted: 14.Aug.2014 at 16:16
Great! I am glad it works for you.
 
The {CODE} section is inserted using BBcodes - see the help link here under the Message posting editor.


-------------
Vladimir Michl (moderator)
ARKANCE - https://arkance.world" rel="nofollow - https://arkance.world - Autodesk Platinum Partner



Print Page | Close Window