We talked about attaching a Shared Parameter to some Revit categories. Now let’s see how SharedParameter Attacher of RevitAddinWizard can assist us to achieve the same goal. The SharedParameter Attacher can be found either from the Revit Addin Coder sub-menu under the Tools or from the Revit Addin Coder toolbar.
When the menu item or button is clicked, the SharedParameter Attacher window will show up:
If the OK button is clicked, the following SharedParameter Attacher will be created and added into the chosen class:
public static void RawAttachSharedParameter(RvtApplication app, string name, CategorySet cats, BuiltInParameterGroup group, bool inst)
{
DefinitionFile defFile = app.OpenSharedParameterFile();
if (defFile == null) throw new Exception("No SharedParameter File!");
var v = (from DefinitionGroup dg in defFile.Groups
from ExternalDefinition d in dg.Definitions
where d.Name == name
select d);
if (v == null || v.Count() < 1) throw new Exception("Invalid Name Input!");
ExternalDefinition def = v.First();
Autodesk.Revit.DB.Binding binding = app.Create.NewTypeBinding(cats);
if(inst) binding = app.Create.NewInstanceBinding(cats);
BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
map.Insert(def, binding, group);
}
In terms of how to use these methods, please refer to previous posts for ideas and code examples.
SharedParameter Attacher of RevitAddinWizard can create all these in a second.
Recent Comments