iLogic Rule - Controlling Suppression of Multiple Folders via Array

iLogic Rule - Controlling Suppression of Multiple Folders via Array

eric.frissell26WKQ
Advocate Advocate
1,645 Views
9 Replies
Message 1 of 10

iLogic Rule - Controlling Suppression of Multiple Folders via Array

eric.frissell26WKQ
Advocate
Advocate

Hi, quick question for you guys as I'm exploring some new VBA/iLogic territory... At the minute I'm attempting to model a configuration-type of work flow (we're still in 2020, plz don't ask why I'm exploring this when it's a feature in 2022... I've been asking for that version as well but no answer as to when we're going to get it...)

 

Currently I've got one assembly which contains many sub-assemblies that are organized into folders an a few patterns.  Because each of the 8 required folder contains about 10 sub-assemblies, I'd prefer to start with an array and find all the folders in my design tree and suppress them (if using iLogic to return all the folders in the tree into an array is difficult then hard coding the folder strings into the array would be an option.)  I'd prefer to start with everything suppressed because it would be easier, in my opinion, to state which value will be unsuppressed rather than declare the 7 values which will become suppressed.

 

Currently the code is as follows

 

 

Folder_Size = New String() {"16.88", "19.88", "22.88", "25.88", "28.88", "31.88", "34.88", "37.88"}

MultiValue.SetList("Compactor_Size", "16.88", "19.88", "22.88", "25.88") ', "28.88", "31.88", "34.88", "37.88")
MultiValue.SetList("Screen_Type","STR", "CF" )
MultiValue.SetList("Catch_Type", "Drain", "Drain2")


oApp = ThisApplication
oDoc = oApp.ActiveDocument
oPane = oDoc.BrowserPanes("Model")
oTopNode = oPane.TopNode
For Each  In Folder_Size

	    
	'Define which folder to suppress
	folder = oTopNode.BrowserFolders.Item(Folder_Size)

	oSelectSet = oDoc.SelectSet
	oSelectSet.Clear
	    
	'Select the folder automaticly
	oSelectSet.Select(folder)

	Dim oCommandMgr As CommandManager
	oCommandMgr = oApp.CommandManager

	'Toggle suppress or unsuppress
	oCommandMgr.ControlDefinitions.Item("AssemblyCompSuppressionCtxCmd").Execute2(True)
Next
On Error Resume Next

 

 

 

I do not know the syntax for the For loop here.  For each... what, I'm not sure?  Variable, of course, but how does it get called there?  For now the model has 3 folders - 19.88, 22.88, 25.88 and I'm hoping the On Error Resume Next will get it through the missing folders.

 

Edit: Bonus points for anyone who can identify a way to dynamically add the folders in the design tree to the array and then link that array to the MultiValue.SetList linked to Compactor_Size.  Would be super neat to have that flexibility so that when a new folder is created it pops up as an available size and the macro doesn't have to be edited

 

Edit Edit:

Turns out a quick way around this is to use the Select command to select multiple folders.  Slightly less convenient than a for loop but considerably more convenient than alternatives

0 Likes
Accepted solutions (1)
1,646 Views
9 Replies
Replies (9)
Message 2 of 10

theo.bot
Collaborator
Collaborator

You can loop thru the browser folders, capture the names in an arraylist and then pass them over to a multivalue parameter.
It's possible to suppress the content of the folder, but not the folder itself. It's a toggle if you use the suppress using the command manager. So you need to check the items in the folder to see the current suppression state. I think it's easier to manage the components directly instead of using the folder to suppress items.

 

here's a sample to get the folder names from the browser and add the values to  a parameter:

 

Sub Main
	
	Dim oApp As Inventor.Application
	oApp = ThisApplication

	Dim oDoc As AssemblyDocument
	oDoc = ThisDoc.Document

	If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MessageBox.Show("this is not an assembly!", "Document check")
		Exit Sub
	End If

	Dim oComdef As AssemblyComponentDefinition
	oComdef = oDoc.ComponentDefinition

	Dim oFolder As BrowserFolder
	Dim oFolderNames As New ArrayList
	Dim oTopnode, oNode As BrowserNode

	'get model pane
	oPane = oDoc.BrowserPanes("Model")

	oTopnode = oPane.TopNode

	For Each oFolder In oTopnode.BrowserFolders

		oFolderNames.Add(oFolder.Name)
		Logger.Info(oFolder.Name & " contains " & oFolder.BrowserNode.BrowserNodes.Count & " Items ")

'		If oFolder.BrowserNode.BrowserNodes.Count <> 0 Then

'			oFolder.BrowserNode.DoSelect

'			Dim oCommandMgr As CommandManager
'			oCommandMgr = oApp.CommandManager

'			'Toggle suppress or unsuppress
'			oCommandMgr.ControlDefinitions.Item("AssemblyCompSuppressionCtxCmd").Execute2(True)
'		End If
	Next

MultiValue.SetValueOptions(True, DefaultIndex := 0)

