Able to suppress or unsuppress all the components in a folder

Able to suppress or unsuppress all the components in a folder

npokhrelYK39M
Enthusiast Enthusiast
142 Views
4 Replies
Message 1 of 5

Able to suppress or unsuppress all the components in a folder

npokhrelYK39M
Enthusiast
Enthusiast

Hi, is there a way to turn on and off a number of components contained in a folder using ilogic? I wanna place all the components that I want to turn on and off in a folder and then just somehow tell the ilogic to activate or deactivate the components in them. This way I wont have to line by line write IsActive = True/False for hundreds of components individually.

Is there a better or efficient way of doing this?

0 Likes
143 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @npokhrelYK39M.  Unfortunately, I do not see a 'built-in' tool for that in the Inventor API.  We have a couple of similar sounding methods, but for features, instead of components (SuppressFeatures & UnsuppressFeatures).  Since we have a context menu control for suppress or unsuppress in the user interface, we can likely attempt to 'simulate' the actions that the user would manually be doing, but that would not be true API way of doing things, and can be a bit unstable.  The code would have to find & get that model browser folder, then 'select' it, then execute the ControlDefinition behind that context menu item for toggling suppression status, and hope it works.

Another idea, which seems simpler to me, would be to use ModelStates for that.  One of the primary purposes of ModelStates is to record suppression status of assembly components and/or features.  They can also record different values for Parameters and iProperties, and such, but that is beside the point.  To do this, create one or more new/custom ModelStates (one for each state wanted), activate one of them, suppress the stuff you want suppressed, and unsuppress the stuff you want unsuppressed.  Then activate a different custom ModelState and do the same thing for another scenario.  Now save the file.  Now, when you want to switch between the two different suppression status for a lot of stuff, just activate the ModelState you created & set-up for that state of the assembly.  Much easier to just activate one ModelState or another by code, if needed, or avoid the need for the code altogether.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

hollypapp65
Advocate
Advocate

Not directly.

When you right click on the folder, there is a command to suppress everything in the folder.

The command is: AssemblyCompSuppressionCtxCmd

 

Try to use iLogic to select the folder and run that command.

 

This may not be faster then loop and suppress each item because that what that command do.

Message 4 of 5

WCrihfield
Mentor
Mentor

I know this general idea/ability has been asked about multiple times here in this forum over the years, so I did a quick search and found one of my previous posts on this subject.  Link to that discussion is below.  It shows a couple examples of some code for doing the 'simulation' route.

https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-code-to-control-folder-supression-... 

I'm sure there are other similar posts out there also, and some are likely even older, but this is one of the first ones I found in my search with an accepted solution.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

mateusz_baczewski
Advocate
Advocate

Hi,

 

Some time ago I worked on a similar problem. The method itself is ThisApplication.CommandManager.ControlDefinitions("AssemblyCompSuppressionCtxCmd").Execute()

but I applied it to each individual item in the folder by first checking whether the item was a ComponentOccurrence and what its current state was. I did this as a safety measure, because if you try to set ComponentOccurrence.Suppressed = False on a folder while one of the components inside that folder has ComponentOccurrence.Suppressed = True, then calling

ThisApplication.CommandManager.ControlDefinitions("AssemblyCompSuppressionCtxCmd").Execute()

will always switch the components in the folder to Suppressed = True.

That’s why I iterated through every item in the folder, confirmed that each item was a ComponentOccurrence and noted its state. Then, depending on what I needed, I added it to an ObjectCollection.

 

My method look like:

Sub Configurator(folderName As String, configurationPar As String, ByRef partToUnsuppress As ObjectCollection, ByRef partToSuppress As ObjectCollection)

	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oModelBrowser As BrowserPaneObject = oDoc.BrowserPanes.Item("Model")
	Dim oConfigurationFolder As BrowserFolder = oModelBrowser.TopNode.BrowserFolders.Item("_KONFIGURACJA_")

	Dim mainFolder As BrowserFolder = oConfigurationFolder.BrowserNode.BrowserFolders.Item(folderName)
	Dim foldersInsideMainFolder = mainFolder.BrowserNode.BrowserFolders
	
	For Each folder As BrowserFolder In foldersInsideMainFolder
		Dim nodesInFolder As BrowserNodesEnumerator = folder.BrowserNode.BrowserNodes
		
		If folder.Name = configurationPar
			For Each node As BrowserNode In nodesInFolder
				If TypeOf node.NativeObject Is ComponentOccurrence And node.NativeObject.Suppressed = True
					partToUnsuppress.Add(node.NativeObject)
				End If
			Next
		Else 
			For Each node As BrowserNode In nodesInFolder
				If TypeOf node.NativeObject Is ComponentOccurrence And node.NativeObject.Suppressed = False
					partToSuppress.Add(node.NativeObject)
				End If
			Next
		End If 
	Next
End Sub

 

If you found it helpful, a "Like" would be much appreciated!
If this post solved your problem, please mark it as "Solution.".