Shared and Project Parameter cannot be assigned to certain categorys

Shared and Project Parameter cannot be assigned to certain categorys

Anonymous
Not applicable
832 Views
8 Replies
Message 1 of 9

Shared and Project Parameter cannot be assigned to certain categorys

Anonymous
Not applicable

Hi there, I created an addin to create multiple shared and meanwhile project parameters in Revit at once. For the main part it works perfect. However some of the categories I implemented keep on failing, such as OST_ConduitFitting, OST_CableTrayRun, MEP-Spaces, OST_Wires...

 

It is all the same code so I wonder what it could be relied on? I am using Revit 2019.

 

if (categoryName == "Kabel")
{
myCategory = Category.GetCategory(m_doc, BuiltInCategory.OST_Wire);
categoryFound = true;
}

 

Any idea what could cause the problem? Thanks in advance!

0 Likes
833 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Dear Alessandra,

  

Does this problem sound similar to yours?

  

https://forums.autodesk.com/t5/revit-api-forum/category-for-ost-revisions/td-p/8706627

  

Can you please provide a minimal reproducible case for the development team to analyse and reproduce the issue?

  

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

  

Thank you!

  

Best regards,

  

Jeremy

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 9

Anonymous
Not applicable
Hi Jeremy,
thanks for the swift reply. Yes as far as I understand that sounds familiar to my problem, but what does “hidden” to user mean? I can see the category in my user interface when creating a shared parameter manually. And with a lot of categorys it works as explained.
What details would you need to analyse the issue? The categorys that don’t work or are they simply not possible to be set via api?
We want to create a big amount of attributes in Revit Templates so I need all provided categories which are visible for the user at least to be working in my addin…
Thanks in advance!
0 Likes
Message 4 of 9

jeremytammik
Autodesk
Autodesk

Can you add a shared parameter to the revisions category in the user interface?

 

Apparently, you cannot in the API.

 

Can you add a shared parameter to the categories you are interested in in the user interface?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 9

adam.krug
Advocate
Advocate

@Anonymous what do you mean exactly by "some of the categories I implemented keep on failing"? What does the exception tells?

 

I just did a small test with BuiltInCategory.OST_Wire category - no problem to add a project shared parameter via API.

 

tested on Revit 2019, new blank project.

0 Likes
Message 6 of 9

adam.krug
Advocate
Advocate

the test code:

public void TestProjParam()
{
	string extDefFilePath = Application.Application.SharedParametersFilename;
	Categories cats = ActiveDoc.Settings.Categories;

	CategorySet catset1 = new CategorySet();
	catset1.Insert(cats.get_Item(BuiltInCategory.OST_Wire));

	ExternalDefinition testpar = GetExternalDefinitionFromFile(ActiveDoc.Application, extDefFilePath, "Exported Parameters", "EAN_code");

	SingleProjectParameterInfo parinfo = new SingleProjectParameterInfo(testpar, catset1, BuiltInParameterGroup.PG_CONSTRUCTION, false);
	
	SetUpParameter(parinfo);
}

public static ExternalDefinition GetExternalDefinitionFromFile(Autodesk.Revit.ApplicationServices.Application app,
                   string filePath,
string groupName,
string defName) string defName) { string currentDefFilePath = app.SharedParametersFilename; ExternalDefinition eDef = null; try { //set new location for def file and read external definition app.SharedParametersFilename = filePath; DefinitionFile defFile = app.OpenSharedParameterFile(); DefinitionGroups defGroups = defFile.Groups; DefinitionGroup myGroup = defGroups.get_Item(groupName); Definitions myDefs = myGroup.Definitions; eDef = myDefs.get_Item(defName) as ExternalDefinition; } finally { //set old location for def file (reset) app.SharedParametersFilename = currentDefFilePath; } return eDef; } public bool SetUpParameter(SingleProjectParameterInfo parInfo) { bool result = false; using (Transaction tx = new Transaction(ActiveDoc, "setting parameter")) { tx.Start(); Binding binding = null; if (parInfo.BoundToInstance) binding = ActiveDoc.Application.Create.NewInstanceBinding(parInfo.Categories); else binding = ActiveDoc.Application.Create.NewTypeBinding(parInfo.Categories); BindingMap map = ActiveDoc.ParameterBindings; result = map.Insert(parInfo.ExtDef, binding, parInfo.Group); if (result) tx.Commit(); else tx.RollBack(); } return result; }
0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi Adam,

thanks for the code. I tried to give it a go on my Computer, but I cannot figure out your "

SingleProjectParameterInfo"? Did I miss some code?

 

In fact the only difference I can see so far is that you apply the wires to

BuiltInParameterGroup.PG_CONSTRUCTION, whereas I always use PG_GENERAL. Could that cause the issue? The code does not fail, the category is just not applied when Setting the Project parameter @jeremytammik  I can see all categories in the user Interface I want to use in my code.... Is there an overview which Parameter belongs to  which Group? Or any hint I can apply that in my addin?

0 Likes
Message 8 of 9

jeremytammik
Autodesk
Autodesk

Here is a link pointing to a description and list of links of the tools and research I invested into this area in the past:

 

https://thebuildingcoder.typepad.com/blog/2019/04/binding-a-shared-parameter-to-revision.html#4

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 9

adam.krug
Advocate
Advocate

SingleProjectParamInfo is simply a container class that has the 4 properties used in the body of SetUpParam method.

 

the category used should not matter at all...

0 Likes