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;
I have tried David's code on ACAD R14 and 2002 by entering the code at command line.
However it gives me an [error: null function in ACAD R14 and no function definition in ACAD 2002] when I key in these code [ (setq obj(vlax-ename->vla-object ename)) ].
Now what have I done wrong here? Is there anything else that I have to do in order to be able to use the vl/vla funtions? This is my first attempt to use the vl functions in autolisp and I hope to get some guidance on these.
Thanks.
csgoh
Hi
Try adding -
(vl-load-com)
at the beginning of David's routine ie
(vl-load-com)
(defun c:get_centroid ( / ename obj centroid)
....
Have a good one, Mike
Thanks Mike but it does not work in ACAD R14. Guess ACAD R14 does not support vl functions. Seems that I have to save the massprop into a file and retrieve the centroid - a longer process as compared to ACAD 2002.
Thanks.
csgoh
Hi
For a little Visual LISP history regarding AutoCAD R14 check out the following links -
Visual LISP For AutoCAD R14
AutoCAD Customization Overview
History of AutoLISP
Have a good one, Mike