When you cut a solid with a view the view specific geometry creates a planar face in the view plane.
This planar face has a FaceNormal matching the view direction.
The edges of the planar face have a graphics style with GraphicsStyleType.Cut.
You can get the area directly from the planar face.
Cylinder with spherical ends
Section 1
Detail view within Section 1
Public Function Obj_220209a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result
Dim app = commandData.Application
Dim uidoc = commandData.Application.ActiveUIDocument
Dim IntDoc = uidoc.Document
Dim GView As View = uidoc.ActiveGraphicalView
Dim R As Reference = Nothing
Try
R = uidoc.Selection.PickObject(Selection.ObjectType.Element, "Pick object to cut.")
Catch ex As Exception
Return Result.Cancelled
End Try
Dim Ops As New Options With {.View = GView, .ComputeReferences = False, .IncludeNonVisibleObjects = False}
Dim El As Element = IntDoc.GetElement(R)
Dim GeomEl As GeometryElement = El.Geometry(Ops)
If GeomEl Is Nothing Then
TaskDialog.Show("Error", "No available geometry")
Return Result.Cancelled
End If
Dim Area As Double = 0
Dim SList As Solid() = ExtractSolids(GeomEl)
For i = 0 To SList.Length - 1
Dim FList As FaceArray = SList(i).Faces
For ia = 0 To FList.Size - 1
Dim PF As PlanarFace = TryCast(FList(ia), PlanarFace)
If PF Is Nothing Then Continue For Else
If PF.FaceNormal.IsAlmostEqualTo(GView.ViewDirection) = False Then Continue For Else
If FaceWithCutEdges(IntDoc, PF) = False Then Continue For Else
Area += PF.Area
Using Tx As New Transaction(IntDoc, "Draw cut edges")
If Tx.Start = TransactionStatus.Started Then
Dim PL As Plane = Plane.CreateByNormalAndOrigin(PF.FaceNormal, PF.Origin)
Dim SKP As SketchPlane = SketchPlane.Create(IntDoc, PL)
Dim EdgeLoops As EdgeArrayArray = PF.EdgeLoops
For ib = 0 To EdgeLoops.Size - 1
Dim EA As EdgeArray = EdgeLoops(ib)
For ic = 0 To EA.Size - 1
Dim ed As Edge = EA(ic)
Dim C As Curve = ed.AsCurve
IntDoc.Create.NewModelCurve(C, SKP)
Next
Next
Tx.Commit()
End If
End Using
Next
Next
End Function
Private Function FaceWithCutEdges(D As Document, PF As PlanarFace) As Boolean
Dim EdgeLoops As EdgeArrayArray = PF.EdgeLoops
Dim Ed As Edge = EdgeLoops.Item(0).Item(0)
If Ed.GraphicsStyleId = ElementId.InvalidElementId Then
Return False
End If
Dim GSEl As GraphicsStyle = D.GetElement(Ed.GraphicsStyleId)
Return GSEl.GraphicsStyleType = GraphicsStyleType.Cut
End Function
Private Function ExtractSolids(GE As GeometryElement) As Solid()
Dim SList As New List(Of Solid)
Dim GeomObs As GeometryObject() = GE.ToArray
For i = 0 To GeomObs.Length - 1
Dim GeomOb As GeometryObject = GeomObs(i)
Select Case GeomOb.GetType
Case GetType(Solid)
SList.Add(GeomOb)
Case GetType(GeometryInstance)
Dim GInst As GeometryInstance = GeomOb
Dim j = ExtractSolids(GInst.GetInstanceGeometry)
If j.Length > 0 Then
SList.AddRange(j)
End If
Case Else
End Select
Next
Return SList.ToArray
End Function