一、将楼板转为组成部分(零件)PartUtils.CreateParts()
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Application revitapp = uiApp.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
Selection sel=uiDoc.Selection;
Reference refer = null;
try
{
refer = uiDoc.Selection.PickObject(ObjectType.Element, new floor());
}
catch (Exception)
{
throw;
}
Element floor = doc.GetElement(refer) as Element;
Transaction ts = new Transaction(doc,"创建零件");
ts.Start();
List<ElementId> list = new List<ElementId>();
if (floor != null)
{
list.Add(floor.Id);
//将当前楼板转换为零件
PartUtils.CreateParts(floor.Document, list);
}
ts.Commit();
二、创建分割PartUtils.DivideParts()
List<ElementId> idList = PartUtils.GetAssociatedParts(floor.Document, floor.Id, true, true).ToList();
PartUtils.DivideParts(floor.Document, idList, new List<ElementId>(), new List<Curve>() { line1, line2, line3, line4 }, sketchPlane.Id);
三、判断
if (PartUtils.HasAssociatedParts(floor.Document, floor.Id))
{
TaskDialog.Show("提示", "有关联零件");
}
else
{
TaskDialog.Show("提示", "没有关联零件");
}
if (PartUtils.ArePartsValidForDivide(doc, new List<ElementId>() { elemPart.Id }))
{
TaskDialog.Show("提示", "楼板可分割");
}
else
{
TaskDialog.Show("提示", "楼板不可分割");
}