Intersection of Work Features (Planes/Axis) in Assemblies - Need tips

Intersection of Work Features (Planes/Axis) in Assemblies - Need tips

llorden4
Collaborator Collaborator
875 Views
1 Reply
Message 1 of 2

Intersection of Work Features (Planes/Axis) in Assemblies - Need tips

llorden4
Collaborator
Collaborator

There's been many a post / wish on creating work features in Assemblies using iLogic using references to other work features and I've used these long enough to know I have basically only one option when I want to create work features in assemblies  (point, vector, vector) using iLogic.  In each of those posts, they appear (to me) to belittle the poster and tell them to go back and handle it in the Part File where those commands/features exist.  I'm able to use these work feature relations manually in assemblies, I don't understand why they're disabled to programming.

 

There are wish lists requesting these features in assemblies that go back for years, but it appears that until half the planet rises up in one voice within a short time frame then it isn't deemed a worthy venture to pursue.

 

I (am I'm sure many others) have the task of automating the placement of parts in an assembly where it would be such a simple task to generate work planes to known features (3 points, intersections, offset, etc), find their intersection and place parts at those locations.  Surely there must be SOME method I can use within an assembly file to generate work features based upon other existing work features that were created from within the assembly file.  Without a method to call for a point(s) of intersection, I'm going to have to figure out a bit of Calculus and Vector math to figure out each point myself which seems such a waste when I know full well these tools are available to me in a parts file.

 

Surely there must be some method I'm not considering!  Suggestions appreciated.

Autodesk Inventor Certified Professional
Accepted solutions (1)
876 Views
1 Reply
Reply (1)
Message 2 of 2

llorden4
Collaborator
Collaborator
Accepted solution

It's been quite the challenge, but I've managed to piece together a routine that will find via iLogic the point of intersection of three planes within an Assembly file.  This investigation highlighted for me errors in matrix return results (at least from what would be expected) from Inventor as well as incomplete documentation of the API help menu's and a serious lack of good examples to follow.  To contribute towards a solution, I am including the results of my efforts for all to share.  

Public Enum enCoordinate
    x = 1
    y = 2
    z = 3
End Enum


Sub Main
	Dim oDoc As AssemblyDocument = ThisDoc.Document
	Dim oAsmCompDef As ComponentDefinition = oDoc.ComponentDefinition
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oAssyPlane(3) As WorkPlane
	
	'Select existing work planes within current assembly file
	oAssyPlane(1) = oAsmCompDef.WorkPlanes.Item("Plane 1")
	oAssyPlane(2) = oAsmCompDef.WorkPlanes.Item("Plane 2")	
	oAssyPlane(3) = oAsmCompDef.WorkPlanes.Item("Plane 3")		
	
	Dim rootPt(3) As Double
	Dim normal(3) As Double
	
	Dim planeEqs(3) As Point
	Dim d(3) As Double

'Get equation of plane  reference https://keisan.casio.com/exec/system/1223596129
For i = 1 To 3																					'Loop for three planes
	' Get the plane root point and normal vector which defines the equation of the plane
	Call oAssyPlane(i).Plane.GetPlaneData(rootPt, normal)	
	
	' Define the root point of the plane
	Dim xRoot As Double: xRoot = rootPt(0)
	Dim yRoot As Double: yRoot = rootPt(1)
	Dim zRoot As Double: zRoot = rootPt(2)
	
	' Define the normal vector of the plane.  This defines the equation of the plane.
	Dim xNormal As Double: xNormal = normal(0)
	Dim yNormal As Double: yNormal = normal(1)
	Dim zNormal As Double: zNormal = normal(2)
	
	d(i) = (xNormal * xRoot) + (yNormal * yRoot) + (zNormal * zRoot)

	' The equation of the plane
	planeEqs(i) = oTG.CreatePoint(xNormal, yNormal, zNormal)
Next																							'End loop

	Dim intersectPt As Point
	intersectPt = GetIntersectionOfThreePlanes(planeEqs, d)

	Dim interPt As Point = oTG.CreatePoint(intersectPt.X, intersectPt.Y, intersectPt.Z )
	oPt1 = oAsmCompDef.WorkPoints.AddFixed(interPt, False)	'False is undocumented & doesn't work without.  Found in a random web search.
	oPt1.Name = "POI"
	oPt1.Grounded = True

End Sub

' *** Compute intersection point given the equation of three planes.
' *** Plane Equation format: ax + by + cz = d

' *** Where:
' ***   planeEQ must contain the coefficients (a, b, c) of the equation of each plane
' ***   d is the equation value
' *** Returns the intersection point
' *** See URL: https://keisan.casio.com/exec/system/1223596129

Function GetIntersectionOfThreePlanes(planeEq() As Point, d() As Double) As Point
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
    Dim N As Integer: N = UBound(d)
    Dim matrx As Matrix2d = oTG.CreateMatrix2d
	Dim Row As Integer
	Dim col As Integer
    For Row = 1 To N
        Dim coeffs As Point: coeffs = planeEq(Row)
        Dim pt As Double
        For col = 1 To N
            If col = 1 Then
                pt = coeffs.X
            ElseIf col = 2 Then
                pt = coeffs.Y
            ElseIf col = 3 Then
                pt = coeffs.Z
            End If
            matrx.Cell(Row, col) = pt
        Next col
    Next Row
    
    ' *** Get the determinant of the main matrix before any substitution
    Dim deter As Double
    deter = Determinant(matrx) ' matrx.Determinant
    
    ' !!! If Determinant = 0, there is no intersection point.
    If deter = 0 Then GoTo errHandler
	Dim x As Double: x = ComputeCoordinate(matrx, d, enCoordinate.x, deter)
	Dim y As Double: y = ComputeCoordinate(matrx, d, enCoordinate.y, deter)
	Dim z As Double: z = ComputeCoordinate(matrx, d, enCoordinate.z, deter)

    
    ' *** The intersection point.
    GetIntersectionOfThreePlanes = oTG.CreatePoint(x, y, z)
    
	Return GetIntersectionOfThreePlanes
    
errHandler:
    MsgBox("The planes do not intersect at a point")
    
End Function

' *** *************************************************************************
' ***
' *** Compute the X, Y, or Z coordinate given the Matrix containing the
' *** coefficients of the equation for each plane.
' ***
' *** Returns the x, y, or z coordindate of the intersection point
' ***
' *** See URL: http://www.ambrsoft.com/TrigoCalc/Plan3D/3PlanesIntersection_.htm
' ***
Function ComputeCoordinate(m As Matrix2d, d() As Double, rp As enCoordinate, determinat As Double) As Double

	Try	
	    Dim N As Integer: N = UBound(d)
	    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	    Dim newMatrix As Matrix2d = oTG.CreateMatrix2d

	    ' *** Find coordinate
	    Dim row As Integer
	    Dim col As Integer
	    For row = 1 To N
	        For col = 1 To N
	            If col = rp Then
	                newMatrix.Cell(row, col) = d(row)
	            Else
	                newMatrix.Cell(row, col) = m.Cell(row, col)
	            End If
	        Next col
	    Next row
	    
	    Dim newDeter As Double: newDeter = Determinant(newMatrix) ' newMatrix.Determinant
	    ComputeCoordinate = newDeter / determinat

	Catch Ex As Exception
		MsgBox("Exception: " & Ex.Message, "iLogic: ComputeCoordinate")
	End Try
	
	Return ComputeCoordinate

End Function


' *** *************************************************************************
' ***
' *** Compute the Determinant of a matrix
' *** The Matrix2d.Determinant does NOT return the correct value.
' ***
' *** Returns the Determinant for the matrix.
' ***
' *** See URL: http://www.ambrsoft.com/MathCalc/Matrix/Matrix3.htm#determinants
' ***
Function Determinant(ByVal src As Matrix2d) As Double

	Dim a11 As Double = src.Cell(1, 1)
	Dim a12 As Double = src.Cell(1, 2)
	Dim a13 As Double = src.Cell(1, 3)
	
	Dim a21 As Double = src.Cell(2, 1)
	Dim a22 As Double = src.Cell(2, 2)
	Dim a23 As Double = src.Cell(2, 3)
	
	Dim a31 As Double = src.Cell(3, 1)
	Dim a32 As Double = src.Cell(3, 2)
	Dim a33 As Double = src.Cell(3, 3)
	
	Dim pt1 As Double = a11 * (a22*a33 - a23*a32)
	Dim pt2 As Double = a12 * (a21*a33 - a23*a31)
	Dim pt3 As Double = a13 * (a21*a32 - a22*a31)
	
	Dim result As Double = pt1 - pt2 + pt3
	
	Return result
	
End Function

 

Autodesk Inventor Certified Professional