Mirror multible solids with ilogic

Mirror multible solids with ilogic

ejaL9K8H
Advocate Advocate
2,102 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,103 Views
23 Replies
Replies (23)
Message 2 of 24

ejaL9K8H
Advocate
Advocate

This rule are able to count all solids in the model:

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim SolidList As New ArrayList()
For Each SurfaceBodies In oDoc.ComponentDefinition.SurfaceBodies
	SolidList.Add(SurfaceBodies.Name)
Next

SolidCount = SolidList.Count
MessageBox.Show(SolidCount, "Number of Solids")

How can I mirror all these solids with one Mirror feature in iLogic?

 

0 Likes
Message 3 of 24

Ralf_Krieg
Advisor
Advisor

Hello

 

Untested:

Sub Main()

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

    Dim oCol As ObjectCollection
    oCol = ThisApplication.TransientObjects.CreateObjectCollection
	
	For Each SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
		oCol.Add(SurfaceBody)
	Next
	
    '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

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 4 of 24

ejaL9K8H
Advocate
Advocate

It gives an error:

 

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

0 Likes
Message 5 of 24

Ralf_Krieg
Advisor
Advisor
Accepted solution

Sorry, you have to create a mirrorfeaturedefinition first.

Sub Main()

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

    Dim oCol As ObjectCollection
    oCol = ThisApplication.TransientObjects.CreateObjectCollection
	
	For Each SurfaceBody In oDoc.ComponentDefinition.SurfaceBodies
		oCol.Add(SurfaceBody)
	Next
	
    '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 oMirrorFeatureDefinition As MirrorFeatureDefinition=oDoc.ComponentDefinition.Features.MirrorFeatures.CreateDefinition(oCol, oPlane)
	
    Dim oMirror As MirrorFeature
    oMirror = oDoc.ComponentDefinition.Features.MirrorFeatures.AddByDefinition(oMirrorFeatureDefinition)

    oMirror.NewBodyOperation = True
	
End Sub

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 24

ejaL9K8H
Advocate
Advocate

Thanks for you help.

But it still shows the same error... 

0 Likes
Message 7 of 24

Ralf_Krieg
Advisor
Advisor

Hello

 

Possible to post the file or a screenshot of the model browser?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 8 of 24

ejaL9K8H
Advocate
Advocate

ejaL9K8H_0-1617183930550.png

 

0 Likes
Message 9 of 24

Ralf_Krieg
Advisor
Advisor

Hello

 

I've tried to model a similar part as of the picture shows. The visible plane is XY-Plane?

My code runs without any errors. Which version of inventor do you use?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 10 of 24

ejaL9K8H
Advocate
Advocate

That is correct. The visible plane is the XY plane.

 

Im am using Inventor Professional 2020, release 2020.2

But I am also using Autodesk Factory Design Utilities 2020, releade 2020.1.3, because i am trying to make a asset model.

 

0 Likes
Message 11 of 24

ejaL9K8H
Advocate
Advocate

I just tried to biuld a new part, and it works if I join the two extrusions.

But I would like to make it as two different solids, because i need to add some different colours to the part and make a pattern.

ejaL9K8H_1-1617185254357.png

And when i am doing this, it is not able to run the rule...

0 Likes
Message 12 of 24

ejaL9K8H
Advocate
Advocate

In adition to this I would like to remove the original part, but the rule would run if i add this:

Dim oMirrorFeatureDefinition As MirrorFeatureDefinition=oDoc.ComponentDefinition.Features.MirrorFeatures.CreateDefinition(oCol, oPlane, True, kOptimizedCompute)
0 Likes
Message 13 of 24

dutt.thakar
Collaborator
Collaborator
Accepted solution

@ejaL9K8H 

 

I have created a similar code with a bit of variation, see below code. The thing is that adding multiple bodies in an object collection seems like an issue in Inventor 2019, (I am using it and I see the same error that you see in Inventor 2020). I also have tested the same code in Inventor 2021 and it is working perfectly fine.

 

The code created by @Ralf_Krieg  will also work fine in Inventor 2021

 

			Dim oDoc As PartDocument
    		oDoc = ThisApplication.ActiveDocument
	
			Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
			Dim oBody As SurfaceBody
			Dim oFeatures As PartFeatures = oDef.Features
			Dim oPlane As Object = oDef.WorkPlanes.Item(3)
			Dim oCol As ObjectCollection
   			oCol = ThisApplication.TransientObjects.CreateObjectCollection
    		        oCol.Clear

			For i = 1 To oDef.SurfaceBodies.Count
				oCol.Add(oDef.SurfaceBodies.Item(i))	
			Next
			
			Dim oMD As MirrorFeatureDefinition = oDef.Features.MirrorFeatures.CreateDefinition(oCol, oPlane)
			Dim oMirror As MirrorFeature = oDef.Features.MirrorFeatures.AddByDefinition(oMD)

 

This seems like a problem/bug in Inventor 2020 or 2019 versions.

I am tagging @MjDeck here, he might be able to answer us in more detail and if it is a bug, it can be reported as well.

@MjDeck 

can you elaborate on this a bit? Any help from you is appreciated.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 14 of 24

dutt.thakar
Collaborator
Collaborator

@ejaL9K8H 

 

You need to add the MirrorFeatureDefinition like this. 'Only two inputs Object collection and Mirror Plane is needed, no other arguments are necessary

 

Dim oMD As MirrorFeatureDefinition = oDef.Features.MirrorFeatures.CreateDefinition(oCol, oPlane)

To remove the original solid, use this.

 

oMD.RemoveOriginal = True

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 15 of 24

ejaL9K8H
Advocate
Advocate

Thanks a lot to the both of you!

But I still get the same error.

Is there any posibility to get this running in Inventor 2020?

0 Likes
Message 16 of 24

dutt.thakar
Collaborator
Collaborator

@ejaL9K8H 

One way to do in Inventor 2020 is to use multiple mirror features, for each solid body a new mirror feature can be created, if you are okay with that I can alter the code and post.

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 17 of 24

ejaL9K8H
Advocate
Advocate

I am able to write the code myselvers that makes multible mirror features, if this is the only posibility.
But I would just like to do it with a single mirror feature.

 

0 Likes
Message 18 of 24

dutt.thakar
Collaborator
Collaborator

@ejaL9K8H 

 

I understand your concern here, but as mentioned it is not working in Inventor 2019 and 2020, let's wait for some response from MJDeck, as he is from Autodesk and a real expert, he might have some idea on this. If we are doing something wrong, he may be able to guide us/show some alternatives or if it is a bug, he can confirm and report it.

 

Hope this will help you.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 19 of 24

ejaL9K8H
Advocate
Advocate

Thanks for your time 

0 Likes
Message 20 of 24

WCrihfield
Mentor
Mentor

Have you tried specifying a different 'PatternComputeTypeEnum' variation, within the 'MirrorFeatureDefinition' line yet?  It sounds like those options mostly apply to when you are mirroring Features, rather than bodies, but you could give it a try anyways to see if it makes any difference for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes