Saturday, November 21, 2009
Home   |   Search   |   About AUGI   |   My AUGI   |   Join Now

Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP
 Welcome, Guest. 

Login

Join Now FAQ Members List Calendar Search Today's Posts Mark Forums Read

AutoLISP AutoLISP or Visual LISP, learn both here!

Reply
 
Thread Tools Display Modes
Old 2004-07-09, 01:51 AM   #1
csgohjmj
Member
 
Join Date: 2003-12
Posts: 47
csgohjmj is starting their journey
Question Getting the centroid of closed polyline

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
csgohjmj is offline   Reply With Quote
Old 2004-07-09, 09:35 AM   #2
David.Hoole
Active Member
 
David.Hoole's Avatar
 
Join Date: 2000-12
Location: Yorkshire
Posts: 81
David.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright future
Default RE: Getting the centroid of closed polyline

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.
__________________
Regards,

David
David.Hoole is offline   Reply With Quote
Old 2004-07-09, 04:32 PM   #3
csgohjmj
Member
 
Join Date: 2003-12
Posts: 47
csgohjmj is starting their journey
Default RE: Getting the centroid of closed polyline

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
csgohjmj is offline   Reply With Quote
Old 2004-07-09, 05:09 PM   #4
David.Hoole
Active Member
 
David.Hoole's Avatar
 
Join Date: 2000-12
Location: Yorkshire
Posts: 81
David.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright future
Red face RE: Getting the centroid of closed polyline

Hi csgoh

Sorry, forgot we were in a programming forum! Try this:

[code]
(setq obj (vlax-ename->vla-object (car (entsel))))
(setq centroid (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj))))
[code]

Hope I got the code window right! Fluffed it last time
__________________
Regards,

David
David.Hoole is offline   Reply With Quote
Old 2004-07-09, 05:47 PM   #5
David.Hoole
Active Member
 
David.Hoole's Avatar
 
Join Date: 2000-12
Location: Yorkshire
Posts: 81
David.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright future
Default RE: Getting the centroid of closed polyline

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)
)
__________________
Regards,

David
David.Hoole is offline   Reply With Quote
Old 2004-07-11, 04:56 PM   #6
csgohjmj
Member
 
Join Date: 2003-12
Posts: 47
csgohjmj is starting their journey
Default RE: Getting the centroid of closed polyline

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
csgohjmj is offline   Reply With Quote
Old 2004-08-30, 03:35 AM   #7
csgohjmj
Member
 
Join Date: 2003-12
Posts: 47
csgohjmj is starting their journey
Default RE: Getting the centroid of closed polyline

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
csgohjmj is offline   Reply With Quote
Old 2004-08-30, 11:37 AM   #8
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
Default

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.
stig.madsen is offline   Reply With Quote
Old 2004-08-30, 04:20 PM   #9
jwanstaett
I could stop if I wanted to
 
Join Date: 2002-02
Location: Kansas
Posts: 462
jwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of lightjwanstaett is a beam of light
Default RE: Getting the centroid of closed polyline

Quote:
Originally Posted by stig.madsen
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 AutoCad
jwanstaett is offline   Reply With Quote
Old 2004-08-30, 04:38 PM   #10
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
Default

Well, I must be getting old. So csgohjmj should have no problem running the code David provided on R14?
stig.madsen is offline   Reply With Quote
Reply


Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Imported Polyline and text show different Gerhard Revit Architecture - General 6 2008-09-26 12:49 PM
Creating closed figures? sinc Land Desktop - General 3 2004-06-10 07:54 PM
Closed loop mjml Revit Architecture - General 10 2003-12-30 02:34 AM
Closed Loop Profiles Jim Storms Revit Architecture - Families 4 2003-11-06 03:53 PM


All times are GMT +1. The time now is 12:30 PM.