视频连接http://v.bimcc.com/course/35/tasks
一、系统族的创建
1.各自类下面的相应方法
以墙为例
namespace RevitDevelopClass
{
[Transaction(TransactionMode.Manual)]
class Class6 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
XYZ pnt1 = uidoc.Selection.PickPoint(ObjectSnapTypes.None, "请选择墙的起点");
XYZ pnt2 = uidoc.Selection.PickPoint(ObjectSnapTypes.None, "请选择墙的终点");
Line li = Line.CreateBound(pnt1, pnt2);
ElementId levelId = new ElementId(2607);
//视频中用的是底部约束value的id 311,这里用的是parameters中的顶部约束value的id(因为本模型样例中没有底部约束属性)
//id会随着模型样例的改变而改变,所以一般用过滤器选择familysymbol或系统族,而不是这样简单粗暴的创建。
using (Transaction trans = new Transaction(doc, "创建墙"))
{
trans.Start();
Wall.Create(doc, li, levelId, false);
trans.Commit();
}
return Result.Succeeded;
}
}
}
2.Document下面的相应方法
二、可载入族的创建
Document.NewFamilyInstance
以柱子为例
namespace RevitDevelopClass
{
[Transaction(TransactionMode.Manual)]
class Class6 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
XYZ pnt1 = uidoc.Selection.PickPoint(ObjectSnapTypes.None, "请选择墙的起点");
//XYZ pnt2 = uidoc.Selection.PickPoint(ObjectSnapTypes.None, "请选择墙的终点");
//Line li = Line.CreateBound(pnt1, pnt2);
ElementId levelId = new ElementId(2607);
Level lev = doc.GetElement(levelId) as Level;
ElementId columSymbol = new ElementId(263331);//这里是选择了柱的familysymbol的Id
FamilySymbol fs = doc.GetElement(columSymbol) as FamilySymbol;
using (Transaction trans = new Transaction(doc, "创建墙"))
{
trans.Start();
//Wall.Create(doc, li, levelId, false);
doc.Create.NewFamilyInstance(pnt1,fs,lev,Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
trans.Commit();
}
return Result.Succeeded;
}
}
}
三、删除操作。
namespace RevitDevelopClass
{
[Transaction(TransactionMode.Manual)]
class Class7 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Reference refer = uidoc.Selection.PickObject(ObjectType.Element);
Element ele = doc.GetElement(refer);
using (Transaction trans = new Transaction(doc, "删除墙"))
{
trans.Start();
doc.Delete(ele.Id);
trans.Commit();
}
return Result.Succeeded;
}
}
}