Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I save a selected parameter in Extensible storage?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
912 Views, 5 Replies

How do I save a selected parameter in Extensible storage?

Hi,

 

I Am trying to replicate the Revit filter dialogue box as part of a c# addin using a combination of listview, treeview and comboboxes for the filters, categories and filter rules respectively.

Whats the best way to set up a combo box drop-down of parameters and then save the selected parameter item in extensible storage (as per the highlighted drop down in the image below)?

 

Trying to save the parameter itself throws an error as is not an allowed extensible storage data type.

ElementId, GUID, String or integer could be used. But the ElementId for a parameter is a negative number (throws error) and not all parameters return a guid.

Does anyone know is it is there a better way to save the parameter selection instead of casting the selected parameter ID to int or parameter name to string then doing a lookup for this?

 

Also - is it possible to a retrieve a parameter using an ID or GUID? Obviously, retrieving elements can be done with doc.getElement(Id) but is there an equivalent for parameters?

 

Thanks in advance

 

image.png

5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

Hi,

I recently completed a project very similar. A resource that will help a lot is the ViewFilters example in the Revit SDK (RevitSDK/Samples/ElementFilter/ViewFilters). This replicates the Revit filter dialogue box and allows for more than 3 rules. However, it only works with built in parameters.

 

As for extracting the BuiltInParameters, the sample code creates a helper class to help with the parsing. Below is the helper class and an example on how it could be used to retrieve a Parameter from its id. There might be a more efficient way, but this is the process used in the example.

String elementName = EnumParseUtility<BuiltInParameter>.Parse(elemendId.IntegerValue);
BuiltInParameter curParam = EnumParseUtility<BuiltInParameter>.Parse(elementName);

 

 

/// <summary>
/// Generic utility class used to extend enum parse related methods
/// </summary>
/// <typeparam name="TEnum">Enum type for this class.</typeparam>
public static class EnumParseUtility<TEnum>
{
   /// <summary>
   /// Parse string to TEnum values
   /// </summary>
   /// <param name="strValue">Enum value in string.</param>
   /// <returns>TEnum value is parsed from input string.</returns>

   public static TEnum Parse(string strValue)
   {
      if (!typeof(TEnum).IsEnum) return default(TEnum);
      try
      {
         return (TEnum)Enum.Parse(typeof(TEnum), strValue);
      }
      catch( Exception ex)
      {
         return default(TEnum);
      }
   }

   /// <summary>
   /// Parse TEnum to string 
   /// </summary>
   /// <param name="enumVal">TEnum value to be parsed.</param>
   /// <returns>String parsed from input TEnum.</returns>
   public static String Parse(TEnum enumVal)
   {
      if (!typeof(TEnum).IsEnum) return String.Empty;
         return Enum.GetName(typeof(TEnum), enumVal);
   }

   /// <summary>
   /// Parse TEnum from integer value to string
   /// </summary>
   /// <param name="enumValInt">Integer value to be parsed.</param>
   /// <returns>String parsed from input TEnum(integer type)</returns>
   public static String Parse(int enumValInt)
   {
      if (!typeof(TEnum).IsEnum) return String.Empty;
         return Enum.GetName(typeof(TEnum), enumValInt);
   }


}

 

I hope this helps, if you have any questions about this or on how to work with custom parameters feel free to ask.

 

Sincerely,

Jason Twigg

 

 

 

Message 3 of 6
Anonymous
in reply to: Anonymous

Hi,

I recently completed a project very similar. A resource that will help a lot is the ViewFilters example in the Revit SDK (RevitSDK/Samples/ElementFilter/ViewFilters). This replicates the Revit filter dialogue box and allows for more than 3 rules. However, it only works with built in parameters.

 

As for extracting the BuiltInParameters, the sample code creates a helper class to help with the parsing. Below is the helper class and an example on how it could be used to retrieve a Parameter from its id. There might be a more efficient way, but this is the process used in the example.

 

String elementName = EnumParseUtility<BuiltInParameter>.Parse(elemendId.IntegerValue);
BuiltInParameter curParam = EnumParseUtility<BuiltInParameter>.Parse(elementName);

Helper Class:

