Mirror body rule, how to mirror all bodies

Mirror body rule, how to mirror all bodies

michael.bouwer
Contributor Contributor
343 Views
3 Replies
Message 1 of 4

Mirror body rule, how to mirror all bodies

michael.bouwer
Contributor
Contributor

hi

 

i found a rule for mirroring bodies in a part

i modified it a bit to suit what i want to do with it

could you guys help me out. the rule is only mirroring the last solid body
its counting the no of solids but using that number as the body to mirror
how would one get it select all solids in the part?

	oFile = ThisDoc.PathAndFileName(False)

'Save a copy of the file
ThisDoc.Document.SaveAs(oFile + "_Mirror" + ".ipt", False)

'Count the Solid bodies in the part file
oFile3 = ThisApplication.ActiveDocument
oSolidBodyCounter = oFile3.ComponentDefinition.SurfaceBodies.Count

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

'Save the new Mirrored Part File
	ThisDoc.Document.Save
	MessageBox.Show("the model has been mirrored", "mirrored")
0 Likes
344 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator

You are getting a total count of the solid bodies (i.e. 3). You would want to add all of the surface bodies to the collection object (1,2, and 3). I didnt test it but it looks like that is your problem.

oSolidBodyCounter = 3
oCol = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To oSolidBodyCounter
	oCol.Add(oDoc.ComponentDefinition.SurfaceBodies(i))
Next

 

0 Likes
Message 3 of 4

michael.bouwer
Contributor
Contributor

i does'nt seam to want to add a second object to the collection.

 

get this error

Error in rule: Rule0, in document: 2920-0903-002_BC_Mirror_Mirror_Mirror_Mirror_Mirror_Mirror_Mirror_Mirror.ipt

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

i tried adding the bodies 1 at a time but get the same error (part has 3 bodies)
i.e.

oCol.Add(oDoc.ComponentDefinition.SurfaceBodies(2))
oCol.Add(oDoc.ComponentDefinition.SurfaceBodies(3))

 

0 Likes
Message 4 of 4

michael.bouwer
Contributor
Contributor

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/mirror-multible-solids-with-ilogic/m...

looks like its an issue with 2019/2020 versions
not ideal but descent solution is to make multiple mirror features

0 Likes