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: 

Mirroring about assembly plane VBA

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
AdalsteinnMar
1768 Views, 5 Replies

Mirroring about assembly plane VBA

Hello,

 

I'm trying to get my code to mirror parts that are located in an assembly about the assembly planes. I have tried both derived parts and direct mirror feature and gotten them to work, just not the way I want them to Smiley Indifferent. So I got this piece of code (located below) from this site and modified it a bit to select an item from my assembly. I want to mirror the part about the assembly planes, I've tried calling the planes from the assembly and use it as an input at various locations without success. I've tried to modify the individual items of the assembly plane object to be identical to the part planes (but they are read only). I've tried creating planes through other means but they are all in the local coordinate system of the part I'm about to mirror. I can supply the coordinates and rotation to get the local plane aligned with the assembly planes since I used that information before to place the member but I really don't want to do all that cross referencing.

 

Can you show me the way to use the assembly plane as in input argument for the mirror? (oAssemblyPlane does not work as an argument in the add procedure)

 

Sub MirrorMirrorOnTheWall()

Dim oAssemblyDoc As AssemblyDocument
Set oAssemblyDoc = ThisApplication.ActiveDocument
Dim oAssemblyPlane As WorkPlane
Set oAssemblyPlane = oAssemblyDoc.ComponentDefinition.WorkPlanes(2)

' Get the part document.
Dim partDoc As PartDocument
Set partDoc = ThisApplication.Documents.Item(16)
 
'Get the part component definition
Dim oPartDef As PartComponentDefinition
Set oPartDef = partDoc.ComponentDefinition
 
' Get the X-Z-Plane work plane.
Dim oxzPlane As WorkPlane
Set oxzPlane = oPartDef.WorkPlanes.Item(2)
 
'Get the Z-Axis
Dim ozAxis As WorkAxis
Set ozAxis = oPartDef.WorkAxes.Item(3)

Dim oPlane4 As WorkPlane
Set oPlane4 = oPartDef.WorkPlanes.AddByLinePlaneAndAngle(ozAxis, oxzPlane, 0)

'Turn off the visibility of the mirror plane
oPlane4.Visible = False
 
'Get the object collection
Dim oCol As ObjectCollection
Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
Call oCol.add(partDoc.ComponentDefinition.SurfaceBodies(1))
 
'Mirror the feature
Dim oMirror As MirrorFeature
Set oMirror = partDoc.ComponentDefinition.Features.MirrorFeatures.add(oCol, oPlane4, False)
 
'This can be activated if the mirrored feature is to be a new solid
oMirror.NewBodyOperation = True

End Sub

 

Tags (1)
5 REPLIES 5
Message 2 of 6

So I've been testing other methods. I now can create a pattern but it still will not allow me to mirror.

In some instances pattern would serve me better than the mirror command but I'd really like to mirror about the XZ and then the both parts about the YZ, I'm wondering if there is a problem due to the name of the mirrored parts?

 

 

 

Sub MirrorMirrorAssemblyHall()

Dim oAssemblyDoc As AssemblyDocument
Set oAssemblyDoc = ThisApplication.ActiveDocument
Dim oAssemblyPlane As Object 'Have also tried WorkPlane
Set oAssemblyPlane = oAssemblyDoc.ComponentDefinition.WorkPlanes(2)

Dim oAssemblyDefinition As AssemblyComponentDefinition
Set oAssemblyDefinition = oAssemblyDoc.ComponentDefinition
Dim oOccurrence As ComponentOccurrence
Dim ZAxis As WorkAxis
Set ZAxis = oAssemblyDefinition.WorkAxes(3)

'Get the object collection
Dim oCol As ObjectCollection
Set oCol = ThisApplication.TransientObjects.CreateObjectCollection

oCol.add oAssemblyDefinition.occurrences.Item(100)  '.SurfaceBodies(1) after checking the object browser but no luck
 
'Mirror the feature
Call oAssemblyDefinition.Features.MirrorFeatures.add(oCol, oAssemblyPlane, False, kOptimizedCompute)

' If I comment out the call in order to go further I can add the pattern quite nicely
               
' How many components in pattern
Dim iNum As Integer
iNum = 3
                
' Create pattern
Call oAssemblyDefinition.OccurrencePatterns.AddCircularPattern(oCol, ZAxis, False, 90, iNum)


End Sub

 

Message 3 of 6

So concerning the mirror question, it is not possible to use a plane defined in the assembly as input for a feature created in the part, you need to work at the same context level, so you will have to create a workplane in the part.

 

You need for that to convert the asm plane data into part coordinate system, based on the position of your part occurrence in the assembly. To do that use the inverse matrix of the part "ComponentOccurrence.Transformation" and transform the workplane origin and normal vector back to part coords, then create a workplane based on those data in the part to use with the mirror feature.

 

I hope it helps.

 

Regards,

Philippe.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 4 of 6

Thank you for your respond. The context level was something that I suspected but I wanted to avoid the transformation, I'll just go through with it then Smiley Embarassed.

 

What puzzles me is that we have the pattern and mirror command as part of the same "group" through the GUI but when trying to mimic these commands using the API the pattern works on the assembly level but not the mirror.

Message 5 of 6

Well, this is rather straighforward, what you have to do is grab the occurrence.Transformation, inverse that and transfrom any input you need in the part to create your workplane, that would be a couple of lines of code, but let me know if you have further trouble with the topic.

 

So to explain why pattern works and mirror doesn't: in your second code sample you are trying to mirror an occurrence. Take a look at the MirrorFeatures.Add method and you will see that occurrences are not supported, you can mirror only SurfaceBodies, features and work features. An assembly doesn't contain actual geometry, it's always referencing the geometry from the parts, so it doesn't contain SurfaceBodies but proxies of those surface bodies. if you are not familiar with what a proxy is in the context of assembly, I encorage you to read the dedicated topic in the API Help Overviews. Also assembly doesn't support features which are generating material, like positive extrusion, revolve, mirroring bodies and so on for that same reason.

 

What you are creating next is an occurrence pattern, this is different than mirroring as it doesn't generate geomerty but just insert another occurrence referencing an existing part.

 

Remember, the input for feature creation or constraints have always to be provided within the same context level.

 

I hope it clarifies.

 

Philippe.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 6 of 6

Thank you very much for the inverse function. I've decided to add the mirrored/symmetry components during the insertion of the part, so when going through the part list I now add multiple instances of the part using relevant point and inverted matrices where/when the parent part has a symmetry component in the truss model I'm working with.

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

Post to forums  

Autodesk Design & Make Report