Jump to content

Help to calculate Area!


lossan805

Recommended Posts

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.

 

Area2.jpg

 

Maybe there is a better way to do it? Any help would be appreciated.

 

Thanks.

Edited by lossan805
Revised picture
Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • lossan805

    8

  • Lee Mac

    6

  • Dadgad

    5

  • amarcon

    4

Top Posters In This Topic

Posted Images

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Did you click the LEE MAC link, and look at the total area function in that lisp? :)

 

I am evaluating that routine right now..

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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])

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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])

Link to comment
Share on other sites

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

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