Elektrik Posted December 7, 2018 Posted December 7, 2018 Is there any lisp to find/mark the centroid of any area you select, just when you run with the area command, you can select any area you want without polygons or regions. Is there any lisp find the centroid of an area when you specify points that define that area? Thanks in advance. Quote
marko_ribar Posted December 7, 2018 Posted December 7, 2018 Study this example and it should be clear to you what to modify to get sub function work with point list... Note that it would be preferable to draw polygon in advance as segments must not cross each other... So actually you don't need to modify anything from Lee's examples - you have to provide LWPOLYLINE polygon ENAME as an argument... http://www.lee-mac.com/polygoncentroid.html HTH., M.R. 1 Quote
Tharwat Posted December 8, 2018 Posted December 8, 2018 Hi, Give this a shot and let me know. (defun c:cnt ( / nxt pnt lst obj reg cen) ;;--------------------------------------------;; ;; Tharwat - Date: 08.12.2018 ;; ;; Print Centriod point from picked points. ;; ;;--------------------------------------------;; (cond ((= 4 (logand 4 (cdr (assoc 70 (entget (tblobjname "LAYER" (getvar 'CLAYER))))))) (alert "Current layer is locked<!>")) ((and (setq nxt " ") (while (setq pnt (getpoint (strcat "\nSpecify" nxt "point : "))) (setq lst (cons pnt lst) nxt " Next ") ) lst (setq obj (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)) '(70 . 1)) (mapcar (function (lambda (p) (cons 10 p))) lst)))) ) (cond ((vl-catch-all-error-p (setq reg (vl-catch-all-apply 'vlax-invoke (list (vla-get-block (vla-get-activelayout (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) 'Addregion (list (vlax-ename->vla-object obj)) ) ))) (alert "Error. Can't create the region <!>")) (t (setq reg (car reg) cen (vlax-get reg 'Centroid)) (alert (strcat "Centriod = " (vl-princ-to-string cen))) (print cen) (vla-delete reg)) )) ) (and obj (entdel obj)) (princ) ) (vl-load-com) (princ "\nType CNT to start.") 1 Quote
Elektrik Posted December 8, 2018 Author Posted December 8, 2018 2 hours ago, Tharwat said: Hi, Give this a shot and let me know. (defun c:cnt ( / nxt pnt lst obj reg cen) ;;--------------------------------------------;; ;; Tharwat - Date: 08.12.2018 ;; ;; Print Centriod point from picked points. ;; ;;--------------------------------------------;; (cond ((= 4 (logand 4 (cdr (assoc 70 (entget (tblobjname "LAYER" (getvar 'CLAYER))))))) (alert "Current layer is locked<!>")) ((and (setq nxt " ") (while (setq pnt (getpoint (strcat "\nSpecify" nxt "point : "))) (setq lst (cons pnt lst) nxt " Next ") ) lst (setq obj (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)) '(70 . 1)) (mapcar (function (lambda (p) (cons 10 p))) lst)))) ) (cond ((vl-catch-all-error-p (setq reg (vl-catch-all-apply 'vlax-invoke (list (vla-get-block (vla-get-activelayout (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) 'Addregion (list (vlax-ename->vla-object obj)) ) ))) (alert "Error. Can't create the region <!>")) (t (setq reg (car reg) cen (vlax-get reg 'Centroid)) (alert (strcat "Centriod = " (vl-princ-to-string cen))) (print cen) (vla-delete reg)) )) ) (and obj (entdel obj)) (princ) ) (vl-load-com) (princ "\nType CNT to start.") Thanks, this is just what I wanted, except it does not mark the centeroid. It would be better if it did. Thanks again. Quote
Tharwat Posted December 8, 2018 Posted December 8, 2018 (edited) Just replace this: (alert (strcat "Centriod = " (vl-princ-to-string cen))) with this: (entmake (list '(0 . "POINT") (cons 10 (trans cen 0 1)))) And get sure is that the PDMODE system variable is other than zero to be able to see the mark point. Edited December 8, 2018 by Tharwat 1 Quote
Elektrik Posted December 8, 2018 Author Posted December 8, 2018 1 hour ago, Tharwat said: Just replace this: (alert (strcat "Centriod = " (vl-princ-to-string cen))) with this: (entmake (list '(0 . "POINT") (cons 10 cen))) And get sure is that the PDMODE system variable is other than zero to be able to see the mark point. Thanks, but it marks somewhere outside the selected area I am not sure why. Quote
Tharwat Posted December 8, 2018 Posted December 8, 2018 14 minutes ago, Elektrik said: Thanks, but it marks somewhere outside the selected area I am not sure why. You must have your UCS other than World system and that's why the mark point located somewhere else. Anyway, I have updated my previous post and please replace them again then try again. NOTE: its not necessarily to quote every reply to write a reply but its up to you anyway. 1 Quote
Maharshi555 Posted March 22, 2022 Posted March 22, 2022 Simply use this: (setq cen_pt (ade_expreval ent_one ".center" "point")) ent_one is the entity Quote
Steven P Posted March 22, 2022 Posted March 22, 2022 2 hours ago, Maharshi555 said: Simply use this: (setq cen_pt (ade_expreval ent_one ".center" "point")) ent_one is the entity of course, ade_expreval is an AutoCAD 3d MAP command and won't work if they don't have that installed. Quote
mhupp Posted March 22, 2022 Posted March 22, 2022 I am assuming center point = geometric center (setq poly (vlax-ename->vla-object (car (entsel "\nSelect polyline")))) (setq CPT (osnap (vlax-curve-getStartPoint poly) "gcen")) Quote
Recommended Posts
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.