Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created June 19, 2020 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/342cb46816865e99c4602ce6af2dc545 to your computer and use it in GitHub Desktop.
Save chuongmep/342cb46816865e99c4602ce6af2dc545 to your computer and use it in GitHub Desktop.
/// <summary>
/// Gets or Creates Element's shared param.
/// </summary>
/// <param name="elem">Revit Element to get param for</param>
/// <param name="paramName">Parameter Name</param>
/// <param name="grpName">Param Group Name (relevant only when Creation takes place)</param>
/// <param name="paramType">Param Type (relevant only when Creation takes place)</param>
/// <param name="visible">Param UI Visibility (relevant only when Creation takes place)</param>
/// <param name="instanceBinding">Param Binding: Instance or Type (relevant only when Creation takes place)</param>
/// <returns></returns>
public static Parameter GetOrCreateElemSharedParam(Element elem, string paramName, string grpName, ParameterType paramType, bool visible, bool instanceBinding)
{
try
{
// Check if existing
Parameter param = GetElemParam(elem, paramName);
if (null != param) return param;
// If here, need to create it...
BindSharedParamResult res = BindSharedParam(elem.Document, elem.Category, paramName, grpName, paramType, visible, instanceBinding);
if (res != BindSharedParamResult.eSuccessfullyBound && res != BindSharedParamResult.eAlreadyBound) return null;
// If here, binding is OK and param seems to be IMMEDIATELY available from the very same command
return GetElemParam(elem, paramName);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(string.Format("Error in getting or creating Element Param: {0}", ex.Message));
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment