See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 25

Thread: Getting the centroid of closed polyline

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

    Question Re: Getting the centroid of closed polyline

    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

  8. #8
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,657
    Login to Give a bone
    0

    Default Re: Getting the centroid of closed polyline

    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

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

    Thumbs up Re: Getting the centroid of closed polyline

    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

  10. #10
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,657
    Login to Give a bone
    0

    Default Re: Getting the centroid of closed polyline

    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

Page 1 of 2 12 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
  •