iLogic Control Multiple Component Visibility

iLogic Control Multiple Component Visibility

Anonymous
Not applicable
2,804 Views
4 Replies
Message 1 of 5

iLogic Control Multiple Component Visibility

Anonymous
Not applicable

Hi. I'm using an iLogic Rule to control the visibility of components which is then controlled by a Form dialogue box where the user selects the required "configuration" from a drop-down list. For each "configuration" there are something like 20-30 components whose visibility states need to be addressed. Is it possible to set the visibility for multiple components with one command? Something like...

 

Component.Visible("Bolted Connection:1" & "Bolted Connection:2" & etc.) = True/False

 

or

 

Component.Visible("Bolted Connection:1 thru 6") = True/False

 

Or perhaps there is a simple line of code I could add to "capture" Bolt Connections 1 thru 6 and set their visibility state - such as maybe assigning them to an object variable or something? (Although ideally, I was hoping there was just some syntax I was missing in the Component.Visible command that could achieve this more simply)

 

So, other than the possible solution I described, do I have to place a separate Component.Visible command for each component?

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

mslosar
Advisor
Advisor
1. You probably want to post this in the customization forum
2. I don't think you can do multiples like that. You might be able to do it with a loop, but I don't believe it does compound statements. I don't think vba or dot net would do what you're after either.

I'm aware of things like:

if parameter1 = "2" and parameter2 = "7" then
'do stuff
end if

but setting values tends to be a one at a time thing from my experience.
0 Likes
Message 3 of 5

cwhetten
Advisor
Advisor
Accepted solution

Hi and welcome to the forum!

 

The Component.Visible command can't do what you want.  It's a one-at-a-time thing.

 

I am working on a project that does something like yours (using component visibility to control configurations).  But, turning a component invisible isn't good enough--it still shows up in the bill of materials.  So, for each line of code to turn a component invisible, I also have to have a line that sets the BOM structure of the component to 'reference'.  This effectively removes it from the BOM.

 

My code was getting quite cumbersome to develop, so I came up with a way to make my life easier:

 

I have an external rule that changes the visibility state and BOM structure of a component with a given name.  I also made it so I could pass an array list of component names and true/false visibility toggles and it would loop through each one.

 

So, instead of two lines of code for each visibility change, it reduced to one line per visibility change plus one line at the beginning of the rule to initialize the array list and two lines at the end of the rule to pass the array list and run the external rule.

 

It works really well and I am happy with it.

 

Below is the external rule.  It is not as complex as its length suggests--there is just a lot of error handling:

 

Spoiler
'Use the custom snippet "Component Visibility" under the Model Automation folder to call this rule.
'Toggles the visibility of an assembly component of a given name.  Optionally sets an associative view
'representation of a given name if the component is made visible.

