ilogic code to control folder supression via a parameter

ilogic code to control folder supression via a parameter

kpk7VYPK
Enthusiast Enthusiast
712 Views
4 Replies
Message 1 of 5

ilogic code to control folder supression via a parameter

kpk7VYPK
Enthusiast
Enthusiast

Hi, 

I am new to ilogic and can only write simple codes, so i hope someone can help me. 

I am trying to write a code that would toggle supression of multiple model folders via a text parameter. 

I've done it using all the parts within the folders but it would be much easier if i could supress the entire folder in one line. This is how i have written it out.

If SK10_Size = "55kW" Then
Component.IsActive("D130000260174 SK10 55kW:1") = True
Component.IsActive("D130000260174 SK10 55kW:2") = True
Component.IsActive("D130000260175 SK10 75kW:1") = False
Component.IsActive("D130000260175 SK10 75kW:2") = False
Component.IsActive("D130000260176 SK10 90 kW:1") = False
Component.IsActive("D130000260176 SK10 90 kW:2") = False


Else If  SK10_Size = "75kW" Then
	Component.IsActive("D130000260174 SK10 55kW:1") = False
Component.IsActive("D130000260174 SK10 55kW:2") = False
Component.IsActive("D130000260175 SK10 75kW:1") = True
Component.IsActive("D130000260175 SK10 75kW:2") = True
Component.IsActive("D130000260176 SK10 90 kW:1") = False
Component.IsActive("D130000260176 SK10 90 kW:2") = False

Else If  SK10_Size = "90kW" Then
Component.IsActive("D130000260174 SK10 55kW:1") = False
Component.IsActive("D130000260174 SK10 55kW:2") = False
Component.IsActive("D130000260175 SK10 75kW:1") = False
Component.IsActive("D130000260175 SK10 75kW:2") = False
Component.IsActive("D130000260176 SK10 90 kW:1") = True
Component.IsActive("D130000260176 SK10 90 kW:2") = True

End If 

 

 

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

WCrihfield
Mentor
Mentor

Hi @kpk7VYPK.  Here is a simple example iLogic rule that shows you how to suppress all components in a BrowserFolder.  First, you must start with the Document object that the browser folder is within, then get its 'Model' browser pane.  If your installation of Inventor is not English, then simply specifying "Model" there might not work, and you might have to use the InternalName of the BrowserPane instead.  Then get its top node.  Then get the folders.  Then you can loop through those folders to find the ones you want, using the folder's properties, if needed.  This simple example will try to suppress them all.  But that command actually 'toggles' suppression, not just suppresses, so if the folder contents are already suppressed, running this again will unsuppress them.

Dim oDoc As Document = ThisDoc.Document
Dim oModelPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
Dim oTopNode As BrowserNode = oModelPane.TopNode
For Each oBFolder As BrowserFolder In oTopNode.BrowserFolders
	'If oBFolder.Name = "MyFolder" Then
	If oBFolder.BrowserNode.BrowserNodes.Count > 0 Then
		oDoc.SelectSet.Clear
		oDoc.SelectSet.Select(oBFolder)
		ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyCompSuppressionCtxCmd").Execute
	End If
Next

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)

Message 3 of 5

kpk7VYPK
Enthusiast
Enthusiast

Thanks for the reply. Where do i add in the 'IF' variable for the parameter?

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Here is another example iLogic rule code that will try to find multiple folders by their names, then toggle the suppression of their contents based on the value of a Text type user parameter, similar to your existing code, but lacking the ability to effect individual components independently.  In incorporated a separate routine into this code because a certain amount of code would need to be repeated for each folder that was found.  This is one way to reduce repetitive blocks of code, and shorten the overall amount of code.

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	Dim oModelPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim oTopNode As BrowserNode = oModelPane.TopNode
	Dim oBFolders As BrowserFoldersEnumerator = oTopNode.BrowserFolders
	If oBFolders.Count = 0 Then Exit Sub 'exit the rule, because no folders found
	Dim oBFolder1, oBFolder2, oBFolder3 As BrowserFolder 'create variables to hold the folders when found
	For Each oBFolder As BrowserFolder In oBFolders 'start looping through all top level folders
		If oBFolder.Name = "Group1" Then
			oBFolder1 = oBFolder
		ElseIf oBFolder.Name = "Group2" Then
			oBFolder2 = oBFolder
		ElseIf oBFolder.Name = "Group3" Then
			oBFolder3 = oBFolder
		End If
	Next
	If SK10_Size = "55kW" Then
		If oBFolder1 IsNot Nothing Then ProcessFolder(oDoc, oBFolder1) 'toggles Suppression of folder contents, if any
	ElseIf SK10_Size = "75kW" Then
		If oBFolder2 IsNot Nothing Then ProcessFolder(oDoc, oBFolder2)
	ElseIf SK10_Size = "90kW" Then
		If oBFolder3 IsNot Nothing Then ProcessFolder(oDoc, oBFolder3)
	End If
End Sub

'this is a custom separate routine that you can run from the main routine
'this helps eliminate the need for repetitive code
Sub ProcessFolder(oDoc As Document, oBrowserFolder As BrowserFolder)
	If oBrowserFolder IsNot Nothing Then
		If oBrowserFolder.BrowserNode.BrowserNodes.Count = 0 Then 'there is nothing in the folder
			MsgBox("Nothing was found in 'Group1' folder.", , "")
		Else
			oDoc.SelectSet.Clear
			oDoc.SelectSet.Select(oBrowserFolder)
			ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyCompSuppressionCtxCmd").Execute
		End If
	End If
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)

Message 5 of 5

kpk7VYPK
Enthusiast
Enthusiast

This is great! Thanks so much!

I am assuming i need to change "Group 1" to the name of the folder?

 

One day i hope to be able to write code like this. I am reading and re-reading trying to understand it. 🙂 

0 Likes