Co-planar faces

Co-planar faces

DWhiteley
Advisor Advisor
797 Views
1 Reply
Message 1 of 2

Co-planar faces

DWhiteley
Advisor
Advisor

I've selected a face on a part & I wish to select any other faces that are co-planar to it (in the same part).

 

Can anyone suggest a way to do this in the API?

 

Thanks in advance,

 

Dave Whiteley

Envisage Uk Ltd

0 Likes
Accepted solutions (1)
798 Views
1 Reply
Reply (1)
Message 2 of 2

Mario-Villada
Advocate
Advocate
Accepted solution

Hi Dave, I think you can achieve this by using the metgod IsCoplanarTo for planes. So basically you can create a plane from the selected planar face and then cycle through all faces in the part, create a plane from each planar face and check if it is coplanar.

try this VBA Code:

 

Public Sub SelectCoplanarFaces()
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    
    If Not TypeOf oDoc.SelectSet(1) Is Face Then
        MsgBox "A face must be selected."
        Exit Sub
    End If
    
    Dim oFace As Face
    Set oFace = oDoc.SelectSet(1)
    
    If Not oFace.SurfaceType = kPlaneSurface Then
        MsgBox "A Flat face must be selected."
        Exit Sub
    End If
    
       
       
    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 oFace.Evaluator.GetPointAtParam(params, points)
    
    ' Create point object
    Dim oPoint As Point
    Set oPoint = ThisApplication.TransientGeometry.CreatePoint(points(0), points(1), points(2))
        
    ' Get normal at this point
    Dim normals(2) As Double
    Call oFace.Evaluator.GetNormal(params, normals)
    
    ' Create normal vector object
    Dim oNormal As Vector
    Set oNormal = ThisApplication.TransientGeometry.CreateVector(normals(0), normals(1), normals(2))
    
    
    Dim RefPlane As Plane
    Set RefPlane = ThisApplication.TransientGeometry.CreatePlane(oPoint, oNormal)
    
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    
    Dim bodies As SurfaceBodies
    Set bodies = oPartDoc.ComponentDefinition.SurfaceBodies

    Dim BodyFace As Face
    Dim PlaneB As Plane
    
    For Each Body In bodies

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

End Sub

Hope this Helps.

 

 

Mario.