Jump to content

Insert An Attribute Block Then Fill In w/Field


Recommended Posts

Posted

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.

Posted

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.

Posted
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.

Posted

There are 144 square inches in a square foot, 9 square feet in a square yard, and 1296 square inches in a square yard

Posted
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

Posted

Honestly I have no idea...I draw, I don't code. I stutter, I don't lisp.

Posted
I draw, I don't code. I stutter, I don't lisp.

 

Haha, this made me laugh :P

Posted

Ugh. It'll take me many moons to decipher what all that code means.:sick:

Posted

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?

Posted
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.

  • 1 year later...
Posted

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

  • 3 months later...
Posted

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?

Posted

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?

  • 5 years later...
Posted

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

Posted

If you do a google search for Lee Mac scripts I am sure I have seen one that will do what you are stating.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...