LISP for creating field off a selected object, grabbing specific attribute

LISP for creating field off a selected object, grabbing specific attribute

MichaelD061
Contributor Contributor
801 Views
2 Replies
Message 1 of 3

LISP for creating field off a selected object, grabbing specific attribute

MichaelD061
Contributor
Contributor

Looking to create an autocad lisp that allows me to select an object and places a field parameter regarding that specific block's attribute titled CIRCUIT#. Original thought process was to select an object, grab its id, then place field parameter. It should autoselect field category as object, the object type should be the object that I selected, property should be Circuit#, and format should be (none).

 

For reference, here are two examples of the field expression for two objects.

%<\AcObjProp Object(%<\_ObjId 1770506033232>%).TextString>%

%<\AcObjProp Object(%<\_ObjId 1770506022224>%).TextString>%

 

I have an attempt above!

(defun c:PlaceField ()
  (setq obj (car (nentselp "\nSelect an object: ")))
  (if obj
    (progn
      (setq entityId (cdr (assoc 5 (entget obj)))) ; Get the handle of the selected object
      (setq fieldText (strcat "%<\\AcObjProp Object(%<\\_ObjId " entityId ">%).Attribute(\"CIRCUIT#\")>%"))
      (command "_.FIELD" "_Object" fieldText "_Type" "Object" "_Object" entityId "_Field")
    )
    (princ "\nNo object selected.")
  )
)



; Examples of proper field expression
;<\AcObjProp Object(%<\_ObjId 1770506033232>%).TextString>%
;%<\AcObjProp Object(%<\_ObjId 1770506022224>%).TextString>%

 

0 Likes
802 Views
2 Replies
Replies (2)
Message 2 of 3

paullimapa
Mentor
Mentor

One item you’re missing is the objid. An example of how to get this

(setq objid (vla-get-ObjectId (vlax-ename->vla-object enam)))

Here’s a link where you can get some ideas on how to put the field expression into an object


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 3

Sea-Haven
Mentor
Mentor

I am confused when using fields need two objects the first is the relative object eg an Attribute, the second is the destination object say a Mtext or another attribute in another block. Dont need tag name if picking an attribute.

 

You appear to have only 1 object in the code.

 

Lastly using VL can put a field textstring into a suitable object and will reflect that field.

Selecting an attribute should give this type of string, need to use nentsel to pick attribute rather than block.

 

 

%<\AcObjProp Object(%<\_ObjId 1961879984>%).TextString>%

 

 

 

 

0 Likes