Display full version of the post: Help With Lisp

mfkozlow
13.08.2014, 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!

Vladimir Michl
13.08.2014, 20:34

Try to replace the lines: [CODE](if (setq ent(entsel "\n Select a Block: "))(progn(setq en(car ent))   [/CODE] with: [CODE](if (setq ss (ssget "_X" '((0 . "INSERT")(2 . "MYBLOCKNAME"))))(progn   (setq en (ssname ss 0))[/CODE]

mfkozlow
13.08.2014, 20:52
Thank you for the quick reply! 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.

mfkozlow
14.08.2014, 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!

Vladimir Michl
14.08.2014, 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.