a layer (LayerTableRecord) is no geometrey object, so it has no area as property or to calculate.
Can you try to declare it in other words?
- alfred -
>> or can you please guide me, how to calculate all entity/object wise of a layer ?
What objecttypes are you working with? Not every object has an area, e.g. Node, Text, Dimensions, BlockReference, also 3D-Solids and a lot more.
The easiest way would be to create a selectionset that is filtered to the layername you like. Then you can scan through the entities within the selectionset and verify if the objecttype is derived from type DatabaseServices.Curve and then if it's property "closed" = true, if so you can read the area-property.
That's the theory, but there are also a lot of obstacles to get passed like 3d-polyline or self-crossing polylines or how to work with solids, with polylines in blocks, objects not oriented plane to XY, ....
Can you describe how your drawings are structures (or upload a typical sample drawing you have to test your app) and what your goal is with this area-calculation?
- alfred -
We have a floor drawing file which contains few layers like Exterior Wall, Interior Wall, etc.
We have to calculate the square feet of the area covered by each layer.
Could you please guide us how to calculate the total area covered by these layers?
>> We have to calculate the square feet of the area covered by each layer.
And again I don't know what object-types you are speaking from. Are these walls polylines or lines or walls created by Autodesk-Architecture?
BTW: do you really want to calculate the area of the wall(s)? ... or is it the area of the rooms you want to get?
- alfred -
The object types are polylines.
Here is the attached sample dwg file screen shot.
I have shown the layers that are present in the dwg file and the spaces that are present in those layers.
I want to calculate the area of the spaces that are associated with the layers.
without island-calculation and to verify the results!
''' <summary>calcAreaPLinesByLayer scans through the modelspace and calculates areas of closed polylines (dxf-typename like *POLYLINE*)</summary> ''' <remarks></remarks> <Autodesk.AutoCAD.Runtime.CommandMethod("calcAreaP
LinesByLayer")> _ Public Shared Sub calcAreaPLinesByLayer() Dim tCumArea As SortedList(Of String, Double) = New SortedList(Of String, Double) Dim tEd As Editor = Application.DocumentManager.MdiActiveDocument.Edit or Dim tDb As Database = Application.DocumentManager.MdiActiveDocument.Data base Dim tTrAct As Transaction = Nothing Try tTrAct = tDb.TransactionManager.StartTransaction 'get BlockTable Dim tBlTab As BlockTable = CType(tTrAct.GetObject(tDb.BlockTableId, OpenMode.ForRead), BlockTable) 'get ModelSpace Dim tModSp As BlockTableRecord = CType(tTrAct.GetObject(tBlTab("*MODEL_SPACE"), OpenMode.ForRead), BlockTableRecord) 'scan through ModelSpace For Each tObjID As ObjectId In tModSp If (tObjID.IsValid) AndAlso (Not tObjID.IsErased) AndAlso (tObjID.ObjectClass.DxfName Like "*POLYLINE*") Then Dim tCurve As Curve = CType(tTrAct.GetObject(tObjID, OpenMode.ForRead), Curve) If tCurve.Closed OrElse (tCurve.StartPoint.DistanceTo(tCurve.EndPoint) < 0.0000001) Then 'ok, it's a poly and it's closed Try Dim tArea As Double = tCurve.Area Dim tLayer As String = tCurve.Layer If tCumArea.ContainsKey(tLayer) Then tCumArea.Item(tLayer) += tArea Else tCumArea.Add(tLayer, tArea) End If Catch ex2 As Exception tEd.WriteMessage(vbNewLine & "Error calculating area for Polyline Handle = &h" & Hex(tCurve.Handle.Value) & ", EX2 = " & ex2.Message) End Try End If End If Next 'now write the areas counted/cumulated For Each tItem As KeyValuePair(Of String, Double) In tCumArea tEd.WriteMessage(vbNewLine & tItem.Key & ": " & tItem.Value.ToString) Next Catch ex As Exception tEd.WriteMessage(vbNewLine & "Unknown Error occured, EX = " & ex.Message) Finally If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing End Try End Sub
- alfred -
I am having a similar kind of doubt,
How can we find the area of particular objectID for the same dwg file?
Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection() Dim acSSet As SelectionSet = acSSPrompt.Value Dim acObjId As ObjectId For Each acObjId In acSSet.GetObjectIds() acObjIdColl.Add(acObjId) Next
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.