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: 

Associative body copy API Sample - problem

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mitcham_boy
1448 Views, 5 Replies

Associative body copy API Sample - problem

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

5 REPLIES 5
Message 2 of 6

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 6

Hi Vladimir - thanks for the reply - yes i'm aware of that sample code and have used it successfully but i need solid output.

“SurfaceBody Copy API Sample” uses surface outputs using the call oPartDoc2.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oBody, oMatrix) --- this call allows specification of the position within the .add()

However for solid output Set baseFeature = targetDef.Features.NonParametricBaseFeatures.AddByDefinition(featureDef) does not allow specifying the position 😞

I’d really appreciate it if you could show me how to achieve the equivalent with solid output . I bet it’s an easy one when you know how !

thanks
dan
Message 4 of 6

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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 6
ekinsb
in reply to: mitcham_boy

I've created a blog post with a cleaned up sample that accounts for a problem I found in Inventor.

 

http://adndevblog.typepad.com/manufacturing/2013/09/copying-a-body-from-one-part-into-another-part.h...


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 6
mitcham_boy
in reply to: ekinsb

Thanks to Brian and Vladimir for digging me out on this! -thanks for your time and quick responses.

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

Post to forums  

Autodesk Design & Make Report