using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace 获得指定参数并修改参数
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
UIApplication uiApp = commandData.Application;
Application revitApp = commandData.Application.Application; //取得应用程序
//取得选择的元素
Selection sel = uiApp.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, "选择一个窗族");
Element elem = revitDoc.GetElement(ref1);
//获得族实例
FamilyInstance familyInstance = elem as FamilyInstance;
//遍历元素的参数
string strParamInfo = null;
////使用parameterId来找到参数
//Parameter param = familyInstance.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM);
//strParamInfo += param.Definition.Name + "value is:" + param.AsValueString() + "\n";
//使用名称来找到参数,因为revit2016为了避免得到重复的名字,只能用GetParameters得到一个集合,如果你只用唯一的名字,那只用取list[0]就可以了
IList
list = familyInstance.GetParameters("底高度");
Parameter param = list[0];
strParamInfo += param.Definition.Name + "value is:" + param.AsValueString() + "\n";
//修改参数的值
Transaction transaction = new Transaction(revitDoc);
//打开子程序,修改参数,然后关闭子程序
transaction.Start("改变族类型名称");
param.Set(10); //注意,这里单位是英寸,10英寸等于3048mm
transaction.Commit();
TaskDialog.Show("REVIT", strParamInfo);
return Result.Succeeded;
}
}
}