Leonardo.cunha Posted November 25, 2022 Posted November 25, 2022 Hello everybody in some searches on the internet I found this lsp that gives the location of the centroid of a region. Would it be possible to use it so that Autocad inserts a point in the centroid of the region? (defun c:centroid() (cond ((not(setq app (vlax-get-acad-object) doc (vla-get-activedocument app) ss (ssget ":S" '((0 . "3dsolid,body,region"))) ) ) (vlax-release-object app) (princ "\nNo valid modeling object selected. ") (princ) ) ((not (setq obj (vlax-ename->vla-object (ssname ss 0)) test (vlax-property-available-p obj 'centroid) ) ) (vlax-release-object app) (vlax-release-object doc) (vlax-release-object obj) (princ "\nCentroid property not available for selected object. ") (princ) ) (T (trans (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj))) (ssname ss 0) 1) ) ) ) I don't have programming knowledge to do this, can you help me? Thanks Quote
Steven P Posted November 25, 2022 Posted November 25, 2022 Quick one to start with, if you hit the <> before you post code and paste your code into the pop-up box it puts it into a shaded box - much easier to read where the code starts and stops. A lesson in LISPs then,,,, what output does this give you - often it will tell you stuff in the command line. Run it and what does it say? Quote
BIGAL Posted November 25, 2022 Posted November 25, 2022 Try this (defun c:centroid( / ss obj ) (setq ss (ssget "+.:E:S" '((0 . "3dsolid,body,region")))) (if (= ss nil) (princ "\nNo valid modeling object selected. ") (progn (setq obj (vlax-ename->vla-object (ssname ss 0))) (if (vlax-property-available-p obj 'centroid) (Command "point" (trans (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj))) (ssname ss 0) 1)) (princ "\nCentroid property not available for selected object. ") ) ) ) (princ) ) Quote
Leonardo.cunha Posted November 26, 2022 Author Posted November 26, 2022 6 hours ago, Leonardo.cunha said: Hello everybody in some searches on the internet I found this lsp that gives the location of the centroid of a region. Would it be possible to use it so that Autocad inserts a point in the centroid of the region? (defun c:centroid() (cond ((not(setq app (vlax-get-acad-object) doc (vla-get-activedocument app) ss (ssget ":S" '((0 . "3dsolid,body,region"))) ) ) (vlax-release-object app) (princ "\nNo valid modeling object selected. ") (princ) ) ((not (setq obj (vlax-ename->vla-object (ssname ss 0)) test (vlax-property-available-p obj 'centroid) ) ) (vlax-release-object app) (vlax-release-object doc) (vlax-release-object obj) (princ "\nCentroid property not available for selected object. ") (princ) ) (T (trans (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj))) (ssname ss 0) 1) ) ) ) I don't have programming knowledge to do this, can you help me? Thanks 5 hours ago, Steven P said: Quick one to start with, if you hit the <> before you post code and paste your code into the pop-up box it puts it into a shaded box - much easier to read where the code starts and stops. A lesson in LISPs then,,,, what output does this give you - often it will tell you stuff in the command line. Run it and what does it say? Thanks for the tip, I'll use <> next time 1 Quote
Leonardo.cunha Posted November 26, 2022 Author Posted November 26, 2022 3 hours ago, BIGAL said: Try this (defun c:centroid( / ss obj ) (setq ss (ssget "+.:E:S" '((0 . "3dsolid,body,region")))) (if (= ss nil) (princ "\nNo valid modeling object selected. ") (progn (setq obj (vlax-ename->vla-object (ssname ss 0))) (if (vlax-property-available-p obj 'centroid) (Command "point" (trans (vlax-safearray->list (vlax-variant-value (vla-get-centroid obj))) (ssname ss 0) 1)) (princ "\nCentroid property not available for selected object. ") ) ) ) (princ) ) Perfect, this is exactly what I was looking for. Thank you very much 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.