More efficient way to suppress/unsuppress features?

More efficient way to suppress/unsuppress features?

william
Advocate Advocate
806 Views
4 Replies
Message 1 of 5

More efficient way to suppress/unsuppress features?

william
Advocate
Advocate

I have been using this subroutine to suppress or unsuppress features. But I am finding that it is taking quite a while to process.
For a single ipt it takes 12-15 seconds which seems like a lot.
It gets worse with an assembly of 3-4 components, I have timed it taking over 2 minutes to push all the parameters into the component files and run the feature supression rules in the components. 

Is there a more efficient way to suppress components that I can implement into my code to speed things up? 

Sub Main
	
Call Feature_State("Active", "LH SEEN")
Call Feature_State("Active", "RH SEEN")

If Seen_End_Configuration = "BOTH ENDS SEEN" Then

Else If Seen_End_Configuration = "NO ENDS SEEN" Then
	Call Feature_State("Suppressed", "LH SEEN")
	Call Feature_State("Suppressed", "RH SEEN")
	
Else If Seen_End_Configuration = "LH END SEEN" Then
	Call Feature_State("Suppressed", "RH SEEN")

Else If Seen_End_Configuration = "RH END SEEN" Then
	Call Feature_State("Suppressed", "LH SEEN")

End If



RuleParametersOutput()
iLogicVb.UpdateWhenDone = True

End Sub

Sub Feature_State(State As String, Searchterm As String)
Dim oFeature As PartFeature
Dim oFeatures As PartFeatures
oFeatures = ThisDoc.Document.ComponentDefinition.Features

If State = "Active" Then
	For Each oFeature In oFeatures
		If oFeature.Name.Contains(Searchterm) = True Then
			oFeature.Suppressed = False
		End If
	Next
Else If State = "Suppressed" Then
	For Each oFeature In oFeatures
		If oFeature.Name.Contains(Searchterm) = True Then
			oFeature.Suppressed = True
		End If
	Next
End If

End Sub

 

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

william
Advocate
Advocate

For example here is a screen share of configuring an assembly with 6 components. 
Initial configure time was 3mins 41 seconds. Subsequent runs were around the 2 minute mark. 
There has to be a faster way to do this. 

0 Likes
Message 3 of 5

Andrii_Humeniuk
Advisor
Advisor

Hi @william . I don't think your problem is in the code, but I have optimized your code. The reason may be in the cyclical rebild of part, perhaps you have many Events that cyclically trigger the same rules.

Sub Main
	Dim oDoc As PartDocument = ThisDoc.Document
	Dim oFeats As PartFeatures = oDoc.ComponentDefinition.Features	
	Call Feature_State(oFeats, False, "LH SEEN")
	Call Feature_State(oFeats, False, "RH SEEN")	
	If Seen_End_Configuration = "BOTH ENDS SEEN" Then	
	Else If Seen_End_Configuration = "NO ENDS SEEN" Then
		Call Feature_State(oFeats, True, "LH SEEN")
		Call Feature_State(oFeats, True, "RH SEEN")		
	Else If Seen_End_Configuration = "LH END SEEN" Then
		Call Feature_State(oFeats, True, "RH SEEN")	
	Else If Seen_End_Configuration = "RH END SEEN" Then
		Call Feature_State(oFeats, True, "LH SEEN")	
	End If	
	RuleParametersOutput()
	oDoc.Update()
End Sub

Private Function Feature_State(ByVal oFeats As PartFeatures, ByVal bState As Boolean, ByVal sName As String)
	For Each oFeat As PartFeature In oFeats
		If oFeat.Name.Contains(sName) Then
			If oFeat.Suppressed <> bState Then oFeat.Suppressed = bState
		End If
	Next
End Function

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Just wanted to mention another related technique/method you may be interested in for this type of task.  The PartComponentDefinition object has two methods for either suppressing or un-suppressing multiple features at once.

PartComponentDefinition.SuppressFeatures() 

PartComponentDefinition.UnsuppressFeatures() 

To use them, you would first need to create an ObjectCollection, then add those features to that collection, then supply that collection to this method.  Taking advantage of these methods may help speed up processing time, compared to calling a custom Sub/Function to run, and suppressing/un-suppressing each individual feature separately.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

william
Advocate
Advocate

Hello Both 
Thanks for the advice. I implemented the suppression state via the object collection, and it is miles faster.
Where it used to take 3mins 40sec, it now takes 30sec to update. Massive time saver, thank you again.. 
Code snippet for others who run into this issue. 

Sub Main
Dim oSupressFeatures As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oUnsupressFeatures As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

CreateFeatureCollection(oSupressFeatures, oUnsupressFeatures, "Your feature searchterm here", "Active")
CreateFeatureCollection(oSupressFeatures, oUnsupressFeatures, "Your feature searchterm here", "Suppressed")

SetFeatureState(oSupressFeatures, oUnsupressFeatures)

RuleParametersOutput()
iLogicVb.UpdateWhenDone = True
End Sub

Sub CreateFeatureCollection(oSupressFeatures As ObjectCollection, oUnsupressFeatures As ObjectCollection, Searchterm As String, State As String)
Dim oDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition

For Each oFeat As PartFeature In oCompDef.Features
	If oFeat.Name.Contains(Searchterm) Then
		If oFeat.Suppressed = True And State = "Active" Then
			oUnsupressFeatures.Add(oFeat)
		Else If oFeat.Suppressed = False And State = "Suppressed" Then
			oSupressFeatures.Add(oFeat)
		End If
	End If
Next
End Sub


Sub SetFeatureState(oSupressFeatures As ObjectCollection, oUnsupressFeatures As ObjectCollection)
Dim oDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition

Try
	oCompDef.SuppressFeatures(oSupressFeatures)
Catch
	Logger.Error("Error Supressing Features")
End Try

Try
	oCompDef.UnsuppressFeatures(oUnsupressFeatures)
Catch
	Logger.Error("Error Unsupressing Features")
End Try

End Sub