rustysilo Posted January 6, 2009 Posted January 6, 2009 For background see this thread. I want to begin my lisp with a macro to insert the block. I have this much: ^C^C_-i;area;\;;; That will get my block inserted, then it prompts for the attribute values. I want to insert the block and when it prompts for the attribute values I want to insert an object linked field that will link to my polyline and display the area of said polyline. It would be desired that the field also convert the area from square feet to square yards as that is the requirement on our cost estimates. Please help me write this lisp code to perform this function. Don't just do it all for me. I want to do one step at a time so I can learn and understand what is going on. I need a lisp tutor. Quote
MaxwellEdison Posted January 6, 2009 Posted January 6, 2009 Perhaps you should start by selecting the object to get the ObjID into a variable and then create the attribute with this string %%).Area \f "%lu2">%. Thats how AutoCAD sees fields, seperate it into two parts and place the ObjID variable between them. Again though I'm thinking more in terms of C# so I'm not exactly sure how the LISP will acoomplish this. Quote
ASMI Posted January 6, 2009 Posted January 6, 2009 I want to insert the block and when it prompts for the attribute values I want to insert an object linked field that will link to my polyline and display the area of said polyline. It easy task, but if you have multiple atributes require name of tag. This is simplified example. Pick some object which have Area property and pick Text, MText or Attribute (if attribute regen): (defun c:arf(/ fStr cObj vObj cTxt vTxt) (vl-load-com) (if (and (setq cObj(entsel "\nPick object with Area property > ")) (vlax-property-available-p (setq vObj(vlax-ename->vla-object(car cObj))) 'Area) ); end and (if (and (setq cTxt(nentsel "\nPick Text, MText or Attribute to insert field > ")) (vlax-property-available-p (setq vTxt(vlax-ename->vla-object(car cTxt))) 'TextString) ); end and (progn (vla-put-TextString vTxt (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa(vla-get-ObjectID vObj)) ">%).Area>%")) ); end progn ); end if ); end if (princ) ); end of c:arfield How many square yards in square feet (I don't know English Units)? It require to add formating string. Quote
MaxwellEdison Posted January 6, 2009 Posted January 6, 2009 There are 144 square inches in a square foot, 9 square feet in a square yard, and 1296 square inches in a square yard Quote
ASMI Posted January 6, 2009 Posted January 6, 2009 There are 144 square inches in a square foot, 9 square feet in a square yard, and 1296 square inches in a square yard Is this right formating? (defun c:arf(/ fStr cObj vObj cTxt vTxt) (vl-load-com) (if (and (setq cObj(entsel "\nPick object with Area property > ")) (vlax-property-available-p (setq vObj(vlax-ename->vla-object(car cObj))) 'Area) ); end and (if (and (setq cTxt(nentsel "\nPick Text, MText or Attribute to insert field > ")) (vlax-property-available-p (setq vTxt(vlax-ename->vla-object(car cTxt))) 'TextString) ); end and (progn (vla-put-TextString vTxt (strcat "%<\\AcExpr (%<\\AcObjProp Object(%<\\_ObjId " (itoa(vla-get-ObjectID vObj)) ">%).Area>%) / 9.0 \\f \"%lu2%pr2%ps[, sq. yards]\">%")) ); end progn ); end if ); end if (princ) ); end of c:arf Quote
MaxwellEdison Posted January 6, 2009 Posted January 6, 2009 Honestly I have no idea...I draw, I don't code. I stutter, I don't lisp. Quote
Lee Mac Posted January 6, 2009 Posted January 6, 2009 I draw, I don't code. I stutter, I don't lisp. Haha, this made me laugh Quote
rustysilo Posted January 6, 2009 Author Posted January 6, 2009 Ugh. It'll take me many moons to decipher what all that code means. Quote
MaxwellEdison Posted January 6, 2009 Posted January 6, 2009 If I had to guess, I'd say he's selecting the object to obtain the ObjID, then prompting the user to select the object to receive the field (text mtext attribute). Then changing the properties of that selected object so the contents read the field string with the ObjID. Is that about right ASMI? Quote
ASMI Posted January 6, 2009 Posted January 6, 2009 If I had to guess, I'd say he's selecting the object to obtain the ObjID, then prompting the user to select the object to receive the field (text mtext attribute). Then changing the properties of that selected object so the contents read the field string with the ObjID. Is that about right ASMI? Yes. And you already can use it. Ugh. It'll take me many moons to decipher what all that code means. I can add some comments to my code, but tomorrow, because time to sleep. For block insertion and attribute filling need to add a few lines, but you shoud to know attribute tag name. Very nice ASMI. Thank you Larry. Quote
Ozymandias Posted January 28, 2010 Posted January 28, 2010 you sir are a genius. I have modified this for my uses but I wish I had this piece of script 6 months ago when I had to take the areas off every room for over 300 buildings....... it would have saved allot of mistakes. If any one wants this as SQ M its not a major ammendment but I have attached it here (defun c:arf(/ fStr cObj vObj cTxt vTxt) (vl-load-com) (if (and (setq cObj(entsel "\nPick object with Area property > ")) (vlax-property-available-p (setq vObj(vlax-ename->vla-object(car cObj))) 'Area) ); end and (if (and (setq cTxt(nentsel "\nPick Text, MText or Attribute to insert field > ")) (vlax-property-available-p (setq vTxt(vlax-ename->vla-object(car cTxt))) 'TextString) ); end and (progn (vla-put-TextString vTxt (strcat "%\\AcExpr (%\\AcObjProp Object(%\\_ObjId " (itoa(vla-get-ObjectID vObj)) ">%).Area>%) / 1000000 \\f \"%lu2%pr2%ps[, sq.M]\">%")) ); end progn ); end if ); end if (princ) ); end of c:arf Quote
Sungam Posted May 12, 2010 Posted May 12, 2010 In the code below made by ASMI you are supposed to select an object to get the area property and then select the Text, MText or Attrib to where you want to insert the field. Is it possible to make the code select the object (attrib) by tag, for example TAG1, instead of picking it? Quote
Sungam Posted May 12, 2010 Posted May 12, 2010 Yes you did, thank you very much. But now I've had a hole nights sleep to think about the problem and I have alot of similar tasks to automate... Do you think it´s possible to be able to adress the attribut by it's TAG instead of picking it? Quote
Jocker_Boy Posted March 24, 2016 Posted March 24, 2016 Hi, This thread have some years, but e need a lisp similar to this. The objective is, instead of select one area, to select one block that have severall attributes, and it will get the attribute "A", then instead of picking a Text, Mtext or Attribute, when pick it will insert a block "blockX" (it is a simple block, just one circle and in the middle it will have one field with the value of the attribute "A", selected initial) It is to confused? Sorry for my english, i'm from portugal. Thanks Quote
Ozymandias Posted March 25, 2016 Posted March 25, 2016 If you do a google search for Lee Mac scripts I am sure I have seen one that will do what you are stating. Quote
Jocker_Boy Posted March 25, 2016 Posted March 25, 2016 I only find one similar: http://www.cadtutor.net/forum/showthread.php?47834-Get-ObjectID-for-Attdef-script&p=657724#post657724 But it is similar, it only needs one change: Instead of select the area, is it possible to select one block and retreive the attribute "TAG2", for example? Quote
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.