Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic 2019 Document units matrix

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
779 Views, 5 Replies

Ilogic 2019 Document units matrix

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

5 REPLIES 5
Message 2 of 6
JamieVJohnson2
in reply to: Anonymous

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.

 

jvj
Message 3 of 6
Anonymous
in reply to: JamieVJohnson2

I don't understand.
this does not work

occ = Component.InventorComponent("iLogic_flange:1")
Dim matrixA = ThisDoc.Geometry.Matrix()
Dim oTransform As Matrix
oTransform = occ.Transformation
occ.CreateGeometryProxy(oTransform, matrixA)

thanks



Message 4 of 6
JamieVJohnson2
in reply to: Anonymous

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?

 

 

jvj
Message 5 of 6
Anonymous
in reply to: JamieVJohnson2

Thanks a lot that explain very weel the proxy concept. But what i want to do is to use the ilogic snippet components.add (new in inventor 2019) (see https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2019...)

see the section on Document Units Geometry


Dim componentA = Components.Add("occName", "a.ipt", position := Nothing, grounded := False, visible := True, appearance := Nothing)

I need to specify the position argument which is a matrix of type DocumentUnitsMatrix. (Dim matrixA = ThisDoc.Geometry.Matrix())

This matrix is different than:

Dim pMat As Matrix = tg.CreateMatrix()

so my question is how do I get the matrix of type DocumentUnitsMatrix ThisDoc.Geometry.Matrix() from a ComponentOccurence?

Thanks




Message 6 of 6
Markus.Koechl
in reply to: Anonymous

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.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report