Find Touching Area of Two Coplanar Faces - Manufacturing DevBlog

Find Touching Area of Two Coplanar Faces - Manufacturing DevBlog Manufacturing DevBlog The resource for software developers working with Design, Lifecycle and Simulation technologies from Autodesk. Home Subscribe Follow Useful Links Autodesk About this Blog « Parent of Mirror Solid | Main | Auto export driven dimension value to Excel » 01/26/2014 Find Touching Area of Two Coplanar Faces By Xiaodong Liang Two planar faces which are coplanar are not always overlapped. To know if they are overlapped and the touching area, one workaround could be extrude the sketches based on the faces with a tiny distance, and use TransientBRep.DoBoolean to check if the bodies of the two extrude features are intersected. The following is demo code. It assumes two planar faces are selected. One material named “Magenta” is available. Note: in UI, if the two planar faces are within one surface body and are overlapped, they cannot be selected independently. So to make a demo, it assumes the two planar faces are from different bodies. Of course, you can distinguish two faces from one surface body in the workflow of code.  Private Sub Test()           Try             'get application             oApp =                 System.Runtime.InteropServices.                 Marshal.GetActiveObject("Inventor.Application")         Catch         End Try           Dim oPartDoc As PartDocument = oApp.ActiveDocument         Dim oPartDef = oPartDoc.ComponentDefinition           'get face1         Dim oFace1 As Face         oFace1 = oPartDoc.SelectSet(1)         'get face2         Dim oFace2 As Face         oFace2 = oPartDoc.SelectSet(2)           'if two faces are planar and coplanar         If oFace1.SurfaceType =                 SurfaceTypeEnum.kPlaneSurface _                     And oFace2.SurfaceType =                     SurfaceTypeEnum.kPlaneSurface Then               Dim oPlane1 As Plane             oPlane1 = oFace1.Geometry             Dim oPlane2 As Plane             oPlane2 = oFace2.Geometry               ' if normal of two faces are same             If oPlane1.Normal.IsEqualTo(oPlane2.Normal) Then                   Dim extrudeDis As Double = 0.001                   'create the extrude feature from face1                 Dim oSketch1 As PlanarSketch =                     oPartDef.Sketches.Add(oFace1)                 Dim oEdgeInFace1 As Edge                 For Each oEdgeInFace1 In oFace1.Edges                     oSketch1.AddByProjectingEntity(oEdgeInFace1)                 Next                 Dim oProfile1 As Profile                 oProfile1 = oSketch1.Profiles.AddForSolid()                   Dim oExtrudeF1Def As ExtrudeDefinition                 oExtrudeF1Def =                     oPartDef.Features.ExtrudeFeatures.                     CreateExtrudeDefinition(oProfile1,                         PartFeatureOperationEnum.kNewBodyOperation)                 oExtrudeF1Def.SetDistanceExtent(extrudeDis,                         PartFeatureExtentDirectionEnum.kPositiveExtentDirection)                   Dim oExtrudeF1 As ExtrudeFeature                 oExtrudeF1 =                     oPartDef.Features.ExtrudeFeatures.Add(oExtrudeF1Def)                   Dim oSB1 As SurfaceBody                 oSB1 = oExtrudeF1.SurfaceBodies(1)                     'create the extrude feature from face2                 Dim oSketch2 As PlanarSketch =                     oPartDef.Sketches.Add(oFace2)                 Dim oEdgeInFace2 As Edge                 For Each oEdgeInFace2 In oFace2.Edges                     oSketch2.AddByProjectingEntity(oEdgeInFace2)                 Next                   Dim oProfile2 As Profile                 oProfile2 =                     oSketch2.Profiles.AddForSolid()                   Dim oExtrudeF2Def As ExtrudeDefinition                 oExtrudeF2Def =                     oPartDef.Features.ExtrudeFeatures.                     CreateExtrudeDefinition(oProfile2,                                  PartFeatureOperationEnum.kNewBodyOperation)                 oExtrudeF2Def.SetDistanceExtent(extrudeDis,                                  PartFeatureExtentDirectionEnum.                                   kPositiveExtentDirection)                   Dim oExtrudeF2 As ExtrudeFeature                 oExtrudeF2 =                     oPartDef.Features.ExtrudeFeatures.Add(oExtrudeF2Def)                   Dim oSB2 As SurfaceBody                 oSB2 = oExtrudeF2.SurfaceBodies(1)                   Dim oTransientB1 As SurfaceBody =                     oApp.TransientBRep.Copy(oSB1)                 Dim oTransientB2 As SurfaceBody =                     oApp.TransientBRep.Copy(oSB2)                   'check if bodies of the two extrude features are intersected                 oApp.TransientBRep.DoBoolean(oTransientB1,                                    oTransientB2,                                    BooleanTypeEnum.kBooleanTypeIntersect)                   If oTransientB1.Volume(0.01) > 0 Then                     MsgBox("The two faces are overlapped!")