See the top rated post in this thread. Click here

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: Getting the centroid of closed polyline

  1. #11
    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

  2. #12
    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

  3. #13
    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

  4. #14
    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

  5. #15
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    1

    Default Re: Getting the centroid of closed polyline

    Hi csgohjmj ! ?

    Here is my old working R14 stuff.
    a point is created in the centroid, check the pdmode, DDptype.
    If you want Moment, Products, Radii from the centroid, You can run
    TP again in that point "Select point for centroid calculation ".


    Code:
    (defun c:tp(/ ucsic ents osm )
    ;;; 2000-05-19 kennet
      (defun calc (/ org tpfil I Xrad Yrad Ytp Ytp TP )
        (setq org (getpoint "Select point for centroid calculation "))
        (command "._ucs" "Origin" org )
        (setvar "UCSICON" 3 )
        (command "._massprop" "l" "" "Y" "C:$$temp$$")
        (command "._erase" "l" "")
        (setq tpfil (open "C:$$temp$$.mpr" "r"))
        (setq I 0 )
        (while (< I 8 )
          (setq Xrad (read-line tpfil ))
          (setq I (1+ I))
        )
        (setq Yrad (read-line tpfil ))
        (close tpfil )
        (command "._del" "C:$$temp$$.mpr")
        (setq Xtp (float(atof (substr Xrad 26 10 ))))
        (setq Ytp (float(atof (substr Yrad 26 10 ))))
        (setvar "OSMODE" 0 )
        (command "._point" (list Xtp Ytp) )
        (setvar "OSMODE" osm )
        (setvar "UCSICON" ucsic )
        (command "._ucs" "p")
        (textscr)
      )
    
      (defun not_ok ()
        (command "._erase" "p" "")
        (princ "!! Cant make  a closed are !! ")
      )
    
    
      (setvar "CMDECHO" 0 )
      (setq ucsic (getvar "UCSICON"))
      (setq osm (getvar "OSMODE"))
      (prompt "nSelect objects in a closed area : ")
      (setq ents (ssget))
      (command "._copy" "p" "" "0,0,0" "0,0,0" )
      (command "._region" "p" "")
      (if (= (cdr (assoc 0 (entget (entlast)))) "REGION" ) (calc) (not_ok) )
      (princ)
    )
    Happy Computing !

    kennet
    Last edited by Glenn Pope; 2004-09-08 at 01:26 PM. Reason: Placed routine in code tag

  6. #16
    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 lisp code for getting the centroid. However, I encounter an error ;saying that it is a self intersecting loop. There is nothing wrong in your code at all. I have even used the command "region" and select a closed polyline and it gives me the same error messages. I also have attached the dwg file for this discusion as to how to solve the problem. The polygon in the dwg looks like it is self intersecting, but it you zoom close enough, it is not so. It so happen that the lines on the right side of the polygon differs by only 0.0001mm. Or is there anyother way ? Pls help.
    Thanks

    csgoh

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

    Default Re: Getting the centroid of closed polyline

    Forgot about the dwg attachment. Here is a sample of polygon.
    Attached Files Attached Files

  8. #18
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Getting the centroid of closed polyline

    Hi Donald ; )

    Here is a solution for you :

    Scale the polygon 1000 times, run TP, scale back again 0.001 times
    (scale in the same point, take the tp-point with you )

    Happy Computing !

    My name is still kennet

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

    Default Re: Getting the centroid of closed polyline

    Hi Kennet;
    In fact, tried out your suggestion and it works. Anyway, the problem I am actually facing is the command "region" even when I type it at command prompt without any lisp program. I tested in acad2002 in xp pro service pack and acad14 and both give me an error but not acad2004 & 2005. Why is that?
    Thanks

    csgoh

    p/s- Kennet, my last post was actually directed to David from the earlier reply in these post.

  10. #20
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Getting the centroid of closed polyline

    OK, but Davids code was not for R14. . .

    Probably AutoCAD do better calculating nowadays ; )

    Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2004-10-11 at 01:31 PM.

Page 2 of 3 FirstFirst 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
  •