Jump to content

Lisp to put point as geometric center of closed polylines


asdfgh

Recommended Posts

2 hours ago, asdfgh said:

i found this lisp which is useful for everyone

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

  • Agree 1
Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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