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: 

Binding Shared Parameters Failing on some Categories

4 REPLIES 4
Reply
Message 1 of 5
greg7KTAR
1080 Views, 4 Replies

Binding Shared Parameters Failing on some Categories

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;

}

Labels (2)
4 REPLIES 4
Message 2 of 5
jeremy_tammik
in reply to: greg7KTAR

For some categories, this is a known issue. Maybe you are running into the same.

 

I cannot view your attached image. It says:

 

> Document preview of Support Shared Parameters Binding to Element Categories.png
> Error displaying attachment content

 

Can you share a complete minimal reproducible case that I can pass on to the development team in case there is a problem that needs reporting?

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

  

Thank you!

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5
greg7KTAR
in reply to: greg7KTAR

Jeremy:

 

Thanks for your reply. I would like to produce a cast, however, this morning I found a solution that looks like it works (with some caveats), and with that in mind I can no longer reproduce exactly the same thing. However, I may be able to pinpoint the problem with a screen cast after I clean up this set of code. Here's an update as to my experience. It appears if you set the categories once, you can't re-set them to a project or set them to more categories later(at least with the code I am using)  - and therein could be the root of the issue.  So starting fresh, if I set them all at once (in a small test it worked). I may need help to set the variables themselves later - or deal with partially set models needing the remaining categories or Shared Parameters added, but am getting the fields on all items when i do it this way. I switched to the method from the SDK, which does all the CatSet.Insert on all categories at once, such as:

 

Category DuctClassification = doc.Settings.Categories.get_Item(BuiltInCategory.OST_DuctCurves);
Category DuctFittingsClassification = doc.Settings.Categories.get_Item(BuiltInCategory.OST_DuctFitting);
Category DuctAccessoryClassification = doc.Settings.Categories.get_Item(BuiltInCategory.OST_DuctAccessory);
Category FlexDuctClassification = doc.Settings.Categories.get_Item(BuiltInCategory.OST_FlexDuctCurves);

catSet.Insert(DuctClassification);
catSet.Insert(DuctFittingsClassification);
catSet.Insert(DuctAccessoryClassification);
catSet.Insert(FlexDuctClassification);

Message 4 of 5
Sean_Page
in reply to: greg7KTAR

Have you tried to bind one of those parameters manually to the families to see what if anything it says? In the past, i have ran into what Jeremy is describing with certain parameter types not being supported by some categories.

Message 5 of 5
bixilix
in reply to: greg7KTAR

I have the very same problem. I cannot add some parameters to some categories by script. When I do it manually it works fine. I´m using Revit 2021. Did anyone solve this problem?

I tried to get the categories with:

Category cat = doc.Settings.Categories.get_Item(builtInCategory);

and 
Category cat = Category.GetCategory(doc, builtInCategory);

 

It does not work when adding these to my CategorySet.

 

Binding the parameter to the category Ebenen is not allowed

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

Post to forums  

Rail Community


Autodesk Design & Make Report