Hi
RE “Associative body copy API Sample” 2013 API Help
The above code in the API help shows how to do an associative or a non-associative copy in an assembly of one part into another part. ..BUT the non-associative copy does not always work correctly....
I have been testing this sample code and notice the following limitations with the lower part entitled “Create a non-associative solid base feature in the second part”...
The code uses the proxybody for the source object but it does not use the proxybody for the target object and therefore the relative positioning is wrong for the nonparametricbasefeature when it is created in the target object if the real targetbody is in a different place than the targetbodyproxy (e.g. it has been rotated/moved in assembly space).
I notice that if you perform this manually using the “copy object” button the relative positioning is maintained correctly even if both target and source objects have been rotated/moved in the assembly...
Please could Brian Ekins or someone from AutoDesk post a solution that will work in all cases.
I'm happy to provide more details, code, assembly files to demonstrate the problem.
I would really appreciate some feedback on this as it is affecting everything we are doing this year.
Many thanks
Dan
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
Could you please look at the sample "SurfaceBody Copy API Sample" in the Inventor API Help.
Pay attention to matrix operations in the following code fragment:
' Get the transform from the occurrence where the surface body currently exists. ' This defines the tranform of the surface body into assembly space. Set oMatrix = oOcc1.Transformation ' Get the matrix of the second occurrence and invert it. ' The inverse of the second occurrence's transform defines the tranform from ' assembly space into that occurrence's part space. Dim oMatrix2 As Matrix Set oMatrix2 = oOcc2.Transformation oMatrix2.Invert ' Combine these matrices. Call oMatrix.PreMultiplyBy(oMatrix2)
' Copy the surface body from the first part into the second.
Call oPartDoc2.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oBody, oMatrix)
This combined transformation ensures correct orientation of the copied body relative to the target body.
Cheers,
Try this workflow. It works for me.
'Assembly definition Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition 'Copied component Dim oOcc1 As ComponentOccurrence = oAsmDef.Occurrences.Item(1) Dim oCompDef1 As PartComponentDefinition = TryCast(oOcc1.Definition, PartComponentDefinition) 'Base component Dim oOcc2 As ComponentOccurrence = oAsmDef.Occurrences.Item(2) Dim oCompDef2 As PartComponentDefinition = TryCast(oOcc2.Definition, PartComponentDefinition) ' Copied body oSourceBody Dim oSourceBody As SurfaceBody = oCompDef1.SurfaceBodies.Item(1) ' it’s transient copy Dim oTransBody1 As SurfaceBody = oTransientBRep.Copy(oSourceBody) ' transformation matrix for component 1 Dim oMatrix As Matrix = oOcc1.Transformation ' transformation matrix for component 2 Dim oMatrix2 As Matrix = oOcc2.Transformation ' combined transformation matrix from CS1 to CS2 Call oMatrix2.Invert() Call oMatrix.PreMultiplyBy(oMatrix2) ' transform copied body orientation Call oTransientBRep.Transform(oTransBody1, oMatrix) 'create NonParametric Base Feature definition Dim oFeatureDef As NonParametricBaseFeatureDefinition _ = oCompDef2.Features.NonParametricBaseFeatures.CreateDefinition 'add copied body to object collection Dim oCollection As ObjectCollection _ = ThisApplication.TransientObjects.CreateObjectCollection Call oCollection.Add(oTransBody1) ' adjust output settings – need solid ! With oFeatureDef .BRepEntities = oCollection .OutputType = BaseFeatureOutputTypeEnum.kSolidOutputType End With ' Transform oTransBody1 to solid body Dim oBaseFeature As NonParametricBaseFeature _ = oCompDef2.Features.NonParametricBaseFeatures _ .AddByDefinition(oFeatureDef) ' base part update CType(oCompDef2.Document, PartDocument).Update() ' assembly update oAsmDoc.Update()
Now part1 contains two solid bodies.
Cheers,
I've created a blog post with a cleaned up sample that accounts for a problem I found in Inventor.