oThisDocName = ThisDoc.Document.DisplayName
Try
	oArrayCollection = SharedVariable("svComponentVisibility")
	If oArrayCollection.Count = 0 Then
		MessageBox.Show("Error in Component Visibility external rule in """ & oThisDocName & """:" & vbNewLine _
		& "The collection of argument arrays from the shared variable is empty.", "Component Visibility external rule", _
		MessageBoxButtons.OK, MessageBoxIcon.Error)
		Exit Sub
	End If

Catch
	MessageBox.Show("Error in Component Visibility external rule in """ & oThisDocName & """:" & vbNewLine _
	& "There was an error in processing the shared variable.", "Component Visibility external rule", _
	MessageBoxButtons.OK, MessageBoxIcon.Error)
	Exit Sub
End Try
SharedVariable.Remove("svComponentVisibility")

For Each oArray In oArrayCollection
	Try
		oVisiCompName = oArray(0)
		bTF = oArray(1)
		If oArray.Length = 3 Then
			ViewRepName = oArray(2)
		Else
			ViewRepName = ""
		End If
	Catch
		MessageBox.Show("Error in Component Visibility external rule in """ & oThisDocName & """:" & vbNewLine _
		& "There was an error in processing the argument array from the collection.", "Component Visibility external rule", _
		MessageBoxButtons.OK, MessageBoxIcon.Error)
		Continue For
	End Try
	
	Try
		oVisiComp = Component.InventorComponent(oVisiCompName)
	Catch
		'Assume error means component not found
		MessageBox.Show("Error in Component Visibility external rule in """ & oThisDocName & """:" & vbNewLine _
		& "The component called """ & oVisiCompName & """ was not found.", "Component Visibility external rule", _
		MessageBoxButtons.OK, MessageBoxIcon.Error)
		Continue For
	End Try
	
	oVisiComp.Visible = bTF
	If bTF Then
		oVisiComp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
		If oVisiComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject And (Not ViewRepName = "") Then
			oViewReps = oVisiComp.Definition.RepresentationsManager.DesignViewRepresentations
			foundit = 0
			For Each oViewRep In oViewReps
				If oViewRep.Name = ViewRepName Then
					foundit = 1
					Exit For
				End If
			Next
			If foundit Then
				oVisiComp.SetDesignViewRepresentation(ViewRepName, , True)
			Else
				MessageBox.Show("Error in Component Visibility external rule in """ & oThisDocName & """:" & vbNewLine _
				& "The view representation named """ & ViewRepName & """ was not found in" & vbNewLine & "the component called """ _
				& oVisiCompName & """.", "Component Visibility external rule", MessageBoxButtons.OK, MessageBoxIcon.Error)
			End If
		End If
	Else
		oVisiComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	End If
Next

Below is a short example of how I use this external rule from my main assembly rule:

 

Spoiler
'Activate the iLogic view representation
ThisDoc.Document.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("iLogic").Activate
Dim ComponentVisibility As New List(Of Object) 	'this initializes the visibility array list

If PumpQuantity = 2 And OutletQuantity = 2 Then
	ComponentVisibility.Add(New Object(){"_DischargeHeaderPipeSupport", 0})
	
Else
	ComponentVisibility.Add(New Object(){"_DischargeHeaderPipeSupport", 1})
	
End If

Select Case FlushWater_YN
	Case "No"
	ComponentVisibility.Add(New Object(){"_FlushInletPipeSupport", 0})

	Case "Yes"
	ComponentVisibility.Add(New Object(){"_FlushInletPipeSupport", 1, "iLogic"})
End Select

SharedVariable("svComponentVisibility") = ComponentVisibility 	'this makes the visibility array list available to the external rule
iLogicVb.RunExternalRule("Component Visibility")


InventorVb.DocumentUpdate()

 

I set up some custom snippets so that I don't have to manually write each line every time:

 

Component Visibility iLogic.png

 

I hope this helps.

 

Please click "Accept as Solution" if this response answers your question.

Cameron Whetten
Inventor 2014

Message 4 of 5

cwhetten
Advisor
Advisor

I thought it might be helpful to post a pared-down version of the external rule with most of the error handling removed.  This makes it easier to see exactly what the external rule is doing:

 

Spoiler
'Use the custom snippet "Component Visibility" under the Model Automation folder to call this rule.
'Toggles the visibility of an assembly component of a given name.  Optionally sets an associative view
'representation of a given name if the component is made visible.

oThisDocName = ThisDoc.Document.DisplayName

oArrayCollection = SharedVariable("svComponentVisibility")

SharedVariable.Remove("svComponentVisibility")

For Each oArray In oArrayCollection
	oVisiCompName = oArray(0)
	bTF = oArray(1)
	If oArray.Length = 3 Then
		ViewRepName = oArray(2)
	Else
		ViewRepName = ""
	End If
	
	oVisiComp = Component.InventorComponent(oVisiCompName)

	oVisiComp.Visible = bTF

	If bTF Then
		oVisiComp.BOMStructure = BOMStructureEnum.kDefaultBOMStructure
		If oVisiComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject And (Not ViewRepName = "") Then
			oViewReps = oVisiComp.Definition.RepresentationsManager.DesignViewRepresentations
			foundit = 0
			For Each oViewRep In oViewReps
				If oViewRep.Name = ViewRepName Then
					foundit = 1
					Exit For
				End If
			Next
			If foundit Then
				oVisiComp.SetDesignViewRepresentation(ViewRepName, , True)
			Else
				MessageBox.Show("Error in Component Visibility external rule in """ & oThisDocName & """:" & vbNewLine _
				& "The view representation named """ & ViewRepName & """ was not found in" & vbNewLine & "the component called """ _
				& oVisiCompName & """.", "Component Visibility external rule", MessageBoxButtons.OK, MessageBoxIcon.Error)
			End If
		End If
	Else
		oVisiComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	End If
Next

Cameron Whetten
Inventor 2014

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks for your responses!

 

cwhetten, that's exactly what I needed to know. In my particular case, I'm not worried about what parts show in the BOM since I will need all the components (visible or not) displayed in the BOM anyway. For future projects though, I think I will give your method a try as it appears to kill two birds with one stone. Still new to Inventor/iLogic, so "tricks" like that are very helpful.

0 Likes