need intersection point of curved surface and 2 planes in assembly.

need intersection point of curved surface and 2 planes in assembly.

tmathieson
Advocate Advocate
868 Views
6 Replies
Message 1 of 7

need intersection point of curved surface and 2 planes in assembly.

tmathieson
Advocate
Advocate

Hello All,

 

i need to find  the intersection point of a curved surface and two planes in an assembly as shown in the attachment. it seems like this can't be done in the assembly level but only in a part level.  in this screen shot, i open the curved top in the assembly,  started a sketch on the correct plane (IN MY PART), projected cut edge (gives me the cylinder face), import the 2nd plane from the assembly (never understand why this has to be done. other software allow you to dim to assembly planes directly), create a point, then constrain the point to the imported plane and curve...

 

  • is this the only way to get an intersection point into an assembly as described... plane,plane,cylindrical face ?
  • i have tried just creating a 2D sketch in the assembly, but when doing so, the "project cut edges" is greyed out

 

of course, i want to program this into our rules/programs, so just want to be sure i am approaching this correctly.

 

thanks to All for any suggestions!!

0 Likes
Accepted solutions (1)
869 Views
6 Replies
Replies (6)
Message 2 of 7

earl_cody
Contributor
Contributor

@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
Message 3 of 7

tmathieson
Advocate
Advocate

@earl_cody, thanks for this code!!  i copied/paste into the VBA editor, made a couple changes (my preferences, nothing wrong with code), and it works great!!  i am now trying to adapt it to Ilogic, but get an error "Array is a type and cannot not be used in an expression"....  on the crossProduct line...

 

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

 any suggestions on how to fix this?  is adapting this code to Ilogic doable (i think so)?

 

really appreciate your help on this

0 Likes
Message 4 of 7

earl_cody
Contributor
Contributor

@tmathieson - Glad you found it useful!

 

For iLogic, you can use curly brackets {1, 2, 3} instead of Array(1, 2, 3).

...
Dim cp As Object
cp = CrossProduct( _
    v1:= {uvPlaneOneNormal.X, uvPlaneOneNormal.Y, uvPlaneOneNormal.Z}, _
    v2:= {uvPlaneTwoNormal.X, uvPlaneTwoNormal.Y, uvPlaneTwoNormal.Z })
...
Function CrossProduct(v1 As Object, v2 As Object) As Object
    CrossProduct = { _
        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

 

Message 5 of 7

tmathieson
Advocate
Advocate

hI @earl_cody ,

 

Thanks again for your help with this.  i have the code in iLogic and it works great when i run it interactively, (manually pick planes and surface).  however, i am trying to hard code the plane in as they are always the same two, just the surface changes. however, i am having an issue assigning them.  i can cycle thru the assy and find the planes, think i am assigning them correctly, but the axis is drawn thru the XZ and XY planes not the XZ and INSIDE RISE-AREA. i assume i am doing something wrong here in this For loop, but not sure what. i've also attached a zip file with my test assembly

For Each oWorkPlane In asmdoc.ComponentDefinition.WorkPlanes   
Logger.Debug(oWorkPlane.Name & "...." & I)
			If InStr(oWorkPlane.name, "YZ Plane") Then
			Logger.Debug(oWorkPlane.Name & "... plane 1" )
			planeOne = oWorkPlane
		End If
			If InStr(oWorkPlane.name, "INSIDE AREA-RISE") Then
				'oworkPlane.delete
				Logger.Debug(oWorkPlane.name)' & oWorkPlane.ITEM())
				planeTwo = oWorkPlane
				Logger.Debug(planeTwo.Name & ".....PLANE 2..." & planeOne.Name)
			End If
			I = I+1
Next
' planeOne = inv.CommandManager.Pick(kWorkPlaneFilter, "pick first plane") ' THESE WORK IF UNCOMMENTED
' planeTwo = inv.CommandManager.Pick(kWorkPlaneFilter, "pick second plane") ' THESE WORK IF UNCOMMENTED

 again, really appreciate your help with this.  the planes are in the top level assembly, so i shouldn't need a Proxy? or do I? or do i need to assign planeOne and PlaneTwo by another means, such as

"planeTwo = asmdoc.ComponentDefinition.WorkPlanes.Item(I)" ?  (have tried this but not luck)....

 

Any insight as to why this works interactively but not hard code would save me some grey matter :+)

 

than ks to All for looking!

0 Likes
Message 6 of 7

earl_cody
Contributor
Contributor
Accepted solution

Hi @tmathieson. No problem! 

 

You will need to create an extent point: the maximum distance from the origin about both plane's root point. Then use that extent point as the input point for creating the work axis. The extent root point is needed now since the scope no longer involves just origin planes with (0,0,0) root points. 

 

VBA

...
'extent point
Dim extentX As Double
Dim extentY As Double
Dim extentZ As Double

If (Abs(planeOne.Plane.RootPoint.x) >= Abs(planeTwo.Plane.RootPoint.x)) Then
    extentX = planeOne.Plane.RootPoint.x
Else
    extentX = planeTwo.Plane.RootPoint.x
End If

If (Abs(planeOne.Plane.RootPoint.y) >= Abs(planeTwo.Plane.RootPoint.y)) Then
    extentY = planeOne.Plane.RootPoint.y
Else
    extentY = planeTwo.Plane.RootPoint.y
End If

If (Abs(planeOne.Plane.RootPoint.Z) >= Abs(planeTwo.Plane.RootPoint.Z)) Then
    extentZ = planeOne.Plane.RootPoint.Z
Else
    extentZ = planeTwo.Plane.RootPoint.Z
End If

Dim pointExtent As Inventor.Point
Set pointExtent = tg.CreatePoint( _
    xcoord:=extentX, _
    ycoord:=extentY, _
    zcoord:=extentZ)

'work axis
Dim wa As Inventor.WorkAxis
Set wa = asmdoc.ComponentDefinition.WorkAxes.AddFixed( _
    Point:=pointExtent, _
    Axis:=inv.TransientGeometry.CreateUnitVector(cp(0), cp(1), cp(2)))
...

 

For getting planes with names, you can just write the name in the .items collection to retrieve them. And you're correct, no need for proxies for the planes since they are in the root assembly document.

...
planeOne = asmdoc.ComponentDefinition.WorkPlanes.Item("YZ Plane")
planeTwo = asmdoc.ComponentDefinition.WorkPlanes.Item("INSIDE AREA-RISE")
...

 

Message 7 of 7

tmathieson
Advocate
Advocate

 thanks,@earl_cody !  yes, i was working on this this weekend, and realized that the code was correct, and that the origin of my axis was wrong.  in this particular case, moving  the origin to the 'planeTwo' origin works, but may need to modify code in future as you suggest.  before i saw this post, i thought creating a work point at the intersection of three planes should work for the axis origin....

from your help, and picking some snippets up from some of other posts, have it pretty well automated to whatw e were looking for. but always room for improvements ! :+)

 

 

appreciate your help!! have a good one!!

0 Likes