Rule to suppress features containg certain words...

Rule to suppress features containg certain words...

Anonymous
Not applicable
731 Views
6 Replies
Message 1 of 7

Rule to suppress features containg certain words...

Anonymous
Not applicable

I'm sure this has been address before..but of course I can't make it work.  I need to have a global rule that will suppress any feature containing the string "control_side" .  

 

I've tried this code I found elsewhere & modified:

 

SyntaxEditor Code Snippet

myparam = "control_side"
Dim oDoc as PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oFeature As PartFeature
For Each oFeature In oDoc.ComponentDefinition.Features
  If oFeature.Name.ToUpper.Contains(myparam.ToUpper) Then
    oFeature.Suppressed = True
    oDoc.Update
  End If
Next

...but no dice.  Can someone get me over the finish line?  Thanks in advance!

0 Likes
Accepted solutions (1)
732 Views
6 Replies
Replies (6)
Message 2 of 7

perrysc
Enthusiast
Enthusiast

Try this.

 

Dim myparam As String = "control_side"
Dim oDoc as PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oFeature As PartFeature
Dim oFeatureName As String For Each oFeature In oDoc.ComponentDefinition.Features oFeatureName = UCase(oFeature.Name)
If oFeatureName.Contains(UCase(myparam)) Then oFeature.Suppressed = True oDoc.Update End If Next

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

Thanks for the reply, but I get these error messages:

 

Error in rule: suppress_control_sides, in document: testing divert to right.iam

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

0 Likes
Message 4 of 7

perrysc
Enthusiast
Enthusiast

Oh, you're running the rule in an assembly? The solution is easy then. 

 

Dim myparam As String = "control_side"
Dim oDoc as AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oFeature As PartFeature
Dim oFeatureName As String
For Each oFeature In oDoc.ComponentDefinition.Features
  oFeatureName = UCase(oFeature.Name)
  If oFeatureName.Contains(UCase(myparam)) Then
    oFeature.Suppressed = True
    oDoc.Update
  End If
Next
0 Likes
Message 5 of 7

Anonymous
Not applicable

Well that got rid of the errors, and yes, I totally see how you switched from Part to Assembly.  Duh on me.  However, the features are still not switching off.  I've attached files that have the assembly/parts in it with the names as they appear in my formal project files.  Prolly shoulda done that right away, again, Duh on me.  If you have time I'd appreciate the extra help in error-checking.  Thanks again!

0 Likes
Message 6 of 7

perrysc
Enthusiast
Enthusiast
Accepted solution

 

Ah, I see, you want to affect features inside of part files from an assembly. Okay, I've written a new rule that does what you want it to. This rule only goes one level down, however, so it's not going to get a part in a subassembly located in the assembly the rule is run it. I wasn't sure if you needed that functionality.

 

Sub Main()

	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	Dim oUniqueOccurrencesFileNames As New List(Of String)()
	Dim oUniqueOccurrencesDefs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	For Each oThing As ComponentOccurrence In oAsmDef.Occurrences
		If Not oUniqueOccurrencesFileNames.Contains(oThing.Definition.Document.FullFileName) Then
			oUniqueOccurrencesFileNames.Add(oThing.Definition.Document.FullFileName)
			oUniqueOccurrencesDefs.Add(oThing.Definition)
		End If
	Next
	
	Dim oStringToFilter As String = "Control_Side" ''' Make this whatever
	
	For Each oThing As ComponentDefinition In oUniqueOccurrencesDefs
		For Each oFeature As PartFeature In oThing.Features
			If oFeature.Name.ToUpper.Contains(oStringToFilter.ToUpper) Then
				oFeature.Suppressed = True
			End If
		Next
	Next
	InventorVb.DocumentUpdate()

End Sub

 

Message 7 of 7

Anonymous
Not applicable

Woah...

 

Excellent!  That works great, just tried it!

0 Likes