Adding more than 1 group will be just a repeat of the first process. Take note of the number change on the Dim line , this could be any unique name you want. Just ensure you change it anywhere else it appears.
Dim oCustomParamGroup1 As CustomParameterGroup
Dim oCustomParamGroup2 As CustomParameterGroup
I have split up the rule to make it more user friendly and added in grouping drop down with names to make it more readable. You can declare your user names at the start or place them inside the groups before you add them to the group.
Sub Main()
Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = oPartDoc.ComponentDefinition
'[User Parameters
' Declare user parameters
Dim oUserParam As UserParameter
Dim oUserParam1 As UserParameter
Dim oUserParam2 As UserParameter
Try
oUserParam = oPartCompDef.Parameters.UserParameters("Hello")
oUserParam1 = oPartCompDef.Parameters.UserParameters("Hello1")
oUserParam2 = oPartCompDef.Parameters.UserParameters("Hello2")
Catch
End Try
']
'[Group1 Creation
Dim oCustomParamGroup1 As CustomParameterGroup
Try
oCustomParamGroup1 = oPartCompDef.Parameters.CustomParameterGroups.Add("Custom Group1","Custom Group1")
Catch
'Delete CustomParameterGroups if one exist in order to add new parameters
oPartCompDef.Parameters.CustomParameterGroups("Custom Group1").Delete
oCustomParamGroup1 = oPartCompDef.Parameters.CustomParameterGroups.Add("Custom Group1","Custom Group1")
End Try
Try
oCustomParamGroup1.Add(oUserParam)
oCustomParamGroup1.Add(oUserParam1)
oCustomParamGroup1.Add(oUserParam2)
Catch
End Try
']
'[Group2 Creation
Dim oCustomParamGroup2 As CustomParameterGroup
Try
oCustomParamGroup2 = oPartCompDef.Parameters.CustomParameterGroups.Add("Custom Group2","Custom Group2")
Catch
'Delete CustomParameterGroups if one exist in order to add new parameters
oPartCompDef.Parameters.CustomParameterGroups("Custom Group2").Delete
oCustomParamGroup2 = oPartCompDef.Parameters.CustomParameterGroups.Add("Custom Group1","Custom Group2")
End Try
Try
oCustomParamGroup2.Add(oUserParam)
'oCustomParamGroup2.Add(oUserParam1)
'oCustomParamGroup2.Add(oUserParam2)
Catch
End Try
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan