Create workplane at the intersecting point of an axis and a face

By Xiaodong Liang

Question:
Is there a way to add a WorkPoint where an Axis and a Part Face Intersect?  I need this to be able to create a WorkPlane normal to the surface of the part at that location.

Solution:
TransientGeometry.CurveSurfaceIntersection can tell the intersecting points of a curve and a surface. And WorkPlanes collection provides the method AddByPointAndTangent creates a new work plane through the input point and tangent to the input surface. But this method does not accept Point as the argument.  We can workaround it by creating a tempeory sketch3d point. The code below demos it.

 

Sub addWPByIntersectPtAtFace()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
   
    Dim oWorkAxis As WorkAxis
    Set oWorkAxis = ThisApplication.CommandManager.Pick(kWorkAxisFilter, "pick an axis")
   
    Dim oFace As Face
    Set oFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "pick an face")
   
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
   
    Dim oObjs As ObjectsEnumerator
    Set oObjs = oTG.CurveSurfaceIntersection(oWorkAxis.Line, oFace.Geometry)
   
    ‘ assume only one intersect point
    Dim oIntersecPt As Point
    Set oIntersecPt = oObjs(1)
   
    ‘WorkPlanes.AddByPointAndTangent does not accept Point
    ‘ so use sketch3d point as an alternative
    Dim oDef As PartComponentDefinition
    Set oDef = oDoc.ComponentDefinition
   
    Dim oTemp3dSketch As Sketch3D
    Set oTemp3dSketch = oDef.Sketches3D.Add
   
    Dim oSketchPt3d As SketchPoint3D
    Set oSketchPt3d = oTemp3dSketch.SketchPoints3D.Add(oIntersecPt)
    
    Call oDef.WorkPlanes.AddByPointAndTangent(oSketchPt3d, oFace)
   
    ‘delete the temp sketch 3d
    oTemp3dSketch.Delete
   
   
End Sub


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading