draw polyline, insert block with field linked to polylines length.

draw polyline, insert block with field linked to polylines length.

Anonymous
Not applicable
1,691 Views
3 Replies
Message 1 of 4

draw polyline, insert block with field linked to polylines length.

Anonymous
Not applicable

I'm trying to find a way to draw a polyline, then insert a block that has a field linked to the polylines length property. I've searched and can't find anything. I'm thinking I'm not searching right. Does anyone hae any ideas on how to do this with lisp?

 

 Thanks in advance!!

0 Likes
Accepted solutions (1)
1,692 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

THIS Henrique's code looks promising as a starting point... you need to change the beginning of the code for something like this

 

(command "_.PLINE") (while (< 0 (getvar 'CMDACTIVE)) (command PAUSE))
(if (setq ss (ssget "_L" '((0 . "LWPOLYLINE"))))

...

 

Anyway, if you not versed in lisp enough yourself, post a DWG sample with the block definition... showing where the block should be located... in the middle of the polyline?

0 Likes
Message 3 of 4

Anonymous
Not applicable

Yes, that is a good place to start! I just needed a sample of how to create a field and link it to an object id in lisp.

 

Thanks!

0 Likes
Message 4 of 4

hencoop
Advisor
Advisor
Accepted solution

Down in the code that @ВeekeeCZ linked there is this:

      (setq s
        (strcat "%<\\AcObjProp Object(%<\\_ObjId "
          (LM:GetObjectID doc (vlax-ename->vla-object p)) ">%).Length \\f \"%lu6\">%"
        )
      )         

which constructs the field string for Length of the object whose symbol in the code is 'p.  Put that string as your attribute value and it is done!

What you are asking for is in there.  It seems that the code to define 'doc which is one of the two inputs required by (LM:GetObjectID doc obj) is not included.  However, 'doc is a pretty standard construct during the setup of most (VLAX-...) function calls but I am still a noob in my understanding of it so I'll leave it to another to provide that for you.

 

(defun LM:GetObjectID ( doc obj )
  (if (eq "X64" (strcase (getenv "PROCESSOR_ARCHITECTURE")))
    (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false)
    (itoa (vla-get-Objectid obj))
  )
)

I am elated to find code that gets the Object ID! I've been wanting this for a while now. Thanks Lee Mac

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes