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: 

VBA mirror solids in part file

5 REPLIES 5
Reply
Message 1 of 6
Lubor.Vitek
1078 Views, 5 Replies

VBA mirror solids in part file

How can I mirror the solids in partfile? I'm able to select all the surfacebodies (Componentdefinition.surfacebodies)  but, I'm not able to mirror them. Thx.

5 REPLIES 5
Message 2 of 6
YuhanZhang
in reply to: Lubor.Vitek

Open a part document with a solid feature, and try below VBA sample:

Sub MirrorSolidTest()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCol As ObjectCollection
    Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
    
    oCol.Add oDoc.ComponentDefinition.SurfaceBodies(1)
        
    Dim oPlane As WorkPlane
    Set oPlane = oDoc.ComponentDefinition.WorkPlanes(1)
    
    Dim oMirror As MirrorFeature
    Set oMirror = oDoc.ComponentDefinition.Features.MirrorFeatures.Add(oCol, oPlane, False, kOptimizedCompute)
End Sub

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 6
Lubor.Vitek
in reply to: Lubor.Vitek

It works fine but I need to take it a step further that means:

 

Starting conditions: I have Solid1

End conditions: To have Solid1 and Solid2 which is the mirror of Solid1.

 

Thx.

Message 4 of 6
YuhanZhang
in reply to: Lubor.Vitek

To create a new solid body for the mirror feature, please use below code:

Sub MirrorSolidTest()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCol As ObjectCollection
    Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
    
    oCol.Add oDoc.ComponentDefinition.SurfaceBodies(1)
        
    Dim oPlane As WorkPlane
    Set oPlane = oDoc.ComponentDefinition.WorkPlanes(1)
    
    Dim oMirror As MirrorFeature
    Set oMirror = oDoc.ComponentDefinition.Features.MirrorFeatures.Add(oCol, oPlane, False, kOptimizedCompute)
    
    oMirror.NewBodyOperation = True
End Sub

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 6
hanhmy.bui
in reply to: YuhanZhang

I  know this thread is already a few years old but I used the exact same code to mirror a part. The mirror plane is supposed to be one surface of my part so that the mirrored part touches the original part. The code worked out well but after modification of the part the mirror plane seems to be different (or the same... the new part is shorter than the old one). When I mirror my part now there is a gap between the original and the mirrored part. Why is that? 

Tags (3)
Message 6 of 6
YuhanZhang
in reply to: hanhmy.bui

Can you share a data and code to reproduce the problem for us to look into it?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

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

Post to forums  

Autodesk Design & Make Report