Suppressing Part Features at the Assembly Level

Suppressing Part Features at the Assembly Level

Jack_DuttonTM2JK
Enthusiast Enthusiast
516 Views
4 Replies
Message 1 of 5

Suppressing Part Features at the Assembly Level

Jack_DuttonTM2JK
Enthusiast
Enthusiast

Hello, this is a sort of a continuation from THIS forum post, but it's not relevant to the parent topic so I wanted to create a new one. 

From the last post I was able to get an external rule working for an individual part and being able to suppress certain features as called out from a list. I wanted to upgrade this to work within the assembly environment and search through all of the parts for features by that name and suppress/un-suppress them. 

As said before, I was able to get it to work within a part. It is meant to prompt the user to select if the features should be On or Off, set that option to the IsVisible variable, then set the suppression state. 

I believe my issue lies in defining the oFeature/oFeatures variables (Bolded and Underlined). Much of the info online is fairly outdated so I think I'm just using incorrect syntax. Getting the "Unable to cast COM object of type..." error on that line. Any help would be much appreciated! 

 

Sub Main()

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAssyDoc.AllReferencedDocuments

Dim oRefDoc As Document

Dim IsVisible As Boolean = InputRadioBox("Turn all CAD Aids On/Off", "On", "Off", False, "iLogic")
	
Dim AidFeatures As New List(Of String)
	AidFeatures.Add("Feature1")
	AidFeatures.Add("Feature2")
	AidFeatures.Add("Feature3")

For Each oRefDoc In oRefDocs
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oFeatures As PartFeatures = oRefDoc.AllReferencedDocuments
		For Each oString In AidFeatures
			oFeature = oFeatures.Item(oString)
			If oFeature.Name.Contains(oString) Then
				If IsVisible = True
					Feature.IsActive(oFeature.Name) = True
				End If
				
				If IsVisible = False
					Feature.IsActive(oFeature.Name) = False
				End If
					
			End If
		Next
	End If
Next

End Sub

  

0 Likes
Accepted solutions (1)
517 Views
4 Replies
Replies (4)
Message 2 of 5

Frederick_Law
Mentor
Mentor

 

 

Dim oFeatures As PartFeatures = oRefDoc.AllReferencedDocuments

 

 

Documents are not Features.  You cannot assign Documents object to Features object.

You need to process each document to get features in the document.

Message 3 of 5

Jack_DuttonTM2JK
Enthusiast
Enthusiast

That makes sense. I was messing with that line a lot and that was the last thing I was testing. I also tried:

Dim oFeatures As PartFeatures = oRefDoc.ComponentDefinition.Features

This actually gets me further. I get an error on line 31:

Feature.IsActive(oFeature.Name) = True 

Feature.IsActive: No feature found with the name: "Feature1". So now I'm think it's struggling to actually dig into the parts themselves. The test fields I'm using do in fact have a feature called Feature1, haha. Maybe it's the way the oFeature = oFeatures.Item(oString) line is worded. I'm doing some testing but still a bit new to iLogic so it's slow going. 

0 Likes
Message 4 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@Jack_DuttonTM2JK 

 

just as an FYI, you can get the syntax needed to reach down the model tree by finding it in the rule editor as shown and choosing Capture Current State

 

For my example that would return something like:

Feature.IsActive("Cube 100:1", "Feature3") = True

Curtis_Waguespack_0-1722361195030.png

 

The problem is that since your code is stepping through all referenced documents, using the iLogic IsActive function for this is likely to result in errors, since you can not be certain how deep a part is nested in sub assemblies, etc.

 

For that reason, it's probably best to use Inventor's API feature.suppressed method here.

 

Keep in mind Suppressed and IsActive return the opposite true/false value for the feature status, so we just need to use the 'Not' operator to flip it.

 

I think this will work for you:

 

iLogicVb.UpdateWhenDone = True

Dim IsVisible As Boolean = InputRadioBox("Turn all CAD Aids On/Off", "On", "Off", False, "iLogic")

Dim AidFeatures As New List(Of String)
AidFeatures.Add("Feature1")
AidFeatures.Add("Feature2")
AidFeatures.Add("Feature3")

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAssyDoc.AllReferencedDocuments

Dim oRefDoc As Document
Dim oFeatures As PartFeatures
Dim oFeature As PartFeature

For Each oRefDoc In oRefDocs
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		oFeatures = oRefDoc.ComponentDefinition.Features

		For Each oString In AidFeatures

			Try ' try to get a feature with this name
				oFeature = oFeatures.Item(oString)				
			Catch
				'catch the error that occurs when 
				'the Feature Is not present In the part
				'and skip to the next item in the list
				Logger.Info("Feature NOT found: " & oString)
				Continue For
			End Try
	
			oFeature.Suppressed = Not IsVisible
			
		Next 'oString
	End If
Next 'oRefDoc

 

EESignature

Message 5 of 5

Jack_DuttonTM2JK
Enthusiast
Enthusiast

Wow, thank you so much @Curtis_Waguespack !! I just tried it in my assembly and exactly how you have it there works PERFECTLY. Thank you, I'm going to have to study this one as I think it accomplishes a lot of stuff I want to do and opens some doors here. 

 

I hope this helps someone else out there looking to do the same thing too!