Finding an original feature through a mirrored feature

Finding an original feature through a mirrored feature

NicholasBrown
Explorer Explorer
887 Views
8 Replies
Message 1 of 9

Finding an original feature through a mirrored feature

NicholasBrown
Explorer
Explorer

I'm currently digging through Inventors API trying to find a link to a original feature of a mirrored feature in a part file.

 

Once the code gets to the kMirrorFeatureObject I need it to reach through and get the original feature object.

 

Does anyone know of a way to get to this value through the API?

 

Thanks

 

If statement sample    

 

Dim ABF As PartFeature             

Dim ExtParam As String

 

If ABF.Type = kExtrudeFeatureObject Then
                            ExtParam = ABF.Extent.Distance.Expression


                       ElseIf ABF.Type = kThickenFeatureObject Then
                            ExtParam = ABF.FeatureDimensions.Item(1).Parameter.Expression


                       ElseIf ABF.Type = kMirrorFeatureObject Then
                          {  ExtParam = ABF.MirrorFeatures }                     <---------- This is where I run into problems
                       
                    End If

0 Likes
Accepted solutions (1)
888 Views
8 Replies
Replies (8)
Message 2 of 9

frederic.vandenplas
Collaborator
Collaborator

Hi, 

 

You need to find the parent feature, because it is derived

 

Sub MirroredFeature()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oDocDef As PartComponentDefinition
Set oDocDef = oDoc.ComponentDefinition

Dim oPartFeature As PartFeature
Dim ExtParam As String
 
For Each oPartFeature In oDocDef.Features

If oPartFeature.Type = kExtrudeFeatureObject Then
    ExtParam = oPartFeature.Extent.Distance.Expression
ElseIf oPartFeature.Type = kThickenFeatureObject Then
    ExtParam = oPartFeature.FeatureDimensions.Item(1).Parameter.Expression
ElseIf oPartFeature.Type = kMirrorFeatureObject Then
    ExtParam = oPartFeature.ParentFeatures.Item(1).Extent.Distance.Expression
End If
Debug.Print ExtParam
Next
End Sub

Please, please use the debugging functionality in vba to find the items, it will save you a lot of trial and error!

Knipsel.JPG

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 9

NicholasBrown
Explorer
Explorer
Accepted solution

Thank you for the reply,
This code works fine when the mirror part is formed using features, and the ParentFeatures.Count = 1. Item(1) as expected.
Mirror_With_Features.png
If you change the mirror selection to solids and the Occurrences of the created mirror have items in it (see below) then the ParentFeatures.Count = 0.
Mirror_With_Solids.png                                                  Occurrence_Multibody.png
Because we are using New Solids on the Mirrored parts I cannot reach the item.
The Part is now a Multibody and I haven't found a way to access the parameter required.
Locals_For_New_Part_Mirror.png

 

0 Likes
Message 4 of 9

CGift
Explorer
Explorer

Nicholas,

 

Did you ever find a solution to this problem? I am finding myself lost on trying to find the parent solids of a mirror solids feature in a multibody as well.

 

Regards,

Cameron

0 Likes
Message 5 of 9

WCrihfield
Mentor
Mentor

Hi @CGift.  Here is an iLogic rule you can play around with for that task.  I am not sure what your end goal was after you have found those parent bodies of a feature that mirrors some bodies, so I just put a simple message in the deepest part of the code, to show the name of each body it finds within the mirror feature's parent features.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisDoc.Document
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oMirrFeats As MirrorFeatures = oPDef.Features.MirrorFeatures
	If oMirrFeats.Count = 0 Then Exit Sub
	For Each oMirrFeat As MirrorFeature In oMirrFeats
		Dim oMirrFeatDef As MirrorFeatureDefinition = oMirrFeat.Definition
		If oMirrFeatDef.MirrorOfBody Then
			Dim oInputBodies As ObjectCollection = oMirrFeatDef.ParentFeatures
			For Each oInputBody In oInputBodies
				If TypeOf oInputBody Is SurfaceBody Then
					Dim oBody As SurfaceBody = oInputBody
					MsgBox("MirrorFeature.Name = " & oMirrFeat.Name & vbCrLf & _
					"oBody.Name = " & oBody.Name, vbInformation, "Input Body Name")
				End If
			Next 'oInputBody
		End If
	Next 'oMirrFeat
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 9

CGift
Explorer
Explorer

Hi @WCrihfield,

 

I tried the code you posted but it did not work. It looks like oMirrFeatDef.ParentFeatures is 0 due to no features being mirrored.

 

I am trying to find the parent solid so I can examine what features affect that solid to make a part description inside the part files derived from the multibody. A solid created by a mirror still needs this description and it was an oversight when initially creating the rule I am working on.

 

The API seems very limited in regards to parent solids when mirroring solids. It seems like there needs to be a oMirrFeatDef.ParentSolidBodies to help find these solids...

 

Are there any other avenues I should try?

 

Regards,

Cameron

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

What version/year of Inventor are you using?  When you created the Mirror feature, did you have the features or solids button active?  Did you choose Join or New Solid as the wanted result?  Did you have the checkbox for "Remove Original" checked when you created that feature?  If you chose Join, then the original body may no longer be accessible because only a different combined body will remain.  If you chose to mirror features instead of bodies, then my code would not work, because I am only looking for SurfaceBody objects.  One process some folks use for determining which solid bodies were created by a specific feature, is by looping through each SurfaceBody in the part, and check its CreatedByFeature property, which should return a generic PartFeature type object, and if that is the same MirrorFeature you are interested in, you would then know that it was created by that mirror feature.  But that would only work if a new body was generated by the feature that includes the original volume within its volume.  Also, if something was done to those bodies later in the model browser tree below that feature, that might also effect how this works.  If a feature was mirrored, instead of a body, then you would have to find the feature that was mirrored first, then find the bodies that it created.  The MirrorFeatureDefinition is supposed to be what was used to create the MirrorFeature in the first place, so its ParentFeatures property should contain whatever was used to create the MirrorFeature.  However, if something happened to those input features/bodies after the MirrorFeature was created, that would cause problems when trying to find the originals.  It can definitely be complicated.  Especially if following a derive trail back from some other document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 9

CGift
Explorer
Explorer

I am using Inventor 2022.4.

 

When creating the mirror feature I am choosing "Mirror Solids", "New Solid", and the "Remove Original" box is greyed out. In the simple test multibody part I tried out your code in the Mirror feature was the last created feature inside the part and it still brought up a count of 0 parent features. It seems like Inventor is not recognizing the solids as a parent feature.

 

Inside the rule I am working on I do use the CreatedByFeature property to determine the feature I need to interrogate. 

 

Would you possibly have an example part in which this code works correct that I could check out? 

 

Regards,

Cameron

0 Likes
Message 9 of 9

C_Haines_ENG
Collaborator
Collaborator

Just to unbury this thread, this solution finds all solids created by another solid.

 

See this thread for the code. 

0 Likes