CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz] ARKANCE | CONTACT - CZ | SK | EN | DE
Over 1.096.000 registered users (EN+CZ). AutoCAD tips, Inventor tips, Revit tips. Try the new precise Engineering calculator and the updated Barcode generator. New AutoCAD 2026 commands and variables.
Plex.Earth connects AutoCAD and Google Earth
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

?
CAD discussions, advices, exchange of experience

CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.
This is a peer-to-peer forum. The forum doesn't replace the official direct technical support provided by ARKANCE for its customers.
How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedHelp With Lisp

 Post Reply Post Reply
Author
mfkozlow View Drop Down
Groupie
Groupie


Joined: 14.Jul.2014
Location: United States
Using: AutoCAD Electrical 2014
Status: Offline
Points: 25
Direct Link To This Post Topic: Help With Lisp
    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!

Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2120
Direct Link To This Post 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 - Autodesk Platinum Partner
Back to Top
mfkozlow View Drop Down
Groupie
Groupie


Joined: 14.Jul.2014
Location: United States
Using: AutoCAD Electrical 2014
Status: Offline
Points: 25
Direct Link To This Post 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.
Back to Top
mfkozlow View Drop Down
Groupie
Groupie


Joined: 14.Jul.2014
Location: United States
Using: AutoCAD Electrical 2014
Status: Offline
Points: 25
Direct Link To This Post 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
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2120
Direct Link To This Post 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 - Autodesk Platinum Partner
Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,070 seconds.