We talked about creating Project Parameter before. Now let’s see how ProjectParameter Creator of RevitAddinWizard can assist us to hit the same target. The ProjectParameter Creator can be found from either 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 ProjectParameter Creator window will show up:
If the settings as above are accepted and the OK button is clicked, the following ProjectParameter Creator code will be created and added into the chosen class:
public static void RawCreateProjectParameterFromExistingSharedParameter(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);
}
public static void RawCreateProjectParameterFromNewSharedParameter(RvtApplication app, string defGroup, string name, ParameterType type, bool visible, CategorySet cats, BuiltInParameterGroup paramGroup, bool inst)
{
DefinitionFile defFile = app.OpenSharedParameterFile();
if (defFile == null) throw new Exception("No SharedParameter File!");
ExternalDefinition def = app.OpenSharedParameterFile().Groups.Create(defGroup).Definitions.Create(name, type, visible) as ExternalDefinition;
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, paramGroup);
}
public static void RawCreateProjectParameter(RvtApplication app, string name, ParameterType type, bool visible, CategorySet cats, BuiltInParameterGroup group, bool inst)
{
//InternalDefinition def = new InternalDefinition();
//Definition def = new Definition();
string oriFile = app.SharedParametersFilename;
string tempFile = Path.GetTempFileName() + ".txt";
using (File.Create(tempFile)) { }
app.SharedParametersFilename = tempFile;
ExternalDefinition def = app.OpenSharedParameterFile().Groups.Create("TemporaryDefintionGroup").Definitions.Create(name, type, visible) as ExternalDefinition;
app.SharedParametersFilename = oriFile;
File.Delete(tempFile);
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.
ProjectParameter Creator of RevitAddinWizard can create all these in a second.
Recent Comments