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: 

How to pass the transformation matrix to imported component inside Assembly environment

4 REPLIES 4
Reply
Message 1 of 5
dhanshri_gavas
303 Views, 4 Replies

How to pass the transformation matrix to imported component inside Assembly environment

Hi,

I am loading the step file as an imported component in the assembly environment by using the API. 

But I want to apply transformations to imported components. One way is to break the link to the imported component and apply the transformation, but for that, you need to save the assembly first and then apply the transformation. But in my case, it's not expected. Is there any other way to apply transformation?

Thanks in advance!

4 REPLIES 4
Message 2 of 5

You can apply transformation without break link.

Dim asm As AssemblyDocument = ThisDoc.Document

Dim boxOccurrence As ComponentOccurrence = asm.ComponentDefinition.Occurrences(1).Definition.Occurrences(1)

Dim mtx As Matrix = boxOccurrence.Transformation
mtx.Cell(1, 4) += 1

boxOccurrence.Transformation = mtx

 

Message 3 of 5

Here is my sample code I have applied transformation to the component, but nothing changes in environment.
before Applying the transformation

dhanshri_gavas_0-1715839473749.png

After applying the transformation
dhanshri_gavas_1-1715839531855.png

var txn = InventorApp.TransactionManager.StartTransactionForDocumentOpen("FDX Import"); Document _document = InventorApp.ActiveDocument; AssemblyDocument aDoc = _document as AssemblyDocument; AssemblyComponentDefinition oPartCompDef = aDoc.ComponentDefinition; InventorApp.PartOptions.EnableConstructionEnvironment = false; aDoc.ObjectVisibility.Sketches = true; ObjectCollection oBodies = InventorApp.TransientObjects.CreateObjectCollection(); string filePath = "D:\\StepFiles\\CCADAEB1A99EB29F20431D6F3761692C105ADF2E.stp";//bRepGeometry.FilePath; ImportedGenericComponentDefinition impPart = (ImportedGenericComponentDefinition)oPartCompDef.ImportedComponents.CreateDefinition(filePath); impPart.ReferenceModel = true; impPart.ImportedModelGeometryTypes = ImportedModelGeometryTypeEnum.kWiresModelGeometryType | ImportedModelGeometryTypeEnum.kSolidsModelGeometryType | ImportedModelGeometryTypeEnum.kMeshesModelGeometryType | ImportedModelGeometryTypeEnum.kSurfacesModelGeometryType; oPartCompDef.ImportedComponents.Add((ImportedComponentDefinition)impPart); impPart.IncludeAll(); // ComponentOccurrence boxOccurrence = pDoc.ComponentDefinition.Occurrences(1).Definition.Occurrences(1); ComponentOccurrence oc1 = aDoc.ComponentDefinition.Occurrences[1]; TransientGeometry transientGeometry = InventorApp.TransientGeometry; Matrix transMatrix = oc1.Transformation; double[] arr = new double[16]; oc1.Transformation.PutMatrixData(ref arr); transMatrix.Cell[1, 4] = 0; transMatrix.Cell[2, 4] = 0; transMatrix.Cell[3, 4] = 1; oc1.Transformation = transMatrix; aDoc.Update2(); txn.End();

Message 4 of 5

Just a tip: please use the code tags in your post (</> button in the ribbon).

The code you posted is difficult to read.

Message 5 of 5

I have a 4x4 transformation matrix. How can I directly apply that matrix to the transformation matrix?

            var txn = InventorApp.TransactionManager.StartTransactionForDocumentOpen("FDX Import");
            Document _document = InventorApp.ActiveDocument;
            AssemblyDocument aDoc = _document as AssemblyDocument;
            AssemblyComponentDefinition oPartCompDef = aDoc.ComponentDefinition;
            InventorApp.PartOptions.EnableConstructionEnvironment = false;
            aDoc.ObjectVisibility.Sketches = true;
            ObjectCollection oBodies = InventorApp.TransientObjects.CreateObjectCollection();
            string filePath = "D:\\StepFiles\\CCADAEB1A99EB29F20431D6F3761692C105ADF2E.stp";//bRepGeometry.FilePath;
            ImportedGenericComponentDefinition impPart = (ImportedGenericComponentDefinition)oPartCompDef.ImportedComponents.CreateDefinition(filePath);
            impPart.ReferenceModel = true;
            impPart.ImportedModelGeometryTypes = ImportedModelGeometryTypeEnum.kWiresModelGeometryType | ImportedModelGeometryTypeEnum.kSolidsModelGeometryType | ImportedModelGeometryTypeEnum.kMeshesModelGeometryType | ImportedModelGeometryTypeEnum.kSurfacesModelGeometryType;
            oPartCompDef.ImportedComponents.Add((ImportedComponentDefinition)impPart);
            impPart.IncludeAll();
            // ComponentOccurrence boxOccurrence = pDoc.ComponentDefinition.Occurrences(1).Definition.Occurrences(1);
            ComponentOccurrence oc1 = aDoc.ComponentDefinition.Occurrences[1];
            TransientGeometry transientGeometry = InventorApp.TransientGeometry;
            Matrix transMatrix = oc1.Transformation;           

            transMatrix.Cell[1, 4] = 0;
            transMatrix.Cell[2, 4] = 1;
            transMatrix.Cell[3, 4] =1;
            oc1.Transformation = transMatrix;
            txn.End();

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

Post to forums  

Autodesk Design & Make Report