adding Shared Parameter with some Parameter Groups

adding Shared Parameter with some Parameter Groups

Eri.Myalitsin
Contributor Contributor
1,012 Views
4 Replies
Message 1 of 5

adding Shared Parameter with some Parameter Groups

Eri.Myalitsin
Contributor
Contributor

Hello,

 

Is there any way of having some different BuiltInParameterGroup when adding Shared Parameter to family document?

 

I am trying to do it with this code but getting error :

 

foreach (DefinitionGroup group in m_sharedFile.Groups)
{
     foreach (ExternalDefinition def in group.Definitions)
     {
          FamilyParameter param = m_manager.get_Parameter(def.Name);

          if (null != param)
          {
               continue;
          }

          try
          {
               if (def.ParameterType == ParameterType.Length)
               {
                    m_manager.AddParameter(def, BuiltInParameterGroup.PG_LENGTH, true);
               }
               else if (def.Name == "Height Range")
               {
                    m_manager.AddParameter(def, BuiltInParameterGroup.PG_DATA, true);
               }
               else
               {
                    m_manager.AddParameter(def, BuiltInParameterGroup.PG_FLEXIBLE, true);
               }
          }

          catch (System.Exception e)
          {
               MessageManager.MessageBuff.AppendLine(e.Message);
               return false;
          }
     }
}

 

 

Best regards,

Eri

 

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

CoderBoy
Advocate
Advocate

What error message are you getting?

 

Are you doing this within a transaction?

 

 

0 Likes
Message 3 of 5

Eri.Myalitsin
Contributor
Contributor

Thank you for your reply.

 

Error message shows :

 

The input parameter group cannot be assigned new parameters.
Parameter name: parameterGroup

 

If I don't use if condition (assigning only one BuiltInParameterGroup), it works.

This program is based on AutoParameter of Revit 2016 SDK sample.

I modified AddSharedParameter method.

 

Best regards,

Eri

0 Likes
Message 4 of 5

CoderBoy
Advocate
Advocate
Accepted solution

Generally speaking, the code looks good.

 

Can you narrow down, is it one specific parameter group that throws the exception, or is it every parameter that gets added to all three groups?

 

Does the exception get thrown when adding to the BuiltInParameterGroup.PG_LENGTH group?

 

Does the exception get thrown when adding to the BuiltInParameterGroup.PG_DATA group?

 

Does the exception get thrown when adding to the BuiltInParameterGroup.PG_FLEXIBLE group?

 

 

Also, I wonder if some of those groups don't (can't?) exist in some families of different categories (most notably PG_FLEXIBLE, which I've not seen before).

 

For those parameter groups that fail, can you test the code on families that already have the groups of interest defined and see if it works on those?

 

 

Message 5 of 5

Eri.Myalitsin
Contributor
Contributor

Thank you for your helpful advice!

 

I tested for each case, then found out that PG_FLEXIBLE is making an error as you pointed out.

Also, PG_LENGTH cannot accept any length parameter ( I don't know why.. )

 

Anyway, basically the code works now if I avoid the issues listed above.

0 Likes