Select all co-planar faces of a selected face in assembly

Select all co-planar faces of a selected face in assembly

Anonymous
Not applicable
1,159 Views
2 Replies
Message 1 of 3

Select all co-planar faces of a selected face in assembly

Anonymous
Not applicable

Hello Everyone,

 

Is there any way to select all co-planar faces of a selected face of a part in an assembly? I found a solution for the part context but still can not apply for the assembly.

 

Please help me in this case. Thanks in advance 🙂

 

Here is my code that I did try:

 

 

 

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

        g_assemblyDoc = g_inventorApplication.ActiveDocument

        Dim _selectSet As Inventor.SelectSet
        _selectSet = g_assemblyDoc.SelectSet

        For i = 1 To _selectSet.Count

            Dim _faceProxy As Inventor.FaceProxy
            _faceProxy = _selectSet.Item(i)

            Dim _face As Inventor.Face
            _face = _faceProxy.NativeObject

            Dim _doc As Inventor.Document
            _doc = _face.Parent.ComponentDefinition.Document

            Dim _partDoc As Inventor.PartDocument
            _partDoc = g_inventorApplication.Documents.ItemByName(_doc.FullDocumentName)

            Dim params(1) As Double
            params(0) = 0.5
            params(1) = 0.5

            ' Get point on surface at param .5,.5
            Dim points(2) As Double
            Call _face.Evaluator.GetPointAtParam(params, points)

            ' Create point object
            Dim oPoint As Inventor.Point
            oPoint = g_inventorApplication.TransientGeometry.CreatePoint(points(0), points(1), points(2))

            ' Get normal at this point
            Dim normals(2) As Double
            Call _face.Evaluator.GetNormal(params, normals)

            ' Create normal vector object
            Dim oNormal As Inventor.Vector
            oNormal = g_inventorApplication.TransientGeometry.CreateVector(normals(0), normals(1), normals(2))

            Dim RefPlane As Inventor.Plane
            RefPlane = g_inventorApplication.TransientGeometry.CreatePlane(oPoint, oNormal)

            Dim bodies As Inventor.SurfaceBodies
            bodies = _partDoc.ComponentDefinition.SurfaceBodies

            Dim BodyFace As Inventor.Face
            Dim PlaneB As Inventor.Plane

            For Each Body In bodies

                For Each BodyFace In Body.faces
                    If BodyFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
                        Call BodyFace.Evaluator.GetPointAtParam(params, points)
                        ' Create point object
                        oPoint = g_inventorApplication.TransientGeometry.CreatePoint(points(0), points(1), points(2))
                        Call _face.Evaluator.GetNormal(params, normals)
                        oNormal = g_inventorApplication.TransientGeometry.CreateVector(normals(0), normals(1), normals(2))
                        PlaneB = g_inventorApplication.TransientGeometry.CreatePlane(oPoint, oNormal)
                        'Check if they are co-planar
                        If PlaneB.IsCoplanarTo(RefPlane) Then
                            Call _partDoc.SelectSet.Select(BodyFace)
                        End If

                    End If
                Next
            Next

        Next

    End Sub

 

 

 

2020-06-08_11h42_27.png

0 Likes
Accepted solutions (1)
1,160 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

I don't know if you want all coplanar faces in the same part as the selected face or in the entire assembly.

Try this rule for all coplanar faces in the entire assembly:

Sub Main
	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oFace As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick face.")
	Dim oSelSet As SelectSet = oAsm.SelectSet

	For Each oOcc As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences.AllLeafOccurrences
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject
			Dim oDef As PartComponentDefinition = oOcc.Definition
			For Each oBod As SurfaceBody In oDef.SurfaceBodies
				For Each oBodFace As Face In oBod.Faces
					If oBodFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface
						Dim oFaceProx As FaceProxy = CreateFaceProxy(oOcc.OccurrencePath, oBodFace)
						If oFaceProx.Geometry.IsCoplanarTo(oFace.Geometry) Then oSelSet.Select(oFaceProx)
					End If
				Next
			Next
		End If
	Next
End Sub

Function CreateFaceProxy(oOccList As ComponentOccurrencesEnumerator, oFace As Face) As Object
	Dim oProx As Object
	For i = oOccList.Count To 1 Step -1
		If i = oOccList.Count
			Call oOccList(i).CreateGeometryProxy(oFace, oProx)
		Else
			Call oOccList(i).CreateGeometryProxy(oProx, oProx)
		End If

	Next
	Return oProx
End Function

And this to only get the coplanar faces in the same part as the selected face:

Sub Main
	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oFace As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick face.")
	Dim oSelSet As SelectSet = oAsm.SelectSet
	Dim oOcc As ComponentOccurrence = oFace.ContainingOccurrence
	Dim oDef As PartComponentDefinition = oOcc.Definition
	For Each oBod As SurfaceBody In oDef.SurfaceBodies
		For Each oBodFace As Face In oBod.Faces
			If oBodFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface
				Dim oFaceProx As FaceProxy = CreateFaceProxy(oOcc.OccurrencePath, oBodFace)
				If oFaceProx.Geometry.IsCoplanarTo(oFace.Geometry) Then oSelSet.Select(oFaceProx)
			End If
		Next
	Next
End Sub

Function CreateFaceProxy(oOccList As ComponentOccurrencesEnumerator, oFace As Face) As Object
	Dim oProx As Object
	For i = oOccList.Count To 1 Step -1
		If i = oOccList.Count
			Call oOccList(i).CreateGeometryProxy(oFace, oProx)
		Else
			Call oOccList(i).CreateGeometryProxy(oProx, oProx)
		End If

	Next
	Return oProx
End Function

 

 

Message 3 of 3

Anonymous
Not applicable

Thanks, Mr. @JhoelForshav 

The second case is what I need! That works so great! 🙂

 

0 Likes