1.系统族的创建
系统族的创建方法放在各自的类下或者Document下面。
比如墙的创建:
Wall.Create Method (Document, IList(Curve), ElementId, ElementId, Boolean)
public static Wall Create(
Document document,
IList profile,
ElementId wallTypeId,
ElementId levelId,
bool structural
)
测试代码:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
XYZ point1 = uidoc.Selection.PickPoint(ObjectSnapTypes.None,"请选择墙的起始点");
XYZ point2 = uidoc.Selection.PickPoint(ObjectSnapTypes.None,"请选择墙的终点");
Line li = Line.CreateBound(point1, point2);
ElementId id = new ElementId(355);
using (Transaction trans = new Transaction(doc, "创建墙"))
{
trans.Start();
Wall.Create(doc, li,id, false);
trans.Commit();
}
return Result.Succeeded;
}
2.可载入族的创建
可载入族的创建都在Document.NewFamilyInstance ,其实包含若干重载。
另外NewFamilyInstances2是批量创建。
创建柱子:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
XYZ point = uidoc.Selection.PickPoint(ObjectSnapTypes.None, "柱子的位置");
ElementId levelId = new ElementId(355);
Level lev = doc.GetElement(levelId) as Level;
ElementId columSymbol = new ElementId(263331);
FamilySymbol fs = doc.GetElement(columSymbol) as FamilySymbol;
using (Transaction trans = new Transaction(doc, "创建柱子"))
{
trans.Start();
doc.Create.NewFamilyInstance(point, fs, lev, StructuralType.NonStructural);
trans.Commit();
}
return Result.Succeeded;
}
3.删除
删除操作都是一样的。
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;
}