Revit API判断是不是柱族模板
OwnerFamily即族模板。
获取类别的方法:
Document.Settings.Categories.get_Item(BuiltInCategory.OST_Columns);url:http://www.cnblogs.com/greatverve/p/ValidateDocument.html
获取类别的方法:
Document.Settings.Categories.get_Item(BuiltInCategory.OST_Columns);
//判断是不是柱族模板
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdCheckFamily : IExternalCommand
{
bool ValidateDocument(Document rvtDoc)
{
if (!rvtDoc.IsFamilyDocument)//判断是不是族文档
{
TaskDialog.Show("Family API", "This command works only in the family editor.");
return false;
}
Family ownerFamily = rvtDoc.OwnerFamily;
if (ownerFamily == null)//判断是否使用了族模板
{
TaskDialog.Show("Family API", "This document does not have Owner Family.");
return false;
}
//取得族类别的方法
Category catColumn = rvtDoc.Settings.Categories.get_Item(BuiltInCategory.OST_Columns);
if (!ownerFamily.FamilyCategory.Id.Equals(catColumn.Id))
{
TaskDialog.Show("Family API", "The category of this document does not match the context of this commands. Please open Metric Column.rft");
return false;
}
return true;
}
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Selection sel = app.ActiveUIDocument.Selection;
ValidateDocument(doc);
return Result.Succeeded;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdCheckFamily : IExternalCommand
{
bool ValidateDocument(Document rvtDoc)
{
if (!rvtDoc.IsFamilyDocument)//判断是不是族文档
{
TaskDialog.Show("Family API", "This command works only in the family editor.");
return false;
}
Family ownerFamily = rvtDoc.OwnerFamily;
if (ownerFamily == null)//判断是否使用了族模板
{
TaskDialog.Show("Family API", "This document does not have Owner Family.");
return false;
}
//取得族类别的方法
Category catColumn = rvtDoc.Settings.Categories.get_Item(BuiltInCategory.OST_Columns);
if (!ownerFamily.FamilyCategory.Id.Equals(catColumn.Id))
{
TaskDialog.Show("Family API", "The category of this document does not match the context of this commands. Please open Metric Column.rft");
return false;
}
return true;
}
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Selection sel = app.ActiveUIDocument.Selection;
ValidateDocument(doc);
return Result.Succeeded;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。