revit添加族参数

 

打开一个族文件,并为族文件添加参数

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
UIApplication uiApp = commandData.Application;
Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
Document newDoc = app.OpenDocumentFile(@"F:\test.rfa");
if (newDoc != null)
{
using (Transaction trans = new Transaction(newDoc))
{
trans.Start("Add Parameter");
FamilyManager flyMgr = newDoc.FamilyManager;
string paraName = "NewParam4";
BuiltInParameterGroup paraGroup = BuiltInParameterGroup.PG_TEXT;
ParameterType paraType = ParameterType.Text;

flyMgr.AddParameter(paraName, paraGroup, paraType, false);
trans.Commit();
}
}
SaveOptions saveOpt = new SaveOptions();
saveOpt.Compact = true;

//newDoc.Save(saveOpt);
newDoc.Close();
return Result.Succeeded;
}
catch (Exception exception)
{
message = exception.Message;
return Result.Failed;
}
}

posted @ 2020-04-07 15:23  廖先生  阅读(1024)  评论(0编辑  收藏  举报