'add Text parameter
Try
prop = oComdef.Parameters.UserParameters​.item ("Folders")
Catch
newprop = oComdef.Parameters.UserParameters​.AddByValue("Folders", "New", UnitsTypeEnum.kTextUnits)
End Try

'convert list to multivalue list
MultiValue.List("Folders") = oFolderNames

oDoc.Update2(True)

end sub

 

0 Likes
Message 3 of 10

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

I'll post my code cause it was already complete.

Suppressing occurrences will lead to a new Level of Detail. You have to save each of them before switching to the next or you will loose your changes (suppressions).

 

Sub Main

	Dim oAssDoc As Inventor.AssemblyDocument = ThisDoc.Document
	Dim oBrowserFolder As Inventor.BrowserFolder 
	Dim oBrowserFolder2 As Inventor.BrowserFolder 
	Dim oBrowserPane As Inventor.BrowserPane=oAssDoc.BrowserPanes.Item("Model")
	Dim oObjCollSup As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oObjCollUnsup As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim oCompOcc As ComponentOccurrence

	Dim oFolderList As New List(Of String)

	'Create a LOD for each BrowserFolder
	For Each oBrowserFolder In oBrowserPane.TopNode.BrowserFolders 
		Try
			oAssDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations.Add(oBrowserFolder.Name)
		Catch
		End Try
		oFolderList.Add(oBrowserFolder.Name)
	Next

	For Each oBrowserFolder In oBrowserPane.TopNode.BrowserFolders 
		oAssDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations.Item(oBrowserFolder.Name).Activate
		For Each oBrowserFolder2 In oBrowserPane.TopNode.BrowserFolders 
			'traverse all the objects in folder an add it to collection
			Dim oBrowserNode As BrowserNode
			For Each oBrowserNode In oBrowserFolder2.BrowserNode.BrowserNodes
				If TypeOf oBrowserNode.NativeObject Is ComponentOccurrence Then
					oCompOcc=DirectCast(oBrowserNode.NativeObject,ComponentOccurrence)
					If Not oBrowserFolder2.Name = oBrowserFolder.Name Then
						oCompOcc.Suppress
					Else
						oCompOcc.Unsuppress
					End If
				End If
			Next
		Next
		oAssDoc.Save 
	Next

	Dim oLOD As LevelOfDetailRepresentation
	For Each oLOD In oAssDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations
		If oLOD.LevelOfDetail = LevelOfDetailEnum.kAllComponentsSuppressedLevelOfDetail Then
			oLOD.Activate
		End If
	Next

	Try
		MultiValue.List("Compactor_Size") = oFolderList
	Catch
		oAssDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("Compactor_Size", "", UnitsTypeEnum.kTextUnits)
		MultiValue.List("Compactor_Size") = oFolderList
	End Try

End Sub

 

You can create a form and place the fx-parameter a selection dropdown. With the rule below this selection will switch the active LOD.

Sub Main
	MultiValue.UpdateAfterChange = True
	
	Dim oAssDoc As Inventor.AssemblyDocument = ThisDoc.Document
	Dim oLOD As LevelOfDetailRepresentation

	For Each oLOD In oAssDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations
		Logger.Debug(oLOD.Name)
		If oLOD.Name = Compactor_Size Then
			Logger.Debug("Activate LOD " & oLOD.Name)
			oLOD.Activate
		End If
	Next

End Sub

R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 4 of 10

theo.bot
Collaborator
Collaborator

@Ralf_Krieg , You're right about the LOD for R2021 and earlier. For R2022 with the Model states, you can supress  components without the need of creating (multiple) model states. So depending on the desired outcome R2022 users (and  later) can choose how they would like to work with this. 

Message 5 of 10

Ralf_Krieg
Advisor
Advisor

Hello

 

@theo.bot 

As eric.frissell26WKQ stated: "we're still in 2020, plz don't ask why"

So there's a need to create all these LOD's for him. Anyway, it's good you point at the differences starting 2022 for other users searching for a solution like this. 👍


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 10

theo.bot
Collaborator
Collaborator

@Ralf_Krieg , Yes your right, I might have missed that line  in the first place 😉.

0 Likes
Message 7 of 10

eric.frissell26WKQ
Advocate
Advocate

@theo.bot curious is that code for iLogic or VBA?  It's kind of amazing how similar they can look sometimes

0 Likes
Message 8 of 10

theo.bot
Collaborator
Collaborator

@eric.frissell26WKQ  I used Ilogic rule for that.

0 Likes
Message 9 of 10

eric.frissell26WKQ
Advocate
Advocate

@theo.bot @Ralf_Krieg 

 

Thank you both for the huge help here, wish I could accept both of your solutions as the answer because they're both awesome and are enough to get me moving in the right direction.  I'm sure that I'll have a few more questions as I get deeper into this regarding the control of the suppression using the data from the lists but I really appreciate the help to get here

Message 10 of 10

eric.frissell26WKQ
Advocate
Advocate

edit: nevermind, was able to figure this out

0 Likes