Author Topic: Area property behaviour  (Read 4788 times)

0 Members and 1 Guest are viewing this topic.

pjm8765

  • Guest
Area property behaviour
« on: November 17, 2017, 07:48:42 AM »
I have the following code to identify the area of a polyline in a block (the outline of a concrete slab) and the cumulative area of polylines used to identify holes in one of these blocks/slabs :

Code: [Select]
    Public Sub GetSlabAndHoleAreas(ByVal slabBlock As AcadBlock, ByRef slabArea As Double, ByRef holeArea As Double)

        Dim entity As AcadEntity

        Try

            'Extract the slab outline area and hole areas in mm2

            slabArea = 0
            holeArea = 0

            For Each entity In slabBlock
                'Find the largest outline i.e. the slab outline
                If entity.ObjectName = "AcDbRegion" Then
                    If entity.Area > slabArea Then
                        slabArea = entity.Area
                    End If
                End If
                'Find the holes
                If entity.Layer = EASICAD_LAYERS.HOLE_SYMBOL Or entity.Layer = EASICAD_LAYERS.COLUMN_CUTOUT_SYMBOL Then
                    holeArea += entity.Area
                End If
            Next

        Catch ex As Exception
            MsgBox("Reusable.GetSlabAndHoleAreas : " & ex.Message, MsgBoxStyle.OkOnly, EasiCADException.EasiCADErrorTitle)
        End Try
    End Sub

I have inherited the logic, which does work and have refactored it to this routine to standardise the output...which has made me interrogate the numbers being generated.  These don't make sense to me.  The slabArea variable is reporting the area of the slab minus the cumulative areas of the holes. 

The help for this property https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-ActiveX/files/GUID-2D31D8C1-9BEC-48CF-8B73-E2AD38A08D74-htm.html doesn't say anything about this behaviour and it's not something I would expect.  But the software is working.

Can anyone explain to me why these closed polyline areas are removed from the total area of the main outline polyline?

Kind regards, Paul

RICVBA

  • Newt
  • Posts: 62
Re: Area property behaviour
« Reply #1 on: November 19, 2017, 03:09:41 AM »
your code is not VBA one, but your question is code independent

slabArea is evaluated as the greatest area out of all region objects found in the block
from what you wrote, those regions (or, at least, the one with the greatest area) are most likely the result of some preceeding subtraction boolean operation on two or more original regions so as that "The area equals the combined area for all the objects in the region."

while holeArea is evaluated as the sum of all entities belonging to two specific layers which are likely to host only "simple" polylines or regions (but Arcs, Circles, Ellipses, Hatches and Splines are eligible for Area property, as well)

you may want to post your dwg to see what's in it

pjm8765

  • Guest
Re: Area property behaviour
« Reply #2 on: November 21, 2017, 11:39:40 AM »
Thanks.  I've been using this part of the forum because although .NET based most of the code I look after is ActiveX/COM based, not true .NET.  But if I should use the .NET part for this kind of question I shall in the future.

So each region in the block stores the area as an attribute rather than calculating at run time?  That seems a bit weird to me, but it isn't the first time AutoCAD has seemed a bit weird to me.  What you're saying is exactly what seems to happen.  The code that adds a hole to a floor area or a single slab at one point does this :

Code: [Select]
         .....
                explodedRegion = holeRegion.Explode

                'Subtract the hole from the slab outline
                'This actually changes the outline of the slab!
                floorOutlineRegion.Boolean(AcBooleanType.acSubtraction, holeRegion)
         .....

Where the floorOutlineRegion is the entire floor area that each slab gets layed on to eventually (some containing the hole, or the hole becoming a notch, some not at all).

Thanks, that makes sense now.  I'll know what to look for in future.