Binding Shared Parameters Failing on some Categories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In the Revit API, I have created the Shared Parameters file and in the routine applied it to the project and in doing create a group definition fine. I am getting the definition file within the api, and am successful at getting the category cat returned. (Jeremy has a previous routine I basically used, but modified it further to solve some holes - can post more), next I loop through the public array called:
public static BuiltInCategory[] AnalyticsDataTargets = new BuiltInCategory[] {
BuiltInCategory.OST_DuctCurves, BuiltInCategory.OST_DuctFitting, BuiltInCategory.OST_DuctAccessory, BuiltInCategory.OST_FlexDuctCurves, BuiltInCategory.OST_DuctTerminal,
BuiltInCategory.OST_MechanicalEquipment,
BuiltInCategory.OST_PipeCurves, BuiltInCategory.OST_PipeFitting, BuiltInCategory.OST_PipeAccessory, BuiltInCategory.OST_PlumbingFixtures,
BuiltInCategory.OST_Conduit, BuiltInCategory.OST_ConduitFitting,
BuiltInCategory.OST_CableTray, BuiltInCategory.OST_CableTrayFitting,
BuiltInCategory.OST_ElectricalEquipment, BuiltInCategory.OST_ElectricalFixtures, BuiltInCategory.OST_LightingDevices, BuiltInCategory.OST_LightingFixtures };
public static void AssignSharedInstanceParameterToCategories(Document doc, string defname, string AnalyticsMEPSharedParameterGroupName)
{
Application app = doc.Application;
bool BindingCreatedSucceeded = false;
bool typeParameter = false;
/// This needs to be a repeatable function passing DefinitionName and DefinitionType
using (Transaction t = new Transaction(doc))
{
t.Start("Create Shared Parameter");
Category cat;
// create instance parameters:
foreach (BuiltInCategory target in AnalyticsDataTargets)
{
cat = GetCategory(doc, target);
if (null != cat)
{
CreateSharedParameterBindingToCategorySet(doc, cat, defname, typeParameter, AnalyticsMEPSharedParameterGroupName);
}
}
t.Commit();
}
}
And within that CreateSharedParameterBindingToCategorySet used Jeremy's example (I can post my efforts at the SDK example approach as well). It isnt working for all categories - not sure why and could use help:
static bool CreateSharedParameterBindingToCategorySet(Document doc, Category cat, string defname, bool typeParameter, string AnalyticsMEPSharedParameterGroupName)
{
Application app = doc.Application;
Autodesk.Revit.Creation.Application ca = app.Create;
string filename = app.SharedParametersFilename;
DefinitionFile file = app.OpenSharedParameterFile();
DefinitionGroup group = file.Groups.get_Item(AnalyticsMEPSharedParameterGroupName);
bool visible = cat.AllowsBoundParameters;
Definition definition = group.Definitions.get_Item(defname);
// create the category set containing our category for binding:
CategorySet catSet = ca.NewCategorySet();
catSet.Insert(cat);
try
{
Binding binding;
if (typeParameter == true)
{
// Binding binding = typeParameter
// ? ca.NewTypeBinding(catSet) as Binding
// : ca.NewInstanceBinding(catSet) as Binding;
binding = ca.NewTypeBinding(catSet) as Binding;
}
else
{
binding = ca.NewInstanceBinding(catSet) as Binding;
}
// we could check if it is already bound, but it looks like insert will just ignore it in that case:
// NEED THE CODE FOR THIS CHECK - THAT IS THE POINT FOR DEBUG
// Option to not Specify the Parameter Group
doc.ParameterBindings.Insert(definition, binding);
// Option to specify the parameter group here:
// doc.ParameterBindings.Insert(definition, binding, BuiltInParameterGroup.PG_GENERAL);
string strTypeParam = "";
if (typeParameter)
{
strTypeParam = "type";
}
else
{
strTypeParam = "instance";
}
string DebugTest = "Created a shared {0} parameter '{1}' for the {2} category. " + strTypeParam + "defname = " + defname + "catName = " + cat.Name;
}
catch (Exception ex)
{
//Util.ErrorMsg(string.Format( "Error binding shared parameter to category {0}: {1}", cat.Name, ex.Message));
return false;
}
return true;
}
Developer Advocacy and Support +