News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Calculate area of irregular shape?

Started by Jennifer, November 23, 2011, 10:21:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jennifer

Is there a way to calculate the area of an irregular shape?

For my immediate purpose, I'd be happy with a shape made from the line tool (polygons). I don't need to be able to calculate the area of a shape with curved edges or from the pencil tool.

If Visio can't do this, it there a simple graphics program that can?
Using Visio 2019, part of Office 365 on Windows 10


Jennifer

I looked at that post when it was posted (by you, I think) in response a differnet question. I tried to understand it, but when I found that I would have to download code, I got spooked. First of all, I would probably screw it up and maybe screw up everything. Socondly, I am very wary of installing add-ins and then having to migrate them whenever I upgrade the product.

Is there a simple step-by-step procedure for installing this Method that I won't mess up?

I'll be upgrading Visio soon. Will I need to redo this procedure?

Finally, and most importantly, will it calculate the area for very complex shapes drawn with the line tool?
Using Visio 2019, part of Office 365 on Windows 10

aledlund

There is no native method to determine what you are asking for, you're going to have to do it with code.

Let's start with the last question "will it calculate the area for very complex shapes drawn with the line tool?". 
Shapes are a combination of the geometry section in the shapesheet and subshapes. Shapes drawn with the line tool are individual shapes unless they have been combined with one of the shape operations (combine, union, etc.). You can test this with a fill operation, to see if the fill stays inside what you have built. Will it work with your shapes? Only testing will tell.

"I'll be upgrading Visio soon. Will I need to redo this procedure" The code is vba and should be level independent. It's not an add-in. It does require you to add some custom fields to your shapes, but that shouldn't be a problem since they are your shapes to begin with.

Are there directions? Only what is in the post. You might consider replying to it on David's forum.

al

JuneTheSecond

"Using Visio 2003 Pro on Win XP"

Tools/Addons/Run Addon/... (Menus may not be accurate, as I have not Visio 2003 Pro. )
Is this too simple?
Best Regards,

Junichi Yoda
http://june.minibird.jp/

wapperdude

#5
If you're just looking for the area, then the "Space" shape should work.  It's on the Walls, Doors and Windows stencil.

Draw your shape, drag the space shape onto your shape.  Resize the space shape to fit within the shape.  Right click the space shape, select autosize.  A popup may occur asking you to select the shape to measure -- do that, keeping the popup open. 

See sample below.

HTH
Wapperdude
Visio 2019 Pro

Jennifer

This looks like just what I need. But I can't get the units to work.

I set up a standard 8.5 x 11 page, landspace. I set up the Drawing scale to be No scale (1:1) and the measurement units to be inches.

I dragged a Space shape onto the page. The Size & Position table says it's 1.25" x 1.25", but the text says

     Office
     100 sq. ft.

If I resize it to 2" x 2", it says the area is 256 sq ft.

I placed a rectangle shape and sized it to be 2"x2". I followed your instructions above and got the same 2"x2" Space reporting 256 sq ft.

I then drew a 2x2 shape with a 1 sq in triangle cut into one side using the line tool. When I autosize the Space shape on that one, it reports 192 sq ft. 192 is 3/4 of 256, which is the right proportions.

Somehow, the Space shape thinks my page is scaled to 1/8" = 1 ft. I checked the page properties and it's set to 1:1.

If I can get the units figured out, this should do the job.
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

You'll probably have to do a couple of things.
1.)  Delete the existing Space shape.
2.)  Next set the page properties to have a scale with have units, e.g., 1 ft = 1 ft or 1 in = 1 in.  Either one preserves the 1:1 scale you currently have.
3.)  Place a new Space shape.  It will probably be huge relative to your page and need shrinking.  Easy way is to have the size and position window displayed, and type in new dimensions for the Space shape, e.g., 6 in wide and 6 in tall.

Now proceed as before.

HTH
Wapperdude
Visio 2019 Pro

Jennifer

OK, that works. I actually did that before, but didn't delete the existing Space shapes. What difference does that make?

Now all I need to do is change the units on the text. It now reports every shape as "0 sq ft". How can I change the display to show something like "0.0 sq in". (And get rid of the "Office" text.)
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

Off to Thanksgiving dinner with friends...

Right click the space shape, the popup menu gives units options.  Don't immediately recall the "office" issue...Visio help on that shape might provide info.

