See the top rated post in this thread. Click here

Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Getting the centroid of closed polyline

  1. #1
    Member
    Join Date
    2003-12
    Posts
    47
    Login to Give a bone
    0

    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

  2. #2
    Active Member David.Hoole's Avatar
    Join Date
    2000-12
    Location
    Yorkshire
    Posts
    84
    Login to Give a bone
    0

    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.

  3. #3
    Member
    Join Date
    2003-12
    Posts
    47
    Login to Give a bone
    0

    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

  4. #4
    Active Member David.Hoole's Avatar
    Join Date
    2000-12
    Location
    Yorkshire
    Posts
    84
    Login to Give a bone
    0

    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))))
    Hope I got the code window right! Fluffed it last time
    Last edited by Opie; 2015-03-18 at 06:23 PM.

  5. #5
    Active Member David.Hoole's Avatar
    Join Date
    2000-12
    Location
    Yorkshire
    Posts
    84
    Login to Give a bone
    1

    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)
    )

  6. #6
    Member
    Join Date
    2003-12
    Posts
    47
    Login to Give a bone
    0

    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

  7. #7
    Member
    Join Date
    2003-12
    Posts
    47
    Login to Give a bone
    0

    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

  8. #8
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    0

    Default Re: Getting the centroid of closed polyline

    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.

  9. #9
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    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

  10. #10
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    0

    Default Re: Getting the centroid of closed polyline

    Well, I must be getting old. So csgohjmj should have no problem running the code David provided on R14?

Page 1 of 3 123 LastLast

Similar Threads

  1. Area without a closed polyline
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2014-02-11, 03:07 PM
  2. ssget closed polyline
    By rad.77676 in forum AutoLISP
    Replies: 31
    Last Post: 2009-04-16, 07:26 AM
  3. Sweeping Closed Polyline around a Helix
    By ralph.burkey in forum AutoCAD General
    Replies: 6
    Last Post: 2008-06-04, 09:40 PM
  4. Create a Surface from a Closed Polyline
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-05-26, 06:42 PM
  5. C# - closed Polyline length
    By RoSiNiNo in forum ARX
    Replies: 1
    Last Post: 2005-03-02, 03:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •