Jump to content

Lisp to put point as geometric center of closed polylines


Recommended Posts

Posted

Hello Everyone,

is there any lisp can help me to put a point in the geometrec center of several closed polylines ?

 

Thanks in Advance

Posted

Something like this

 

(setq obj (vlax-ename->vla-object (entlast)))
(setq cpt (osnap (vlax-curve-getStartPoint obj) "gcen"))

Thanks to Kent Cooper for the hint about gcen

  • Like 1
  • Agree 1
Posted

I think vlax-curve-getStartPoint works with entity names also.

 

(setq cpt (osnap (vlax-curve-getStartPoint (entlast)) "gcen"))

 

  • Like 1
Posted
7 minutes ago, tombu said:

Better to provide a link to give credit to the author Kent Cooper which would be the source if anyone had any questions about the lisp.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-subfunction-to-get-quot-center-quot-inside-closed-polyline/m-p/8747852#M384196

i didn't know who is the author as i got the lisp from a college not from internet but thanks for sharing the author with us he deserves the credit 

Posted

Here you go. :)

(defun c:Test (/ spc get sel int ent rgn)
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (or *TH:doc*
      (setq *TH:doc* (vla-get-activedocument (vlax-get-acad-object)))
  )
  (setq spc ((if (> (vla-get-activespace *TH:doc*) 0) vla-get-modelspace vla-get-paperspace) *TH:doc*
            )
  )
  (and
    (cond
      ((= 4
          (logand
            4
            (cdr
              (assoc
                70
                (setq get (entget (tblobjname "LAYER" (getvar 'CLAYER))))
              )
            )
          )
       )
       (alert "Current layer is locked. Unlock it and try again <!>")
      )
      ((minusp (cdr (assoc 62 get)))
       (alert "Current layer is off. Turn it on and try again <!>")
      )
      (t get)
    )
    (setq int -1
          sel (ssget "_:L" '((0 . "LWPOLYLINE") (-4 . "=") (70 . 1)))
    )
    (or (zerop (getvar 'PDMODE))
        (setvar 'PDMODE 3)
    )
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (entmake
        (list
          '(0 . "POINT")
          (cons
            10
            (vlax-get (setq rgn (car (vlax-invoke
                                       spc
                                       'addregion
                                       (list (vlax-ename->vla-object ent))
                                     )
                                )
                      )
                      'Centroid
            )
          )
        )
      )
      (and rgn (vla-delete rgn))
    )
  )
  (princ)
) (vl-load-com)

 

Posted

Steven P draw a pline as a "U" rotated and compare the methods suggested. You could average points also but it may not be geom centre.

 

image.png.2b28e87e328f055c2df67d40f88c00d1.png

 

 

  • Like 1
Posted

It is tricky with the OP wanting the geometric centre of several objects. For a single object AutoCAD has an object snap of geometric centre (not sure about Bricscad, I assume it is similar), place a point there, no LISP required for just that. As above to get the centre if you need that point in a LISP.... for single polylines.

 

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...