Hi @CattabianiI, thank you so much, it works great! Not seen tuple before in ilogic, very intrigued 🤓
I've added the existing part no. as a string and then added the material suffix after, seems to be working okay.
I'm wondering if you could help with 1 further tweak though. I've added in the last line to go back to Primary once done. I'd ideally like to ensure it starts on Primary as well, due to line 19. However if I add that same line higher in the code, it wont work on a part that has no existing mode states already. In other words, how can I ensure it always starts with Primary, whether there is existing model states or not?
Dim msRows As New List(Of Tuple(Of String, String, String))()
' Define model states: name, material, part number
msRows.Add(New tuple(Of String, String, String)("AL", "Aluminum 6061", "/AL"))
msRows.Add(New tuple(Of String, String, String)("COP", "Copper", "/COP"))
msRows.Add(New tuple(Of String, String, String)("IRON", "Iron, Cast", "/IRON"))
msRows.Add(New tuple(Of String, String, String)("NI", "Nickel-Copper Alloy 400", "/NI"))
msRows.Add(New tuple(Of String, String, String)("SS", "Stainless Steel", "/SS"))
msRows.Add(New tuple(Of String, String, String)("TI", "Titanium", "/TI"))
Dim doc As Document = ThisApplication.ActiveDocument
Dim mss As ModelStates = doc.componentdefinition.modelstates
Dim PartNo As String = iProperties.Value("Project", "Part Number")
'Start from Primary ### Wont work if part has no existing model states??? ####
ThisDoc.ActiveModelState = ThisServer.LanguageTools.CurrentPrimaryModelStateString
' Assume active model state is the [Primary] ### hopefully solved with above ###
' Set part number in the active model state
iProperties.Value("Project", "Part Number") = PartNo & "/XX"
For Each msRow As Tuple(Of String, String, String) In msRows
' Create model state
mss.Add(msRow.Item1)
' the newly created model state is now the active one
' Set iProperties in the active model state
iProperties.Material = msRow.Item2
iProperties.Value("Project", "Part Number") = PartNo & msRow.Item3
Next
'Go back to Primary once complete
ThisDoc.ActiveModelState = ThisServer.LanguageTools.CurrentPrimaryModelStateString
Thanks again, appreciate the help!
Craig