public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; List <ElementId> hostElemIdList = uidoc.Selection.GetElementIds().ToList(); List <Element> dsList = BasisCode.FilterElementList <DirectShape>(doc); List <ElementId> delIds = new List <ElementId>(); foreach (Element ds in dsList) { int id = ds.LookupParameter("HostElemID").AsInteger(); if (hostElemIdList.Contains(new ElementId(id))) { delIds.Add(ds.Id); } } using (Transaction trans = new Transaction(doc, "删除模板")) { trans.Start(); doc.Delete(delIds); trans.Commit(); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; List <Level> levList = BasisCode.GetLevList(doc); //所有需要配模板的墙的集合 List <List <Wall> > wallListList = new List <List <Wall> >(); //所有需要配模板的梁的集合 List <List <FamilyInstance> > beamListList = new List <List <FamilyInstance> >(); //所有需要配模板的柱的集合 List <List <FamilyInstance> > colListList = new List <List <FamilyInstance> >(); //所有需要配模板的板的集合 List <List <Floor> > flListList = new List <List <Floor> >(); using (TransactionGroup transGroup = new TransactionGroup(doc, "模型预处理")) { transGroup.Start(); for (int i = 0; i < levList.Count; i++) { Level lev = levList[i]; //需要配模的墙实例 List <Wall> wallList = bc.FilterElementList <Wall>(doc, BuiltInCategory.OST_Walls).ConvertAll(m => m as Wall); //需要配模的梁实例 List <FamilyInstance> beamList = bc.FilterElementList <FamilyInstance>(doc, BuiltInCategory.OST_StructuralFraming, lev) .ConvertAll(m => m as FamilyInstance); //需要配模的柱实例 List <FamilyInstance> colList = bc.FilterElementList <FamilyInstance>(doc, BuiltInCategory.OST_StructuralColumns, lev) .ConvertAll(m => m as FamilyInstance); //标高以下的柱子 List <FamilyInstance> nextColList = new List <FamilyInstance>(); if (i > 0) { nextColList = bc.FilterElementList <FamilyInstance>(doc, BuiltInCategory.OST_StructuralColumns, levList[i - 1]) .ConvertAll(m => m as FamilyInstance); } //参与比较的柱子 List <FamilyInstance> compareColList = null; if (nextColList.Count == 0) { compareColList = colList; } else { compareColList = nextColList; } //需要配模的楼板实例 List <Floor> flList = bc.FilterElementList <Floor>(doc, BuiltInCategory.OST_Floors, lev).ConvertAll(m => m as Floor); ////处理梁柱关系 //JoinBeamAndColumns(ref beamList, compareColList, doc); //List<FamilyInstance> beCutBeam_List = bc.JoinBeamToBeam(beamList, doc); ////处理板和梁柱的关系 //FloorJoinBeamAndColumn(levList, flList, doc); //处理墙和柱子的连接 WallJoinColumns(doc, wallList); } transGroup.Assimilate(); } return(Result.Succeeded); }