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!
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
Here is my sample code I have applied transformation to the component, but nothing changes in environment.
before Applying the transformation
After applying the transformation
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();
Just a tip: please use the code tags in your post (</> button in the ribbon).
The code you posted is difficult to read.
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.