Revit API共享参数的使用
共享参数相当于为某一类别元素增加一个额外的参数。
需要读取值的时候,就当作普通参数值来读。
这里仅仅把读取共享参数文件,然后绑定到某一类别的代码贴出来。
API创建组,创建参数具体代码详见源码。
更多示例源码:http://revit.5d6d.com/thread-1305-1-1.html
需要读取值的时候,就当作普通参数值来读。
这里仅仅把读取共享参数文件,然后绑定到某一类别的代码贴出来。
API创建组,创建参数具体代码详见源码。
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Command4 : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
Transaction ts = new Transaction(uiDoc.Document, "LevelDuct");
ts.Start();
//打开文件
cmdData.Application.Application.SharedParametersFilename = @"C:\Users\HongYe\Desktop\RevitParameters.txt";
DefinitionFile sharedParametersFile = cmdData.Application.Application.OpenSharedParameterFile();
//绑定到类别
CategorySet categories = null;
categories = cmdData.Application.Application.Create.NewCategorySet();
Category wallCategory = null;
//wallCategory = commandData.Application.ActiveUIDocument.Document.Settings.Categories.get_Item("Walls");
wallCategory = cmdData.Application.ActiveUIDocument.Document.Settings.Categories.get_Item("墙");
categories.Insert(wallCategory);
InstanceBinding instanceBinding = null;
instanceBinding = cmdData.Application.Application.Create.NewInstanceBinding(categories);
//参数
//参数分组
Autodesk.Revit.DB.DefinitionGroup sharedParameterGroup = null;
sharedParameterGroup = sharedParametersFile.Groups.get_Item("RevitParameters");
if (null == sharedParameterGroup)
{
sharedParameterGroup = sharedParametersFile.Groups.Create("RevitParameters");
}
//参数值
Definition sharedParameterDefinition = null;
sharedParameterDefinition = sharedParameterGroup.Definitions.get_Item("APIParameter");
if (sharedParameterDefinition == null)
{
sharedParameterDefinition = sharedParameterGroup.Definitions.Create("APIParameter", ParameterType.Text, true);
}
cmdData.Application.ActiveUIDocument.Document.ParameterBindings.Insert(sharedParameterDefinition, instanceBinding);
ts.Commit();
return Result.Succeeded;
}
}
[Regeneration(RegenerationOption.Manual)]
public class Command4 : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
Transaction ts = new Transaction(uiDoc.Document, "LevelDuct");
ts.Start();
//打开文件
cmdData.Application.Application.SharedParametersFilename = @"C:\Users\HongYe\Desktop\RevitParameters.txt";
DefinitionFile sharedParametersFile = cmdData.Application.Application.OpenSharedParameterFile();
//绑定到类别
CategorySet categories = null;
categories = cmdData.Application.Application.Create.NewCategorySet();
Category wallCategory = null;
//wallCategory = commandData.Application.ActiveUIDocument.Document.Settings.Categories.get_Item("Walls");
wallCategory = cmdData.Application.ActiveUIDocument.Document.Settings.Categories.get_Item("墙");
categories.Insert(wallCategory);
InstanceBinding instanceBinding = null;
instanceBinding = cmdData.Application.Application.Create.NewInstanceBinding(categories);
//参数
//参数分组
Autodesk.Revit.DB.DefinitionGroup sharedParameterGroup = null;
sharedParameterGroup = sharedParametersFile.Groups.get_Item("RevitParameters");
if (null == sharedParameterGroup)
{
sharedParameterGroup = sharedParametersFile.Groups.Create("RevitParameters");
}
//参数值
Definition sharedParameterDefinition = null;
sharedParameterDefinition = sharedParameterGroup.Definitions.get_Item("APIParameter");
if (sharedParameterDefinition == null)
{
sharedParameterDefinition = sharedParameterGroup.Definitions.Create("APIParameter", ParameterType.Text, true);
}
cmdData.Application.ActiveUIDocument.Document.ParameterBindings.Insert(sharedParameterDefinition, instanceBinding);
ts.Commit();
return Result.Succeeded;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。