Hi;
I am trying get the coordinates of the centroid of a closed polyline but do not have any idea at all. Is there any lisp routine whereby the coordinate can be obtained? Any help is much appreciated. Thanks.
csgoh
9-7-04
|
Hi;
I am trying get the coordinates of the centroid of a closed polyline but do not have any idea at all. Is there any lisp routine whereby the coordinate can be obtained? Any help is much appreciated. Thanks.
csgoh
9-7-04
Hi csgoh
Use the REGION command to convert the Polyline to a Region, then use the MASSPROP command to list its physical properties, which include the centroid.
Hi David,
Thanks for the tip but using massprop only lists out the properties. But I need to get the centroid coordinates in order to insert text at this point and how can I do this?
Thanks.
csgoh
Hi csgoh
Sorry, forgot we were in a programming forum! Try this:
Hope I got the code window right! Fluffed it last timeCode:(setq obj (vlax-ename->vla-object (car (entsel)))) (setq centroid (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj))))
Last edited by Opie; 2015-03-18 at 06:23 PM.
Hi csgoh
Looks like I fluffed the text window again . I may have to read the instructions
Thought you might find a practical example useful:
Code:(defun c:get_centroid ( / ename obj centroid) (setq ename (car (entsel "\nSelect polyline:"))) (command "region" ename "") (setq ename (entlast)) (setq obj (vlax-ename->vla-object ename)) (setq centroid (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj)))) (command "undo" "") (command "text" "j" "mc" centroid 2.5 0.0 "CENTROID") (princ) )
Dear David;
Thanks but the code that you have given is good for ACAD 2K & above. How about those older version like Autocad R14 version. I have tried using entget to retrieve the centroid but to no avail and I hope you could help me.
Thanks again.
csgoh
11-7-04
Hi all;
What is a variant? I went through the help section of ACAD R14 and tells if I need to obtain the centroid coordinates, I will have to use <variant>=object.Centroid and define these :-
Dim anObj as object
Dim retCentroid as Variant
retCentroid=anObj.Centroid
Could someone please tell me how to incorporate these codes into Autolisp? Some of our machines are using ACAD R14 version. Any help to get the centroid in ACAD R14 lisp codes is much appreciated.
thanks.
csgoh
A variant is a variable that can hold one of several different data types. It's used in Visual Basic and has no direct counterpart in AutoLISP but can be read and assigned by functions in Visual LISP.
If I remember correctly, R14 does not have access to ActiveX or VBA - even with the add-on Visual LISP for R14c, I think (could be very wrong on this) - so you may have to get a function that does all the analyses and math itself. Did you search the AUGI Exchange?Otherwise, searching for "centroid AutoLISP" in Google turned up 238 hits so maybe there is hope.
no r14 was when Autodesk added VBA to AutoCadOriginally Posted by stig.madsen
Well, I must be getting old. So csgohjmj should have no problem running the code David provided on R14?