Hi all, I'm trying to work with the 2019 ilogic snippet component.Add. My problem is to retrieive the position of an existing component. Normally to get the transformation matrix I would do:
Dim oOccurrence As ComponentOccurrence oOccurrence = Component.InventorComponent("iLogic_flange:1") Dim oTransform As Matrix oTransform = oOccurrence.Transformation
But if I want to use Component.Add the position argument is of type pointormatrix:
Dim matrixA = ThisDoc.Geometry.Matrix()
Dim componentA = Components.Add("occName", "a.ipt", position := matrixA, grounded := False, visible := True, appearance := Nothing)
How can I convert a matrix object (oTransform) to a DocumentUnitMatrix object (matrixA).
thanks
Solved! Go to Solution.
Solved by Markus.Koechl. Go to Solution.
Perhaps your working too hard.
Take a look at the 'proxy' series of objects and the componentoccurrence.CreateGeometryProxy() command.
A proxy will report the translated matrix for you. Also nested objects need to nest their proxy.
Proxy = reference of original object, but translated as placed in assembly.
Yep, you don't understand the concept of Proxy. Back up your thought process and start here:
Assembly has a
AssemblyComponentDefinition has a list of
Occurrences which is actually a list of
ComponentOccurrence
Each ComponentOccurrence has a map to his position in the assembly space, you can get its objects relative to this map by using
CreateGeometryProxy(original object in definition, proxy version of object)
Once it succeeds the proxyObject has the transformation matrix already applied, but you don't need to think in matrixes because it also tells you about each feature based on the built in matrix of the componentoccurrence.
So an example:
dim asmDoc as AssemblyDocument = ThisDocument
dim acd as AssemblyComponentDefinition = asmDoc.ComponentDefinition
dim ocFlange1 as ComponentOccurrence = acd.Occurrences("iLogic_flange:1") 'this assumes you can find the existing item by name. Other methods would be to cycle through the list and look for an item by comparing names.
dim wpCenter as WorkPoint = ocFlange1.ComponentDefinition.WorkPoints(1)
dim pxWpCenter as WorkPointProxy = Nothing 'notice that many objects have a Proxy type parallel to it.
ocFlange1.CreateGeometryProxy(wpCenter, pxWpCenter)
If pxWpCenter IsNot Nothing Then
debug.print(wpCenter.Point.X)
debug.print(pxWpCenter.Point.X)
End If
You will see the two centerpoints are different. One is defined in the space of the original part, the other is defined in the space of the assembly. And that explains the Proxy concept.
Now back to your original question. You wan to add a component to the assembly component definition.
You first need the ComponentOccurrences object from the AssemblyDocument.ComponentDefinition.Occurrences
dim compOccs as ComponentOccurrences = acd.Occurrences
dim tg as TransientGeometry = thisApplication.TransientGeometry 'use this to create points, vectors, and matrices out of thin air
Dim pMat As Matrix = tg.CreateMatrix()
pMat.SetTranslation(tg.CreateVector(0, 0, 0))'this creates a position vector from nowhere to nowhere (insert at origin)
dim coFlange = compOccs.Add(partdocfilenameandpath, pMat)
So now you need to decide, do you need to create a simple matrix to put a part into space or get a matrix from an existing part and use. If you have an existing component occurrence and want to get the its transformation to apply (or copy and modify) to another component occurrence, the use the co.Tranformation property to get the Matrix.
Any better?
Although the thread is older, here is the solution:
Dim mInvMatrix As Inventor.Matrix = mOccurrence.Transformation
Dim matrixA = ThisAssembly.Geometry.Matrix()
matrixA.InDatabaseUnits = mInvMatrix
As a result matrixA has both the document unit based matrix matrixA.Cells and the database unit based matrix.InDataBaseUnits.Cells.
Can't find what you're looking for? Ask the community or share your knowledge.