Reaper_of_Lykos Posted May 2, 2023 Posted May 2, 2023 Hello, I have a simple drawing with a few enclosed polylines. I am trying to use the area function to compute their areas. My code looks like this: ;prompt user to select all polylines to compute area in one go. (setq ss (ssget)) (setq tot (sslength ss)) ;get total area of all spaces (setq areaTot 0) (setq iter 0) (while (< iter tot) (setq space (entget (ssname ss iter))) (command "area" "o" space) <<------This line is obviously the problem (setq areaTot (+ areaTot (getvar "area"))) (setq iter (+ iter 1)) ) (print areaTot) But clearly this doesn't work, as area function is expecting an "object" input while I'm giving it an entity. But what data format is it looking for exactly? How to make entity an object? Thank you. Quote
ronjonp Posted May 3, 2023 Posted May 3, 2023 Weclome to CADTutor ;; Change this (setq space (entget (ssname ss iter))) (command "area" "o" space) (setq areatot (+ areatot (getvar "area"))) ;; To this (setq space (ssname ss iter)) (setq areatot (+ areatot (vlax-curve-getarea space))) 1 Quote
Reaper_of_Lykos Posted May 3, 2023 Author Posted May 3, 2023 3 hours ago, ronjonp said: Weclome to CADTutor ;; Change this (setq space (entget (ssname ss iter))) (command "area" "o" space) (setq areatot (+ areatot (getvar "area"))) ;; To this (setq space (ssname ss iter)) (setq areatot (+ areatot (vlax-curve-getarea space))) Thank you ronjonp, that works great. I am looking into vlax now because of your answer and that seems to unlock a whole new world of functionalities! Quote
ronjonp Posted May 3, 2023 Posted May 3, 2023 (edited) You should also put in a filter for the objects selected. If you select a block the code will fail on vlax-curve-getarea. Something like this: (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*POLYLINE,REGION,SPLINE")))) Edited May 3, 2023 by ronjonp Quote
Reaper_of_Lykos Posted May 3, 2023 Author Posted May 3, 2023 2 hours ago, ronjonp said: You should also put in a filter for the objects selected. If you select a block the code will fail on vlax-curve-getarea. Something like this: (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*POLYLINE,REGION,SPLINE")))) Thank you for that! Quote
ronjonp Posted May 3, 2023 Posted May 3, 2023 4 minutes ago, Reaper_of_Lykos said: Thank you for that! Not a problem! Quote
Reaper_of_Lykos Posted May 4, 2023 Author Posted May 4, 2023 (edited) Quote (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*POLYLINE,REGION,SPLINE")))) Hi ronjonp, one follow up question I hope to ask is, what does the * before POLYLINE do? Thank you! Edited May 4, 2023 by Reaper_of_Lykos Quote
ronjonp Posted May 4, 2023 Posted May 4, 2023 3 minutes ago, Reaper_of_Lykos said: Hi ronjonp, one follow up question I hope to ask is, what does the * before POLYLINE do? Thank you! It grabs lightweight polylines( LWPOLYLINE ) and 'heavy' 2D polylines ( POLYLINE ). Look at the objects listed in light blue HERE. Quote
BIGAL Posted May 5, 2023 Posted May 5, 2023 Use dumpit to see VL properties one of those must have programs. ;;;===================================================================; ;;; DumpIt ; ;;;-------------------------------------------------------------------; ;;; Dump all methods and properties for selected objects ; ;;;===================================================================; (defun C:Dumpit ( / ent) (while (setq ent (entsel)) (vlax-Dump-Object (vlax-Ename->Vla-Object (car ent)) ) ) (princ) ) also (defun c:entdump () (entget (car (entsel "\Pick object "))) ) 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.