Custom Parameter Groups

Custom Parameter Groups

SpokenEarth
Advocate Advocate
831 Views
8 Replies
Message 1 of 9

Custom Parameter Groups

SpokenEarth
Advocate
Advocate

Hi forum, I m trying to create custom parameter groups so i can organize my parameters. Here is my syntax code with error so far.

 

Sub Main()

	Dim oPartDoc As PartDocument = ThisDoc.Document  
	Dim oPartCompDef As ComponentDefinition  
	oPartCompDef = oPartDoc.ComponentDefinition 
	
    Dim oCustomParamGroup As CustomParameterGroup
    oCustomParamGroup = oPartCompDef.Parameters.CustomParameterGroups.Add("Custom Group", "BS 4825-3")
    
    oCustomParamGroup.Add("BS 4825-3")
End Sub
0 Likes
Accepted solutions (2)
832 Views
8 Replies
Replies (8)
Message 2 of 9

A.Acheson
Mentor
Mentor
Accepted solution

You will need to add the parameter by object "oUserParam" . The group needs to be deleted if it has been all ready created, in order to add more parameters. I have also added some error catching. Here is a helpful post that shows the API help sample which helped show how it functions. Ensure the user parameters exist before running the rule.

 

API Help Location

AAcheson_0-1629253436503.png

 

 

 

Sub Main()

	Dim oPartDoc As PartDocument = ThisDoc.Document 
	
	Dim oPartCompDef As PartComponentDefinition
	oPartCompDef = oPartDoc.ComponentDefinition 
	 
	Dim oCustomParamGroup As CustomParameterGroup
	
	Try
   	oCustomParamGroup = oPartCompDef.Parameters.CustomParameterGroups.Add("Custom Group", "BS 4825-3")
	Catch
	'Delete CustomParameterGroups if one exist in order to add new parameters
	oPartCompDef.Parameters.CustomParameterGroups("BS 4825-3").Delete
	oCustomParamGroup = oPartCompDef.Parameters.CustomParameterGroups.Add("Custom Group", "BS 4825-3")
	End Try
	
        ' Create a user parameter
        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

	Try
        oCustomParamGroup.Add(oUserParam)
	oCustomParamGroup.Add(oUserParam1)
	oCustomParamGroup.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
Message 3 of 9

SpokenEarth
Advocate
Advocate

Hi, the code you provided me does what I was expecting, thought I need to rewrite my parameters but definitely it is worth the time to do so.
I have no API knowledge but I will be very interesting learning.
Thank you so much for your help.
Have a good one.

0 Likes
Message 4 of 9

SpokenEarth
Advocate
Advocate

Can this code applied also for text parameters?

0 Likes
Message 5 of 9

A.Acheson
Mentor
Mentor

Yes this works with text parameters, I just tested and it works fine. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 9

SpokenEarth
Advocate
Advocate

Custom Parameter Groups

0 Likes
Message 7 of 9

SpokenEarth
Advocate
Advocate

A.Acheson, earlier today you helped me out with the code for custom parameter groups, the code works fine but when i create two groups the values for the second group appears also in the first group.
Please see attached image at the original post.
Thank you Achilles

0 Likes
Message 8 of 9

A.Acheson
Mentor
Mentor
Accepted solution

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
Message 9 of 9

SpokenEarth
Advocate
Advocate

Beautiful!! it works like a charm.
Thank you for the time you took to review my posts Alan and your effort to find a solution

Regards.
Achilles