sadhu Posted March 17, 2010 Share Posted March 17, 2010 I got most of the code below from here What I am trying to do is read the attribute value and tag from a block (the block has multiple attributes). When I (princ) it, it returns nil. What am I doing wrong ? thanks (defun c:sk (/) (if (setq ent(entsel "\n Select a Block: ")) ;- Let the user select a block (progn (setq en(car ent)) ;- Get the entity name of the block (setq enlist(entget en)) ;- Get the DXF group codes (setq blkType(cdr(assoc 0 enlist))) ;- Save the type of entity (if (= blkType "INSERT") ;- If the entity type is an Insert entity (progn (if(= (cdr(assoc 66 enlist)) 1) ;- See if the attribute flag equals one (if so, attributes follow) (progn (setq en2(entnext en)) ;- Get the next sub-entity (setq enlist2(entget en2)) ;- Get the DXF group codes (while (/= (cdr(assoc 0 enlist2)) "SEQEND") ;- Start the while loop and keep (princ "\n ") ;-Print a new line (princ enlist2) ;- Print the attribute DXF group codes (setq en2(entnext en2)) ;- Get the next sub-entity (setq enlist2(entget en2)) ;- Get the DXF group codes ) ) ) ;- Close the if group code 66 = 1 statement ) ) ;- Close the if block type = "ATTRIB" statement ) ) ;- Close the if an Entity is selected statement [color=Red](setq att_value (cdr (assoc 1 enlist2))) (princ "\nAtt_value : ") (princ att_value) (setq att_tag (cdr (assoc 2 enlist2))) (princ "\nAtt_tag : ") (princ att_tag) [/color] ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 17, 2010 Share Posted March 17, 2010 Perhaps: (defun c:sk (/ dxf ent) (defun dxf (code ent) (cdr (assoc code (entget ent)))) (if (and (setq ent (car (entsel "\nSelect an Attributed Block: "))) (eq "INSERT" (dxf 0 ent)) (= 1 (dxf 66 ent))) (while (not (eq "SEQEND" (dxf 0 (setq ent (entnext ent))))) (princ (strcat "\n\nAtt_Tag:" (dxf 2 ent) "\nAtt_Value: " (dxf 1 ent))))) (princ)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 17, 2010 Share Posted March 17, 2010 What a strange thing to list. This information can be seen by double-clicking on the attributed block and looking at that editor. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 17, 2010 Share Posted March 17, 2010 What a strange thing to list. This information can be seen by double-clicking on the attributed block and looking at that editor. I think it's more of a learning exercise Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 17, 2010 Share Posted March 17, 2010 I think it's more of a learning exercise Perhaps, it just seemed odd. Quote Link to comment Share on other sites More sharing options...
sadhu Posted March 18, 2010 Author Share Posted March 18, 2010 I just read the posts. Thanks Lee for your code. It is what I wanted to do. Now I have to study all of your code because what I have to do to is even more complex. All the posts I have made serve for the same project. Anyway I have started. Now I need to transfer these att_value to another block (the block isn't on the drawing yet). So I have to call this block "RH" change its att_value (replace them with the ones just read and place it on the drawing. So you see, it is learning and exercise though it may seem odd. Maybe what I ask is so simple to you guys that it seems odd. Both of you are of great help. Quote Link to comment Share on other sites More sharing options...
sadhu Posted March 24, 2010 Author Share Posted March 24, 2010 Can you add another feature to your code that can read and extract sub-entity ( I mean blocks inside blocks - one level) tags, values and prints them. sub-entity-1 name : xxx sub-entity-1 tag: xxx sub-entity-1 value : xxx .... (defun c:sk (/ dxf ent) (defun dxf (code ent) (cdr (assoc code (entget ent)))) (if (and (setq ent (car (entsel "\nSelect an Attributed Block: "))) (eq "INSERT" (dxf 0 ent)) (= 1 (dxf 66 ent))) (while (not (eq "SEQEND" (dxf 0 (setq ent (entnext ent))))) (princ (strcat "\n\nAtt_Tag:" (dxf 2 ent) "\nAtt_Value: " (dxf 1 ent))))) (princ)) Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2010 Share Posted March 24, 2010 Not a simple addition, you would have to dig into the block definition for that. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2010 Share Posted March 24, 2010 Check this by CAB Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 25, 2010 Share Posted March 25, 2010 You can definately change the values of one block but pick another block to get the values. You just need to know the name of each block your working with. We do something like your asking pick a block on the layout (model space) it then updates another block with information from the model the other block can be anywhere in the total Autocad dwg usually in a layout tab. It reads the displayed attributes as a common ID link Quote Link to comment Share on other sites More sharing options...
sadhu Posted March 25, 2010 Author Share Posted March 25, 2010 Check this by CAB Thank you for the link.I managed to work it out by inserting this : (if (and (= (cdr (assoc 0 data)) "ATTRIB") (= (cdr (assoc 2 data)) "NO") ; just a tag ) (setq att_value (cons (dxf 1) att_value)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 25, 2010 Share Posted March 25, 2010 It was more of a reference for you to see the structure of different blocks, so that it is easier for you to see how to modify them, but each to their own I suppose. Quote Link to comment Share on other sites More sharing options...
sideyb Posted March 23, 2012 Share Posted March 23, 2012 Hey Sadhu, I am facing the exact same sort of problem and I was curious how yours went? I would love to check out your code if possible. Feel free to PM me, for some reason it wouldn't let me send you a message. Thanks, Ben Quote Link to comment Share on other sites More sharing options...
sideyb Posted March 26, 2012 Share Posted March 26, 2012 Hey Sadhu is there any chance I could check out your code for this problem? I'm having the same issue. Thanks. You can email me below. enjaminb@yahoo.com Quote Link to comment Share on other sites More sharing options...
LATINU30 Posted November 15, 2012 Share Posted November 15, 2012 Greetings to all, I need a little help I RELATED TO A LISP EXTRACTION attributes in dynamic blocks meet a certain geometry TABLE (EXAMPLE 190X500) and does not change when I try to update the table. Quote Link to comment Share on other sites More sharing options...
sadhu Posted November 15, 2012 Author Share Posted November 15, 2012 Have a look at this http://www.lee-mac.com/attributefunctions.html http://www.lee-mac.com/countattributevalues.html http://www.lee-mac.com/nestedblockcounter.html Quote Link to comment Share on other sites More sharing options...
sadhu Posted November 15, 2012 Author Share Posted November 15, 2012 This too Quote Link to comment Share on other sites More sharing options...
dpolsky Posted September 19, 2014 Share Posted September 19, 2014 Perhaps: (defun c:sk (/ dxf ent) (defun dxf (code ent) (cdr (assoc code (entget ent)))) (if (and (setq ent (car (entsel "\nSelect an Attributed Block: "))) (eq "INSERT" (dxf 0 ent)) (= 1 (dxf 66 ent))) (while (not (eq "SEQEND" (dxf 0 (setq ent (entnext ent))))) (princ (strcat "\n\nAtt_Tag:" (dxf 2 ent) "\nAtt_Value: " (dxf 1 ent))))) (princ)) I know this is a 4 year old thread, but I was doing some Googling and this is almost what I need. We keep text data (program numbers, sheet call outs, etc) as blocks. And we use the attributes to populate them. We are trying to change how we are doing this, either by making a different/cleaner blocks or by changing to fields. I was hoping to write a LISP routine that would read the block and extract the fields, but instead of displaying them like this routine does, saving them for me to do something else with. I'm not great at LISP, I'm having trouble figuring out if you are storing the values anywhere, or if it reads it and it's gone? Thanks, Daniel Quote Link to comment Share on other sites More sharing options...
CheSyn Posted September 19, 2014 Share Posted September 19, 2014 What are your tag/attribute names, how many are there, and what are you looking to do with them? Quote Link to comment Share on other sites More sharing options...
dpolsky Posted September 19, 2014 Share Posted September 19, 2014 Tags: DDate Part Sheetsize Prgm Name Not sure what I'm going to do with them yet, I hadn't gotten that far, was just trying to figure out how to read them at this point. If I could grab the values of the Tags and then !Name and return the value of the Tag "Name" I would be in good shape to figure things out. Thanks, Daniel Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.