Hello!
I'm not a very experienced Revit developer (nor an experienced Revit user), so I'm sorry if I got something wrong.
I need to add new parameters to Revit objects via the API. I'm developing an AddIn to do so, but the parameters should be visible in this window:
(I'm sorry, I'm using the German version of Revit, but I think this is called the Properties Palette in English).
How can I add a new set of values there?
I was trying to add a new instance parameter to an existing Revit element, but I couldn't find any information on how to do so.
It seems like I can access all parameters of an object via
element.Parameters
Which returns a ParameterSet. ParameterSet contains the method Insert, but I don't know how to use it. Moreover, in the API documentation, it says that "New parameters can be added to Elements by adding a ParameterBinding object to the Document object." What does this mean?
Or did I get this completely wrong and Instance Parameters are not what I'm looking for?
Thanks for your help!
Solved! Go to Solution.
Solved by JimJia. Go to Solution.
Hi,
Did you find this link?
http://www.revitapidocs.com/2018.1/7978cb57-0a48-489e-2c8f-116fa2561437.htm?section=exampleToggle
The code example also shows how to bind an instance parameter to the document.
I hope this is what you are looking for.
Hi,
The Revit SDK samples have one sample named RoomSchedule which has some code snippet on shared parameter creation, you may refer to this sample for more details.
I also copy/paste the code snippet below for your convenience:
/// <summary> /// Create shared parameter for Rooms category /// </summary> /// <returns>True, shared parameter exists; false, doesn't exist</returns> private bool CreateMyRoomSharedParameter() { // Create Room Shared Parameter Routine: --> // 1: Check whether the Room shared parameter("External Room ID") has been defined. // 2: Share parameter file locates under sample directory of this .dll module. // 3: Add a group named "SDKSampleRoomScheduleGroup". // 4: Add a shared parameter named "External Room ID" to "Rooms" category, which is visible. // The "External Room ID" parameter will be used to map to spreadsheet based room ID(which is unique) try { // check whether shared parameter exists if (ShareParameterExists(RoomsData.SharedParam)) { return true; } // create shared parameter file String modulePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); String paramFile = modulePath + "\\RoomScheduleSharedParameters.txt"; if (File.Exists(paramFile)) { File.Delete(paramFile); } FileStream fs = File.Create(paramFile); fs.Close(); // cache application handle Autodesk.Revit.ApplicationServices.Application revitApp = m_commandData.Application.Application; // prepare shared parameter file m_commandData.Application.Application.SharedParametersFilename = paramFile; // open shared parameter file DefinitionFile parafile = revitApp.OpenSharedParameterFile(); // create a group DefinitionGroup apiGroup = parafile.Groups.Create("SDKSampleRoomScheduleGroup"); // create a visible "External Room ID" of text type. ExternalDefinitionCreationOptions ExternalDefinitionCreationOptions = new ExternalDefinitionCreationOptions(RoomsData.SharedParam, ParameterType.Text); Definition roomSharedParamDef = apiGroup.Definitions.Create(ExternalDefinitionCreationOptions); // get Rooms category Category roomCat = m_commandData.Application.ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Rooms); CategorySet categories = revitApp.Create.NewCategorySet(); categories.Insert(roomCat); // insert the new parameter InstanceBinding binding = revitApp.Create.NewInstanceBinding(categories); m_commandData.Application.ActiveUIDocument.Document.ParameterBindings.Insert(roomSharedParamDef, binding); return false; } catch (Exception ex) { throw new Exception("Failed to create shared parameter: " + ex.Message); } }
I'm glad you got a solution. You might also find this post of mine helpful:
https://forums.autodesk.com/t5/revit-api-forum/sorting-parameters-in-the-family-editor/td-p/7676931
It is basically "A sharp macro that runs from within the family manager, and adds and sorts parameters from the shared parameters file."
Even though I made a sharp macro, the main block of code will run in Visual Studio.
Hi,
I have started to develop something similar. Is it possible to share your code here ?.
This will save me some amount of time. We can always exchange knowledge. I have started recently to do development for Revit. My target is to increas the interoperability in my workflows through managing my families using Excel sheets.
Best regards,
CadRobots
I've been struggling with a problem related to this for quite a while now. I manage to add a shared parameter to instances of elements I desire but I cannot utilise the .Set( command on it since I get an exception saying that the same parameter that I've just created is read-only. This comes down to a situation where I'm able to add a parameter and make it user modifiable but I can't modify it through the API which is absurd. Anyone's got an idea where might my mistake be?
I've just managed to avoid the read-only exception. Earlier I was trying to assign the value of the parameter to all wall objects in the project file. When I select some walls by hand and then run the command everything works. I wonder why some of the walls won't allow me to change the value from API. Does anyone know a workaround for that? There is always a risk that I might stumble upon one of those "evil walls" while selecting and then the code will fail.
Yes, you can easily add parameters from the user interface, but please notice that this is the Revit API (i.e. coding) forum.
Can't find what you're looking for? Ask the community or share your knowledge.