It may be necessary to dig into the shapesheet to get the precision display you need.
Visio 2019 Pro

Jennifer

#10
I finally got it to work.

It is a fairly involved and non-intuitive procedure:

1.   Define the page properties before adding the Space shape. It will inherit the units when placed, but will not change if the page properties are changed.
   a.   File | Page Setup....
   b.   Drawing Scale | Custom scale | 1 in = 1 in (or whatever) but not No Scale (1:1).
   c.   Page Properties | Measurement units | Inches (or whatever).
2.   Create the target shape whose area is to be calculated.
3.   Have the Size & Position panel open.
4.   Drag a Space shape to the page. It defaults to 10' x 10', so it will be huge for regular pages.
5.   Resize: Drag the edges or change the dimensions on the Size & Position panel.
6.   Change the units: Right click | Set Display Options... | Set the Units and Precision at the bottom
7.   Get rid of the "Office" text: Right click | Properties | Clear the Space use field.
8.   Shrink the Space shape so that it can fit entirely within the target shape (and free of any cutouts).
9.   Fit the Space shape to the target shape: Right click | Autosize.
   a.   If the Autosize pop-up appears (as it usually will), click on the target shape without closing the pop-up.
   b.   Verify that the target shape is selected.
   c.   Click OK.
   d.   The Space shape will expand to fill the target shape and the area is displayed.
10.   The Space shape can now be moved, deleted, copied, or resized. It is not attached to the target shape and the target shape is not

This method seems to work on any closed shape. I used it on an outline I made of a train engine using the like tool with about 100 segments. It took 20-30 seconds to calculate the area.

It works with cutouts. I created a 3"x3" square with a 1"x1" square cutout using fragment. The Space shape reported 8.00 sq in.

Thanks, wapperdude. That was a fun way to spend Thanksgiving. :)


PS: Before I had this Space shape method, I was using rectangles and triangles with a field set to display the area to estimate the area of the target shape.

In method 1, I created a rectangle around the entire shape. Then I created little rectangles around the cutouts. Where there were irregular edges, I just estimated by eyeball trying to have as much image inside the shape as cutout outside. I'd then add them up and subtract from the total area.

In method 2, I crated little rectangles around the image "pieces" working around the cutouts.

Interestingly, all three methods gave the same answer to within about 1-2%. For complicated shapes, the little rectangles is simpler and quicker.
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

Gee!  Glad I could contribute in a small way to a memorable Thanksgiving Day for you!   ???   ;D

Yep.  Those are the steps.  Although, Step 8 may not be necessary.  When measuring the area of a floorplan which has walls, then step 8 does allow a single click auto fill.  But, for general shapes, that doesn't seem to work.  But the sequence of steps 9a-c doesn't require that the space shape to be initially within the bounds of the shape to be measured. 

So, consider step 8 optional.

Wapperdude
Visio 2019 Pro

Jennifer

On my system, if the Space shape did not fit entirely within the target shape, it would not work.

Since Visio obviously knows how to calculate areas, it's really too bad that "area" & "perimeter" aren't in the Geometry options in the Field control. So much simpler than the arcane procedure above.
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

Totally agree.

The space shape could/would be a great candidate as an add-on.
Visio 2019 Pro

JuneTheSecond

#14
I wonder if VBA macro is acceptable.


Option Explicit

Sub GetArea()
    Dim shp As Visio.Shape
    Dim xy() As Double
    Dim I As Long
    Dim s As Double
    Set shp = ActivePage.Shapes(1)
    shp.Paths(1).Points 0#, xy
    For I = LBound(xy) To UBound(xy) - 5 Step 2
        s = s + ((xy(I + 2) - xy(0)) * (xy(I + 5) - xy(1)) - (xy(I + 3) - xy(1)) * (xy(I + 4) - xy(0))) / 2#
    Next
       
    s = Abs(s)
       
    Debug.Print s & " in^2"
    Debug.Print s * 25.4 ^ 2 & " mm^2"
   
    shp.Text = s * 25.4 ^ 2 & " mm^2"
   
End Sub

Best Regards,

Junichi Yoda
http://june.minibird.jp/

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 391 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1270KB.
Tokens: post-login.
Cache hits: 14: 0.00214s for 26,725 bytes (show)
Cache misses: 3: (show)
Queries used: 15.

[Show Queries]