Mirror multible solids with ilogic

Mirror multible solids with ilogic

ejaL9K8H
Advocate Advocate
2,101 Views
23 Replies
Message 1 of 24

Mirror multible solids with ilogic

ejaL9K8H
Advocate
Advocate

Hi

 

I would like to mirror multible solids (166) with one miror feature.

I have a code, which is working with one solid at the time, but what do I have to change or add to mirror more solids at once?

I dont want 166 new mirror features added to model, but only one.

 

Sub Main()

'Create Mirror Part and remove orginal part.
    
    Dim oDoc As PartDocument
    oDoc = ThisApplication.ActiveDocument

    Dim oCol As ObjectCollection
    oCol = ThisApplication.TransientObjects.CreateObjectCollection

    oCol.Add(oDoc.ComponentDefinition.SurfaceBodies(1)) ' What do i have to write in this line, to mark multible solids?

    Dim oPlane As WorkPlane
    oPlane = oDoc.ComponentDefinition.WorkPlanes(3)

    Dim oMirror As MirrorFeature
    oMirror = oDoc.ComponentDefinition.Features.MirrorFeatures.Add(oCol, oPlane, True, kOptimizedCompute)

    oMirror.NewBodyOperation = True
	
End Sub

  

Thanks in Advance.

0 Likes
Accepted solutions (2)
2,102 Views
23 Replies
Replies (23)
Message 21 of 24

ejaL9K8H
Advocate
Advocate

Sorry I am a bit new to this coding. Im now sure what you mean about a different 'PatternComputeTypeEnum' variation ?

0 Likes
Message 22 of 24

WCrihfield
Mentor
Mentor

Sorry, I should have provided more information about it when I posted.  When creating a new MirrorFeature using the MirrorFeatures method called 'AddByDefinition', you first have to create a MirrorFeatureDefinition object, using the MirrorFeatures.CreateDefinition method.  The last optional input variable being requested by the CreateDefinition method is called "ComputeType", and it is expecting a value from the PatternComputeTypeEnum Enumerator.  I was just wandering if changing what you specify for that PatternComputeTypeEnum value would maybe change the outcome of your code, or somehow make it work, where it has been failing previously.  Just a thought.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 23 of 24

Anonymous
Not applicable

Hello, I'm new to this forum but using Inventor for a few years now. Recently we have upgraded to Inventor 2021 and I have encountered a strange situation. In Inventor drawing I cannot get a dimension between a face and a sharp edge in a flat pattern. I have tried direct dimension, with intersection between two lines and via a sketch and point with no results.

0 Likes
Message 24 of 24

ejaL9K8H
Advocate
Advocate

Thanks for all your advices!

I succeeded in making a code, where I firstly combine all solid bodies into one solid, whereafter it is possible to mirror this single solid. Here is the code I am using, if anyone is interessed:

 

'Combine and Mirror

Sub Main()
oDoc = ThisApplication.ActiveDocument

' Check the Document type 
If (oDoc.DocumentType = kPartDocumentObject) Then
	
	Try 
		'delete named feature if it exists
		oDoc.ComponentDefinition.features.CombineFeatures.item("My_Combine").delete		
	Catch		
	End Try
	
	'get the first body to use in as the base body in the combine
	Dim oBody As SurfaceBody
	Try
		oBody = oDoc.ComponentDefinition.SurfaceBodies.Item(1)
	Catch
		MessageBox.Show("Could not find the base body", "ilogic")
		Return ' can't get body so exit rule
	End Try
	
	'create a collection 
	Dim oColl As ObjectCollection
    oColl = ThisApplication.TransientObjects.CreateObjectCollection
	
	'get the solid body count
	oCount = oDoc.ComponentDefinition.SurfaceBodies.Count
	
	'add the rest of the bodies to the collection 
	For  i = 2 To oCount 
		oColl.Add(oDoc.ComponentDefinition.SurfaceBodies.Item(i))		
	Next
	'create the combine feature
	oCombine = oDoc.ComponentDefinition.features.CombineFeatures.Add _
	(oBody, oColl, PartFeatureOperationEnum.kJoinOperation, True) 
	
	'rename the feature
	oCombine.name = "My_Combine"
End If


'Mirror Solid:
    Dim oCol As ObjectCollection
    oCol = ThisApplication.TransientObjects.CreateObjectCollection

    oCol.Add(oDoc.ComponentDefinition.SurfaceBodies(1))

    Dim oPlane As WorkPlane
    oPlane = oDoc.ComponentDefinition.WorkPlanes(3)

    Dim oMirror As MirrorFeature
    oMirror = oDoc.ComponentDefinition.Features.MirrorFeatures.Add(oCol, oPlane, True, kOptimizedCompute)
	
End Sub

 

0 Likes