Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
earl_cody
in reply to: tmathieson

@tmathieson - Hi. Here's an attempt with VBA at creating a workpoint(s) in an assembly that locates the intersection of two planes and a curved surface. You can determine the line of intersection from the two chosen planes by computing the cross product of their normal vectors. From there, you can use the intersecting line's ".IntersectWithSurface()" method to create a collection of viable points. A further check then determines if the point is actually on the chosen cylindrical face. 

Sub Main()

Dim inv As Inventor.Application
Set inv = ThisApplication

Dim tg As Inventor.TransientGeometry
Set tg = inv.TransientGeometry

Dim asmdoc As Inventor.AssemblyDocument
Set asmdoc = inv.ActiveDocument

Dim planeOne As Inventor.WorkPlane
Dim planeTwo As Inventor.WorkPlane

'Set planeOne = asmdoc.ComponentDefinition.WorkPlanes.Item(1)
'Set planeTwo = asmdoc.ComponentDefinition.WorkPlanes.Item(2)
Set planeOne = inv.CommandManager.Pick(kWorkPlaneFilter, "pick first plane")
Set planeTwo = inv.CommandManager.Pick(kWorkPlaneFilter, "pick second plane")

Dim uvPlaneOneNormal As Inventor.UnitVector
Dim uvPlaneTwoNormal As Inventor.UnitVector

Set uvPlaneOneNormal = planeOne.Plane.Normal
Set uvPlaneTwoNormal = planeTwo.Plane.Normal

Dim cp As Variant
cp = CrossProduct( _
    v1:=Array(uvPlaneOneNormal.X, uvPlaneOneNormal.Y, uvPlaneOneNormal.Z), _
    v2:=Array(uvPlaneTwoNormal.X, uvPlaneTwoNormal.Y, uvPlaneTwoNormal.Z))

'Debug.Print ("a(x-x0) + b(y-y0) + c(z+z0) = 0")
'Debug.Print (uvPlaneOneNormal.X & "(x-" & planeOne.Plane.RootPoint.X & ") + " & uvPlaneOneNormal.Y & "(y-" & planeOne.Plane.RootPoint.Y & ") + " & uvPlaneOneNormal.Z & "(z-" & planeOne.Plane.RootPoint.Z & ")")
'Debug.Print (uvPlaneTwoNormal.X & "(x-" & planeTwo.Plane.RootPoint.X & ") + " & uvPlaneTwoNormal.Y & "(y-" & planeTwo.Plane.RootPoint.Y & ") + " & uvPlaneTwoNormal.Z & "(z-" & planeTwo.Plane.RootPoint.Z & ")")

Dim wa As Inventor.WorkAxis
Set wa = asmdoc.ComponentDefinition.WorkAxes.AddFixed( _
    Point:=planeOne.Plane.RootPoint, _
    Axis:=inv.TransientGeometry.CreateUnitVector(cp(0), cp(1), cp(2)))
                                  
Dim surfCurve As Inventor.Face
Set surfCurve = inv.CommandManager.Pick(kPartFaceCylindricalFilter, "pick a cylindrical face")

Dim pColl As Inventor.ObjectsEnumerator
Set pColl = wa.Line.IntersectWithSurface(surfCurve.Geometry)

Dim foundPoint As Boolean
foundPoint = False

If Not pColl Is Nothing Then
    For Each Point In pColl
        If surfCurve.GetClosestPointTo(Point).IsEqualTo(Point) Then
               asmdoc.ComponentDefinition.WorkPoints.AddFixed (Point)
               If foundPoint = False Then
                   foundPoint = True
               End If
        End If
    Next
End If

If foundPoint = False Then
    Call MsgBox("No intersection points found. :(")
End If

End Sub

Function CrossProduct(v1 As Variant, v2 As Variant) As Variant
    CrossProduct = Array( _
        v1(1) * v2(2) - v1(2) * v2(1), _
        v1(2) * v2(0) - v1(0) * v2(2), _
        v1(0) * v2(1) - v1(1) * v2(0))
End Function