Create a field linked to an object
Here is one way to create a field linked to an object. For example, this could be used if you wanted to write your own program to label the area of closed polylines, but you want to use a dynamic field instead of a static TEXT entity. Here is a code example...
(vl-load-com) ;;get a reference to model space (setq *model-space* (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)) ) ) ;;pass this function an entity and a point (defun LinkedArea (ent pt / obj objID ip width str) ;;convert the entity to an object (setq obj (vlax-ename->vla-object ent) ;;get the object ID objID (vla-get-objectid obj) ;;convert the point ip (vlax-3D-Point pt) ;;set the width for the MTEXT width 0.0 ;;set the string - this creates the field str (strcat "%<\\AcObjProp.16.2 Object(%<\\_ObjId " (rtos objID 2 0) ">%).Area \\f \"%lu2%pr2%ps[, Acres]%ct8[2.295684113865932e-005]\">%" ) ) ;;Create the MTEXT entity containing the field. (vla-addMText *model-space* ip width str) )
Then, you can call this function like this:
;; Set A = the entity and set B = Point for text (setq a (car (entsel)) b (getpoint "\n Select Point: ")) ;;Call the function (linkedarea a b)
This particular string creates a field that converts the AREA (assumed to be Square Feet) to Acres. The resulting label will be a field displayed something like 3.97 Acres.
For just the basic area itself, at the current precision, you could use:
%<\AcObjProp Object(%<\_ObjId 2130432400>%).Area \f "%lu2">%
...replacing the embedded ObjectID with the ObjectID you retreive from your entity.
All content is copyright © CAD PANACEA 2005-2011 unless otherwise noted.
All content of CAD PANACEA is solely my own personal thoughts and opinions and do not those of any other entity or person.
All comments posted to this blog are the sole responsibility of the person making the comment.
Google, as a third party vendor, uses cookies to serve ads on this site. Google's use of their cookies enables it to serve ads to users based on their visit to your sites and other sites on the Internet. You may opt out of the use of these cookies by visiting the Google ad and content network privacy policy.

Recent comments
1 day 12 hours ago
1 day 15 hours ago
2 days 17 hours ago
4 weeks 2 days ago
7 weeks 1 day ago
7 weeks 1 day ago
7 weeks 1 day ago
7 weeks 1 day ago
12 weeks 21 hours ago
12 weeks 2 days ago