I'm working on a piece of iLogic code that supresses components in an assembly base on selections made to an excel sheet. To do this I'm using Case statements. The problem is that the display name of the components has the part number in it and I want to be able to use this code on multiple assemblies with different parts in them. So I want to be able to suppress component based on if their name contains a string. Here is a sample of my code.
Select Case DRIVE
Case "0"
Component.IsActive("226343:1-DRIVE 460V")=0
Component.IsActive("236662:1-DRIVE 380V")=0
Component.IsActive("289132:1-DRIVE 575V")=0
Case "1"
Component.IsActive("226343:1-DRIVE 460V")=1
Component.IsActive("236662:1-DRIVE 380V")=0
Component.IsActive("289132:1-DRIVE 575V")=0
Case "2"
Component.IsActive("226343:1-DRIVE 460V")=0
Component.IsActive("236662:1-DRIVE 380V")=1
Component.IsActive("289132:1-DRIVE 575V")=0
Case "3"
Component.IsActive("226343:1-DRIVE 460V")=0
Component.IsActive("236662:1-DRIVE 380V")=0
Component.IsActive("289132:1-DRIVE 575V")=1
End Select
So basically I want to remove the part numbers from what I've got shown and suppress or unsuppress based on the 460V, 380V, and 575V string. Does anyone know how to do this?
Andrew In’t Veld
Designer
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi andrewiv,
You can use String.Contains() to do this. Here is a real quick example that looks at all of the components in an assembly and finds the ones that contain a defined string value.
I didn't have time to stop to look at your Select Case code to see how this would tie into what you have, but you should be able to work it out. If not post back and I'm sure someone will take another look.
Related links:
http://stackoverflow.com/questions/6370081/vb-net-if-string-contains-value1-or-value2
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
' set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim myString1 As String = "380V"
Dim myString2 As String = "460V"
Dim myString3 As String = "575V"
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
If oOccurrence.Name.Contains(myString1) Or _
oOccurrence.Name.Contains(myString2) Or _
oOccurrence.Name.Contains(myString3) Then
'Show occurrence name in the message
MessageBox.Show("Suppressing: " & oOccurrence.Name, "iLogic")
'suppress the component
Component.IsActive(oOccurrence.Name) = False
Else
End If
Next
Thanks for the help. I think I got it now. I changed my program to read like this.
Dim doc As AssemblyDocument Dim oAsmCompDef As AssemblyComponentDefinition Dim oComp As ComponentOccurrence Dim oComps As ComponentOccurrences doc = ThisDoc.Document oAsmCompDef = doc.ComponentDefinition oComps = oAsmCompDef.Occurrences For Each oComp In oComps If oComp.Name.Contains("DRIVE 460V") Then DRIVE460V = oComp.Name ElseIf oComp.Name.Contains("DRIVE 380V") Then DRIVE380V = oComp.Name ElseIf oComp.Name.Contains("DRIVE 575V") Then DRIVE575V = oComp.Name End If Next Select Case DRIVE Case "0" Component.IsActive(DRIVE460V)=0 Component.IsActive(DRIVE380V)=0 Component.IsActive(DRIVE575V)=0 Case "1" Component.IsActive(DRIVE460V)=1 Component.IsActive(DRIVE380V)=0 Component.IsActive(DRIVE575V)=0 Case "2" Component.IsActive(DRIVE460V)=0 Component.IsActive(DRIVE380V)=1 Component.IsActive(DRIVE575V)=0 Case "3" Component.IsActive(DRIVE460V)=0 Component.IsActive(DRIVE380V)=0 Component.IsActive(DRIVE575V)=1 End Select
Andrew In’t Veld
Designer
This code works for me as well, but how can I also suppress constraints containing the same string of text?
This code works for me as well, but how can I adjust the code to suppress constraints containing a string of text (rather than or in addition to files)?
Hi @Curtis_Waguespack is it possible to use above code with below condition instead of the below hard way one by on to suppress based on name " INNER" , thanks.