lossan805 Posted July 11, 2012 Share Posted July 11, 2012 (edited) I need help to calculate area of multiple closed polyline shapes. In my drawing I could have hundreds of shapes as shown in the picture. I want to find total of the shaded area by adding the area of the outer shapes. Then subtracting the area of the Inner shapes. Maybe there is a better way to do it? Any help would be appreciated. Thanks. Edited July 11, 2012 by lossan805 Revised picture Quote Link to comment Share on other sites More sharing options...
Dadgad Posted July 12, 2012 Share Posted July 12, 2012 Welcome to the forum. Are they all HATCHED with a SOLID HATCH like these seem to be? The area of all hatches, or if not all, selected ones, or FILTERED ones could be found. Quote Link to comment Share on other sites More sharing options...
Dadgad Posted July 12, 2012 Share Posted July 12, 2012 When in doubt check LEE MAC out ..... http://www.lee-mac.com/totallengthandarea.html Thanks Lee! Quote Link to comment Share on other sites More sharing options...
lossan805 Posted July 12, 2012 Author Share Posted July 12, 2012 Welcome to the forum. Are they all HATCHED with a SOLID HATCH like these seem to be? The area of all hatches, or if not all, selected ones, or FILTERED ones could be found. Dadgad, Thanks for your reply.. The shapes are not are not hatched... I hatched them only to help illustrate the area that i want calculated.. Quote Link to comment Share on other sites More sharing options...
Dadgad Posted July 12, 2012 Share Posted July 12, 2012 Did you click the LEE MAC link, and look at the total area function in that lisp? Quote Link to comment Share on other sites More sharing options...
lossan805 Posted July 12, 2012 Author Share Posted July 12, 2012 Did you click the LEE MAC link, and look at the total area function in that lisp? I am evaluating that routine right now.. Quote Link to comment Share on other sites More sharing options...
lossan805 Posted July 12, 2012 Author Share Posted July 12, 2012 I tried LEE MAC's routine for total area. This is good, however this takes all the shapes and adds all the areas together. Maybe I'm not thinking about this the right way. What I need is the sum of all the outer shapes and then subtract the sum of all the inner shapes. I am going to try to create the routine myself. Its been a while since I've done a custom lisp. I think its just a matter of creating a couple of selection sets, one for the outer shapes and one for the inner shapes. Figuring out the total area for each and then subtracting. We'll see how it goes.. Quote Link to comment Share on other sites More sharing options...
Dadgad Posted July 12, 2012 Share Posted July 12, 2012 You could very easily use the FILTER command, set it up to only select items you are after, then use the lisp on the selection set, or GROUP them. Quote Link to comment Share on other sites More sharing options...
lossan805 Posted July 12, 2012 Author Share Posted July 12, 2012 You could very easily use the FILTER command, set it up to only select items you are after, then use the lisp on the selection set, or GROUP them. I appreciate your advice Dadgad.. I will certainly try that. Quote Link to comment Share on other sites More sharing options...
Dadgad Posted July 12, 2012 Share Posted July 12, 2012 If you get the FILTER set up so that you are happy with it, be sure to SAVE AS in the filter dialog box, so that it will be available right out of the gate when you need it another time. It is a very powerful and useful tool. I have about 8 different saved filters which I routinely use, and it is very helpful not having to redefine them each time I want to use them. You can also start from one of your saved FILTERS and then add or subtract items, to suit a specific search selection. Quote Link to comment Share on other sites More sharing options...
Manila Wolf Posted July 15, 2012 Share Posted July 15, 2012 If your shapes were regions, I mean for each individual illustration the inner region is subtracted from the outer region, it would then be easy to find the total area in one go. Quote Link to comment Share on other sites More sharing options...
lossan805 Posted July 16, 2012 Author Share Posted July 16, 2012 Update! I have started the code for this. I have my selection set to include all closed polylines within a specific layer. However, i am having trouble creating the filter to remove the area of the inner regions from the outer regions. Any help to create this filter would be would be much appreciated! If worse comes to worst, I could add code to hatch all of these polyline shapes and then extract the total area of the hatch itself. I want to try to avoid doing it this way though.. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 16, 2012 Share Posted July 16, 2012 Are you looking to use a single selection set and programmatically determine those polylines residing within other polylines in the set, or would you use two selection sets: one for inner objects, and one for outer? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 16, 2012 Share Posted July 16, 2012 Here is a rather crude method, utilising a ray-casting algorithm: [color=GREEN];; Polyline Area - Lee Mac[/color] [color=GREEN];; Prompts the user to make a selection of closed LWPolylines and returns[/color] [color=GREEN];; the total area of all objects in the selection, subtracting the area[/color] [color=GREEN];; of objects residing entirely inside other objects.[/color] ([color=BLUE]defun[/color] c:polyarea ( [color=BLUE]/[/color] dim inc inner lst outer sel spc ) ([color=BLUE]setq[/color] inner 0.0 outer 0.0 ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"LWPOLYLINE"[/color]) (-4 . [color=MAROON]"&="[/color]) (70 . 1)))) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] spc ([color=BLUE]vlax-get-property[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport)) 'paperspace 'modelspace ) ) ) ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]sslength[/color] sel)) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] inc ([color=BLUE]1-[/color] inc)))) lst)) ) ([color=BLUE]foreach[/color] obj1 lst ([color=BLUE]if[/color] ([color=BLUE]vl-some[/color] ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( obj2 [color=BLUE]/[/color] int pnt tmp ) ([color=BLUE]and[/color] ([color=BLUE]null[/color] ([color=BLUE]vlax-invoke[/color] obj1 'intersectwith obj2 [color=BLUE]acextendnone[/color])) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] pnt ([color=BLUE]vlax-curve-getstartpoint[/color] obj1) tmp ([color=BLUE]vla-addray[/color] spc ([color=BLUE]vlax-3D-point[/color] pnt) ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]polar[/color] pnt 0.0 1.0))) int ([color=BLUE]vlax-invoke[/color] tmp 'intersectwith obj2 [color=BLUE]acextendnone[/color]) ) ([color=BLUE]vla-delete[/color] tmp) ([color=BLUE]=[/color] 1 ([color=BLUE]rem[/color] ([color=BLUE]length[/color] int) 2)) ) ) ) ) ([color=BLUE]vl-remove[/color] obj1 lst) ) ([color=BLUE]setq[/color] inner ([color=BLUE]+[/color] inner ([color=BLUE]vla-get-area[/color] obj1))) ([color=BLUE]setq[/color] outer ([color=BLUE]+[/color] outer ([color=BLUE]vla-get-area[/color] obj1))) ) ) ([color=BLUE]setq[/color] dim ([color=BLUE]getvar[/color] 'dimzin)) ([color=BLUE]setvar[/color] 'dimzin 0) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nOuter Area: "[/color] ([color=BLUE]rtos[/color] outer 2 [color=MAROON]"\nInner Area: "[/color] ([color=BLUE]rtos[/color] inner 2 [color=MAROON]"\nTotal Area: "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]-[/color] outer inner) 2 ) ) ([color=BLUE]setvar[/color] 'dimzin dim) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted July 17, 2012 Share Posted July 17, 2012 (edited) Here is mine version ... (based on recently created vlax-curve-getfurthestpointfrom) M.R. areaoutinshapes.lsp Edited July 17, 2012 by marko_ribar Quote Link to comment Share on other sites More sharing options...
lossan805 Posted July 17, 2012 Author Share Posted July 17, 2012 PROBLEM SOLVED!!!! I would like to thank both of you Marko_ribar and Lee Mac. I can now do what i wanted with either of your routines. I really appreciate it! Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted July 17, 2012 Share Posted July 17, 2012 Lisp once more changed to accept only closed ellipses... M.R. PROBLEM SOLVED!!! You're welcome lossan805 Quote Link to comment Share on other sites More sharing options...
amarcon Posted July 18, 2012 Share Posted July 18, 2012 Lee, thank you, this routine is awesome. My existing routines are setup to do the 2 selections and take one from the other. Works well but is painful if you have 200 outer and 20 inner items. (ie total Precast Panel area minus doors and windows.) To make your routine suitable to me I am trying to get the total number of 'outer' and 'inner' area values selected! However, I'm not smart enough to decipher your elegant logic Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 18, 2012 Share Posted July 18, 2012 Lee, thank you, this routine is awesome. My existing routines are setup to do the 2 selections and take one from the other. Works well but is painful if you have 200 outer and 20 inner items. (ie total Precast Panel area minus doors and windows.) Thank you very much amarcon To make your routine suitable to me I am trying to get the total number of 'outer' and 'inner' area values selected! However, I'm not smart enough to decipher your elegant logic If I have understood you correctly, this small modfication should suffice: [color=GREEN];; Polyline Area - Lee Mac[/color] [color=GREEN];; Prompts the user to make a selection of closed LWPolylines and returns[/color] [color=GREEN];; the total area of all objects in the selection, subtracting the area[/color] [color=GREEN];; of objects residing entirely inside other objects.[/color] ([color=BLUE]defun[/color] c:polyarea ( [color=BLUE]/[/color] dim inc inner ino lst ono outer sel spc ) ([color=BLUE]setq[/color] inner 0.0 outer 0.0 ino 0 ono 0 ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"LWPOLYLINE"[/color]) (-4 . [color=MAROON]"&="[/color]) (70 . 1)))) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] spc ([color=BLUE]vlax-get-property[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport)) 'paperspace 'modelspace ) ) ) ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]sslength[/color] sel)) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] inc ([color=BLUE]1-[/color] inc)))) lst)) ) ([color=BLUE]foreach[/color] obj1 lst ([color=BLUE]if[/color] ([color=BLUE]vl-some[/color] ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( obj2 [color=BLUE]/[/color] int pnt tmp ) ([color=BLUE]and[/color] ([color=BLUE]null[/color] ([color=BLUE]vlax-invoke[/color] obj1 'intersectwith obj2 [color=BLUE]acextendnone[/color])) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] pnt ([color=BLUE]vlax-curve-getstartpoint[/color] obj1) tmp ([color=BLUE]vla-addray[/color] spc ([color=BLUE]vlax-3D-point[/color] pnt) ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]polar[/color] pnt 0.0 1.0))) int ([color=BLUE]vlax-invoke[/color] tmp 'intersectwith obj2 [color=BLUE]acextendnone[/color]) ) ([color=BLUE]vla-delete[/color] tmp) ([color=BLUE]=[/color] 1 ([color=BLUE]rem[/color] ([color=BLUE]length[/color] int) 2)) ) ) ) ) ([color=BLUE]vl-remove[/color] obj1 lst) ) ([color=BLUE]setq[/color] inner ([color=BLUE]+[/color] inner ([color=BLUE]vla-get-area[/color] obj1)) ino ([color=BLUE]1+[/color] ino) ) ([color=BLUE]setq[/color] outer ([color=BLUE]+[/color] outer ([color=BLUE]vla-get-area[/color] obj1)) ono ([color=BLUE]1+[/color] ono) ) ) ) ([color=BLUE]setq[/color] dim ([color=BLUE]getvar[/color] 'dimzin)) ([color=BLUE]setvar[/color] 'dimzin 0) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nOuter Area: "[/color] ([color=BLUE]rtos[/color] outer 2 [color=MAROON]" from "[/color] ([color=BLUE]itoa[/color] ono) [color=MAROON]" object(s)."[/color] [color=MAROON]"\nInner Area: "[/color] ([color=BLUE]rtos[/color] inner 2 [color=MAROON]" from "[/color] ([color=BLUE]itoa[/color] ino) [color=MAROON]" object(s)."[/color] [color=MAROON]"\nTotal Area: "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]-[/color] outer inner) 2 ) ) ([color=BLUE]setvar[/color] 'dimzin dim) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote Link to comment Share on other sites More sharing options...
lossan805 Posted July 18, 2012 Author Share Posted July 18, 2012 Thank you very much amarcon If I have understood you correctly, this small modfication should suffice: [color=GREEN];; Polyline Area - Lee Mac[/color] [color=GREEN];; Prompts the user to make a selection of closed LWPolylines and returns[/color] [color=GREEN];; the total area of all objects in the selection, subtracting the area[/color] [color=GREEN];; of objects residing entirely inside other objects.[/color] ([color=BLUE]defun[/color] c:polyarea ( [color=BLUE]/[/color] dim inc inner ino lst ono outer sel spc ) ([color=BLUE]setq[/color] inner 0.0 outer 0.0 ino 0 ono 0 ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"LWPOLYLINE"[/color]) (-4 . [color=MAROON]"&="[/color]) (70 . 1)))) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] spc ([color=BLUE]vlax-get-property[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport)) 'paperspace 'modelspace ) ) ) ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]sslength[/color] sel)) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] inc ([color=BLUE]1-[/color] inc)))) lst)) ) ([color=BLUE]foreach[/color] obj1 lst ([color=BLUE]if[/color] ([color=BLUE]vl-some[/color] ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( obj2 [color=BLUE]/[/color] int pnt tmp ) ([color=BLUE]and[/color] ([color=BLUE]null[/color] ([color=BLUE]vlax-invoke[/color] obj1 'intersectwith obj2 [color=BLUE]acextendnone[/color])) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] pnt ([color=BLUE]vlax-curve-getstartpoint[/color] obj1) tmp ([color=BLUE]vla-addray[/color] spc ([color=BLUE]vlax-3D-point[/color] pnt) ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]polar[/color] pnt 0.0 1.0))) int ([color=BLUE]vlax-invoke[/color] tmp 'intersectwith obj2 [color=BLUE]acextendnone[/color]) ) ([color=BLUE]vla-delete[/color] tmp) ([color=BLUE]=[/color] 1 ([color=BLUE]rem[/color] ([color=BLUE]length[/color] int) 2)) ) ) ) ) ([color=BLUE]vl-remove[/color] obj1 lst) ) ([color=BLUE]setq[/color] inner ([color=BLUE]+[/color] inner ([color=BLUE]vla-get-area[/color] obj1)) ino ([color=BLUE]1+[/color] ino) ) ([color=BLUE]setq[/color] outer ([color=BLUE]+[/color] outer ([color=BLUE]vla-get-area[/color] obj1)) ono ([color=BLUE]1+[/color] ono) ) ) ) ([color=BLUE]setq[/color] dim ([color=BLUE]getvar[/color] 'dimzin)) ([color=BLUE]setvar[/color] 'dimzin 0) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nOuter Area: "[/color] ([color=BLUE]rtos[/color] outer 2 [color=MAROON]" from "[/color] ([color=BLUE]itoa[/color] ono) [color=MAROON]" object(s)."[/color] [color=MAROON]"\nInner Area: "[/color] ([color=BLUE]rtos[/color] inner 2 [color=MAROON]" from "[/color] ([color=BLUE]itoa[/color] ino) [color=MAROON]" object(s)."[/color] [color=MAROON]"\nTotal Area: "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]-[/color] outer inner) 2 ) ) ([color=BLUE]setvar[/color] 'dimzin dim) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Nice Lee Mac!!! Quote Link to comment Share on other sites More sharing options...
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.