We talked about creating Shared Parameter before. Now let’s see how SharedParameter Creator of RevitAddinWizard can assist us to hit the same target. The SharedParameter 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 SharedParameter Creator window will show up:
If the settings as above are accepted and the OK button is clicked, the following SharedParameter Creator code will be created and added into the chosen class:
public static List<T> RawConvertSetToList<T>(IEnumerable set)
{
List<T> list = (from T p in set select p).ToList<T>();
return list;
}
public static Definition RawCreateSharedParameter(RvtApplication app, string name, string group, ParameterType type, bool visible)
{
DefinitionFile defFile = app.OpenSharedParameterFile();
if (defFile == null) throw new Exception("No SharedParameter File!");
DefinitionGroup dg = RawConvertSetToList<DefinitionGroup>(defFile.Groups).FirstOrDefault(g => g.Name == group);
if (dg == null) dg = defFile.Groups.Create(group);
Definition def = RawConvertSetToList<Definition>(dg.Definitions).FirstOrDefault(d => d.Name == name);
if (def != null) return def; //dg.Definitions.Erase(def); //ReadOnly Exception!!
def = dg.Definitions.Create(name, type, visible);
return def;
}
In terms of how to use these methods, please refer to previous posts for ideas and code examples.
SharedParameter Creator of RevitAddinWizard can create all these in a second.
Recent Comments