CAD PANACEA HAS MOVED TO http://cadpanacea.com
06 September 2006
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.


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

Labels:


PermaLink       Posted 9/06/2006 08:41:00 AM     
0 COMMENTS!

Post a comment