Hi guys,
Is that possible to have a lisp to extract the Field Expression of a attribute in a block?
Specifically, to extract the property VALUE (TextString) of this attribute.
After to extract, I would like to put this text extracted in a different layout tab, in the same drawing. In this way, I will have a text linked to the attribute value between two layout tabs. So, when I have to change the attribute value, the text will be updated automatically.
I know that if I use the FIELD command to manually copy and paste this value it will work, but when I have a lot of attributes it becomes very laborious.
Thanks for any help!
Marcelo
Solved! Go to Solution.
Yes it is possible!! After quite a bit of digging, research, and trial and error, I came up with the attached test application. The application extracts and prints to text screen a Field Expression for a Field that is inserted into a Text or MText entity, or Attribute Definition that is within a block. The format of the Field Expression is slightly different than what you would see in the Field dialog box due to syntax requirments for LISP. The application is only setup to handle one Field per entity, however can handle multiple Attributes within the same block. It is also only setup to pick a single entity. It perhaps can be better written, but I do not have much experience extracting information from AutoCAD Object dictionaries. Maybe somebody else can enlighten me.
I found the following two forum discussions that where a great help in providing some clues and code regarding the topic, although their discussions seem to focus more on creating field expressions. So Kudos to the folks that posted on the following:
field expressions in lisp
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/field-expressions-in-lisp/td-p/183381...
Updating Lisp Variable
http://forums.augi.com/showthread.php?t=114016
Anyway, I think my application will at least get you started. It essentially accomplishes the first half of what I think you are trying to do. As far as the second half, I think that you can take what I did and look at the forum postings mentioned above for possible guidance.
I would be interested in seeing what you finally come up with. I will be unavailable for the next few days, but if you have a question about what I did or something related, go ahead and post it and I will look at it later. Or perhaps some one else can address the question or has some thoughts.
Hi Gavin Rouleau,
Thanks for the lisp but when I try I get this:
Select Text, MText, or Attributed Block with Field Expression:
; error: bad argument type: lentityp nil
I do not know if it matters, but I have Autocad Architecture 2012
Marcelo
Yes, it might matter. I do not have AutoCAD Architecture 2012, so cannot test it out on that platform. I do notice that if you do not actually select an entity that you get that error, so make sure the object is highlighted when you select it. I attached a revised version of the application to force you to select an entity, but it still has to be the correct type of object. So try the attached version instead.
Otherwise, post a dwg file with an Attributed Block that you are trying to read the fields from, and I'll see if I get the same error on Civil 3D 2012 or try to see what is going on.
The lisp program is not meant to catch all errors or be all inclusive, so you have to select the correct type of entity otherwise it will probably give you an error.
A couple of side thoughts, before calling it a weekend.
Not sure what sort of Field entries you are dealing with, but you may be able to get the functionality you are looking for in other ways. Have you considered creating a attributed block library, or a template file that incorporates the attributed blocks into a layout that you reuse and perhaps Sheet Set Manager functionality? Just some other thoughts. Again, not sure what it looks like on the AutoCAD Architectural end but perhaps those are some other built-in ideas you could utilize.
Thanks Gavin for the ideas , but I do not want to use Sheet Set Manager. I am doing this because I realy would like to try another way.
After to try in AutoCAD Architecture, I tryed your lisp in normal AutoCAD 2012 and it still does not works.
I attached the drawin with the attribute in the block.
Thanks again,
Marcelo
Having the drawing file definitely helps. Thanks.
In your drawing:
So, taking all that into account I modified the application and renamed it to do the following:
So you can discard the first two getfield.lsp applications, and use the attached GetAttFieldRefObjID.lsp instead. It should allow you to select the Block or MText entities in your file. If it is still not working on your end, I do not know why because it works on this end with your file.
Hopefully, the new application is more straight forward and user friendly, and shows that the Field Expressions can be extracted in addition to other information. Again it is just meant to be a test application and example of how to get the information you seek. I know there is a lot of detail in my posting, but the task is pretty involved.
As far as utilizing the information, I think that is still up to you on how you would go about it, and how you would approach it from a coding standpoint. If you haven't got familiar with AutoLisp or Visual Lisp, maybe it is a good time, although this is a complicated example to start out with. I also found an additional forum discussion that may be of some help in addition to the others referenced previously:
How to get the 'Object ID' of a block while inserting.
http://forums.augi.com/showthread.php?t=96776
I corrected an error in the latest application, and also modified it to be able to handle multiple non-attributed text entities with field expressions inserted within the same block. So see the modified application attached.
This has been interesting digging into your request, and have learned a lot about the AutoCAD entity database. Hopefully it works for you and is some help in your endeavors.
Hi Gavin,
I'm a little embarrassed because I see you're working hard and I guess I'm not getting me explain.
The %<\AcObjProp Object(%<\_ObjId 2128078928>%).TextString>% is exactly what I want to extract from each block attribute, because when I paste this associated expression in the drawing I have a link that I want.
Take a look in the dwg file attached and see how this is interesting: If I change the text in the attribute, for exemple in A01 I will change "Site plan" for "Site plan and specifications", the text linked in the page A00 wil update automatically
Even if the attribute has a FIELD, like in the "Drawing page" I used the ctab Sistem Variable , I copy and paste it's associated expression, I got the desired result.
So, I would like to have the expression associated with the Field that I see in the FIELD dialog box.
For example,
in the page A01, for Drawing name is %<\AcObjProp Object(%<\_ObjId 2129148816>%).TextString>%
In the page A02, for Drawing name is %<\AcObjProp Object(%<\_ObjId 2129148928>%).TextString>%
and so on.
So, after to extract this expression associated, I will put this value in a different layout tab to build my drawing list, like I made in page A00.
However, I'm glad because despite all the work you made, at least you have learned a lot about the AutoCAD entity database.
Thanks and have a nice day!
Marcelo
No worries. I get into this kind of thing and want to satisfy my own curiosity on how things work and whether it can be done.
Yes, I understand that you are linking objects through Fields, but perhaps I did not understand that you are trying to "Construct" a Field Expression not "Extract" a Field Expression?
So back to a field expression like %<\AcObjProp Object(%<\_ObjId 2128078928>%).TextString>%. The application I put together will list something like the following when you click "Site Plan" on your A00 tab (although the Object ID will be different):
Field Expression of Text Value "Site plan":
\AcObjProp Object(%<\_ObjIdx 0>%).TextString
Object ID of Object Referenced in Field Expression: 2129431440
Are you at least seeing that on your end, or is it not working at all? I know it may not be doing what you want, but does it run and give output to the text screen? Otherwise, no need in me continuing.
I see that maybe what you want to do is click on "Site Plan" on say the A01 tab, and construction a Field Expression based upon that entity, not extract an expression as there is not an expression to extract. So you really would need to extract the Object ID and then concatenate a Field Expression that includes that Object ID. I think this is probably possible as well, but would need to give it a try. Does that make sense??
Since all this is fresh on my mind, I went ahead and proceeded with my latest thoughts.
Alright, so I put together a Construct Field application as described in my previous posting that actually extracts an Object ID of a Block Attribute and constructs a Field Expression with that Object ID, and then allows you to create a MText Object on Layout A00 that has the Field Expression Inserted in the MText. Sound like I got it this time?
Anyway try the following with your FielBetweenTabs.dwg:
Hopefully that worked for you. You could conceivably get fancier and somehow select multiple Block Attributes and build a Drawing List or Table of Contents, or possibly automate the whole selection and building process.
This is exactly what I wanted! The ConstructField.lsp routine works perfectly for my purposes. Thank you very much!
I'd like to apologize for having used the wrong term. You have reason, I should have asked for "Construct" a Field Expression, or, like you said, for a lisp to extracts an Object ID of a Block Attribute and constructs a Field Expression with that Object ID.
Since now we are on track, I would like to ask a question:
When you said: "The application automatically switches to the the A00 Layout tab. (could be changed or prompted for)"
Is that possible to be promped for?
Perhaps the lisp routine could show a dialog box with a list of all layouts in the drawing, and then I could pick one of them. This is just an idea because I saw this on another lisp routine here in the Discussion Groups and it would be possible.
I ask this because in some projects, my first layout tab has a different name than A00.
Well, I would like to thank you again for the great job.
Marcelo
Great. Glad we finally got something that works for you and essentially does what you want it to do.
Well, sometimes it is cumbersome communicating by non-verbal means, and not always the best way to get a clear understanding of what each other is talking about. So as I said, no worries. I am now much more versed on the topic, so even though I went down some paths of knowledge that I really didn't need to for the final outcome, they are still items that are valuable to know.
The attached lisp has been modified to prompt you to enter a Layout tab name. While you could undoubtly design a dialog control box to select the layout tab, this is another undertaking that I am not going to get into right now.
So good luck with it. Don't be afraid to learn Lisp or perhaps .NET, if you have not got into it before.
You're welcome,
Hi, thanks so much for the useful script. I'm using this to try to auto-generate my sheet index. Is there anyway I could get it to output to a cell in a table instead of an mtext object?
Thank you for your time.
Can't find what you're looking for? Ask the community or share your knowledge.