Section View Profile Area calculation

Section View Profile Area calculation

sahin.ikbal
Advocate Advocate
876 Views
5 Replies
Message 1 of 6

Section View Profile Area calculation

sahin.ikbal
Advocate
Advocate

I want to calculate the section's closed profiles area.I have taken some reference from here- https://github.com/jeremytammik/SectionCutGeo 


But I have two problems after that

1.How can I get the non-line curves from this view, for now I can get lines only.
2.How can I calculate the area enclosed by closed looped curves in a plane.

How would you suggest me to go about this problem?

Picture1.png

0 Likes
Accepted solutions (1)
877 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

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 endsCylinder with spherical ends

Section 1Section 1

Detail view within Section 1Detail 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

 

 

Message 3 of 6

sahin.ikbal
Advocate
Advocate

Thank You Very Much @RPTHOMAS108.

It's working Perfectly.

0 Likes
Message 4 of 6

sahin.ikbal
Advocate
Advocate

If some element is in link file how can I do it then?
@RPTHOMAS108 can you help me out here....

0 Likes
Message 5 of 6

RPTHOMAS108
Mentor
Mentor

The issue with that is when you extract the geometry by view the view will be in the wrong document. So if you provide that in the options it is ignored.

 

If you create a temporary copy of the linked document you can open it in the background to create a view in that matching your source view. You would have to transform the position of the view in terms of how the source view extent sits in the linked document rather than the source document. Then you can perhaps process the elements in the same way in the copy of the linked document as you would do without links.

 

Would suggest copying the linked document so you don't have to unload it in the source document.

 

The alternative to the above would be you get the bounding box of the view extent, transform that into the link document to filter elements there. The solids of those elements can then be used to create a direct shape in the source document that you can then cut.

 

You have to bring one thing to the other either way.

Message 6 of 6

sahin.ikbal
Advocate
Advocate

Thanks, will try to implement your suggestions.

0 Likes