/// <summary>
/// Generic utility class used to extend enum parse related methods
/// </summary>
/// <typeparam name="TEnum">Enum type for this class.</typeparam>
public static class EnumParseUtility<TEnum>
{
   /// <summary>
   /// Parse string to TEnum values
   /// </summary>
   /// <param name="strValue">Enum value in string.</param>
   /// <returns>TEnum value is parsed from input string.</returns>

   public static TEnum Parse(string strValue)
   {
      if (!typeof(TEnum).IsEnum) return default(TEnum);
      try
      {
         return (TEnum)Enum.Parse(typeof(TEnum), strValue);
      }
      catch( Exception ex)
      {
         return default(TEnum);
      }
   }

   /// <summary>
   /// Parse TEnum to string 
   /// </summary>
   /// <param name="enumVal">TEnum value to be parsed.</param>
   /// <returns>String parsed from input TEnum.</returns>
   public static String Parse(TEnum enumVal)
   {
      if (!typeof(TEnum).IsEnum) return String.Empty;
         return Enum.GetName(typeof(TEnum), enumVal);
   }

   /// <summary>
   /// Parse TEnum from integer value to string
   /// </summary>
   /// <param name="enumValInt">Integer value to be parsed.</param>
   /// <returns>String parsed from input TEnum(integer type)</returns>
   public static String Parse(int enumValInt)
   {
      if (!typeof(TEnum).IsEnum) return String.Empty;
         return Enum.GetName(typeof(TEnum), enumValInt);
   }


}

 

I hope this helps, if you have any questions about this or on how to work with custom parameters feel free to ask.

 

Sincerely,

Jason Twigg

 

 

 

Message 4 of 6
Anonymous
in reply to: Anonymous

Hi Jason,

 

Thanks for getting back and pointing me to the ViewFitlers SDK. That'll be great for finishing out creating the filter criteria.... I wish I would have spotted this one sooner!

 

Unfortunately though, as you mentioned in reply, this only covers builtin parameters. I can see from the SDK it uses the viewFilter method to store the filter information in Revit. Whereas I was thinking to use extensible storage to do the same but allow for custom parameters. Did you manage to get your example working with other parameters as well?

 

Thanks again for getting back 

 

Paul

Message 5 of 6
Anonymous
in reply to: Anonymous

Hi Paul,

 

I managed to store custom parameter data in the filter information in Revit. I am not too familiar with the extensible storage, but hopefully explaining how I stored the data as Revit filters will help. The changes made are too much to include in one reply so I will try to explain how I did it, and if you have any specific errors or questions hopefully I can respond with a solution.

 

To start, I created a variable in FilterRuleBuilder for holding the custom Parameter. I intended to have either the BuiltInParameter or CustomParameter variable initialized and leave the other variable null or invalid id. From there, I created copies of each constructor to handle the second case of a custom parameter being passed. Once this is setup, most Filter creation commands need a elementId of the parameter and this could be retrieve like this:

ElementId paramId = null;
if (sharedParameter == null) {
     paramId = new ElementId(Parameter);
}
else
{
     paramId = sharedParameter.Id;
}

 

Next I changed the FilterUtils class to have a second CreateFilterRuleBuilder method that takes a Parameter instead of a BuiltInParameter and creates those rules using the new constructors.

 

From there, I tried to find each place in the code that used BuiltInParameters, and create a second option if the parameter is a custom parameter this can be easily checked with the sign of the ElementId (negative is builtin, and positive is custom).

 

There are a some things I am probably missing, and I was trying to be a concise as possible. So, if you have any questions or need clarification, feel free to ask!

 

Sincerely,

Jason

Message 6 of 6
Anonymous
in reply to: Anonymous

Hi Jason,

 

Apologies for my long delay in marking your response as the solution. This is one part of a larger addin i'm trying to make so had to continue with other items before circling back to this.... it's also my first addin so it took me a long time to figure it out!

 

I've gotten the custom parameters working using filters. I ended up using sharedParameterElement as the extra custom parameter for my filter selection. 

 

A few extra notes if anyone is ever trying to do the same:

 

I Had to create a dictionary of storage vs. parameter types for the typeOfStorage() lookup. This is certainly not the correct way of doing but I filtered all elements then added them to the dictionary.

Also, had to create a list of all sharedparameterelements to use as a lookup, so in the loop above to get the storage types also output all the sharedParameterElements to a List for lookup.

 

Once again, thanks a million for pointing me in the right direction!

 

Cheers,

 

Paul

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community