public bool AllowElement(Element e) { RebarHostData myRbHostData = RebarHostData.GetRebarHostData(e); if (myRbHostData.GetRebarsInHost().Count > 0) { return true; } return false; }
/// <summary> /// Do some check for the selection elements, includes geometry check. /// If the data doesn't meet our need, Exception will be thrown. /// </summary> private void Assert() { // Reserve all element ids for following iteration List <ElementId> selectedIds = new List <ElementId>(); foreach (Autodesk.Revit.DB.ElementId elemId in m_rvtUIDoc.Selection.GetElementIds()) { Autodesk.Revit.DB.Element elem = m_rvtUIDoc.Document.GetElement(elemId); selectedIds.Add(elem.Id); } if (selectedIds.Count == 0) { throw new Exception("Please select a concrete beam or column to create rebar."); } // // Construct filter to find expected rebar host // Structural type filters firstly LogicalOrFilter stFilter = new LogicalOrFilter( new ElementStructuralTypeFilter(StructuralType.Beam), new ElementStructuralTypeFilter(StructuralType.Column)); // + StructuralMaterial LogicalAndFilter hostFilter = new LogicalAndFilter(stFilter, new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete)); // Expected rebar host: it should be family instance FilteredElementCollector collector = new FilteredElementCollector(m_rvtUIDoc.Document, selectedIds); FamilyInstance rebarHost = collector.OfClass(typeof(FamilyInstance)).WherePasses(hostFilter).FirstElement() as FamilyInstance; // Make sure the selected beam or column is rectangular. try { m_geometryData = new GeometrySupport(rebarHost); } catch { throw new Exception("Please select a beam or column in rectangular shape."); } m_rebarHost = rebarHost; // Judge the rebar host is a valid host. RebarHostData rebarHostData = RebarHostData.GetRebarHostData(rebarHost); if (rebarHostData == null || !rebarHostData.IsValidHost()) { throw new Exception("The selected element is not a valid rebar host."); } // Make sure the selected beam or column doesn't contain any rebar. if (rebarHostData.GetRebarsInHost().Count > 0) { throw new Exception("Please select a beam or a column which doesn't contain any rebar."); } }
internal static ICollection<ElementId> GetElementIdsInLayer(Document doc, Element host, bool bottomLayer) { RebarHostData hostData = RebarHostData.GetRebarHostData(host); ICollection<ElementId> rebarsInHost = hostData.GetRebarsInHost().Select(r => r.Id).ToList(); BoundingBoxXYZ box = host.get_BoundingBox(null); double midZ = 0.5 * (box.Max.Z + box.Min.Z); Outline outline; if (bottomLayer) { outline = new Outline(box.Min, new XYZ(box.Max.X, box.Max.Y, midZ)); } else { outline = new Outline(new XYZ(box.Min.X, box.Min.Y, midZ), box.Max); } BoundingBoxIsInsideFilter filter = new BoundingBoxIsInsideFilter(outline); FilteredElementCollector collector = new FilteredElementCollector(doc, rebarsInHost); return collector.WherePasses(filter).ToElementIds(); }
public void makeGroupRebarByHost() { try { UIDocument uiDoc = this.ActiveUIDocument; Document doc = uiDoc.Document; string nameGroup = ""; string namePartition = ""; int rebarCount = 1; // Show form using (SettingDialog myInputFormSetting = new SettingDialog()) { myInputFormSetting.ShowDialog(); //if the user hits cancel just drop out of macro if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return; } { //else do all this :) myInputFormSetting.Close(); } if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.OK) { nameGroup = myInputFormSetting.GroupName_Tb1.Text; namePartition = myInputFormSetting.Partition1_Tb.Text; rebarCount = Convert.ToInt32(myInputFormSetting.RebarCount_Tb.Text); myInputFormSetting.Close(); } } List <Reference> myListRef = uiDoc.Selection.PickObjects(ObjectType.Element, new FilterByNumberRebarHostIn()).ToList(); foreach (Reference myRef in myListRef) { Element myHost = doc.GetElement(myRef); RebarHostData myRbHostData = RebarHostData.GetRebarHostData(myHost); List <Rebar> myListRebar = myRbHostData.GetRebarsInHost() as List <Rebar>; using (Transaction trans_1 = new Transaction(doc, "Change parameter Rebar")) { trans_1.Start(); //Set parameter foreach (Rebar myRebar in myListRebar) { //Partition Parameter partitionPara = myRebar.LookupParameter("Partition"); if (partitionPara == null) { TaskDialog.Show("Error!!", "Has no parpation"); } else { partitionPara.Set(namePartition); } //Partition Parameter rebarCountPara = myRebar.LookupParameter("COUNT_REBAR"); if (rebarCountPara == null) { TaskDialog.Show("Error!!", "Has no parpation"); } else { rebarCountPara.Set(rebarCount); } } trans_1.Commit(); } //Set parameter List <ElementId> myListElementId = new List <ElementId>(); foreach (Rebar myRebar in myListRebar) { myListElementId.Add(myRebar.Id); } using (Transaction trans = new Transaction(doc, "Make group Rebar")) { trans.Start(); if (myListElementId.Count > 0) { Group myGroupRebar = doc.Create.NewGroup(myListElementId); if (nameGroup != "") { myGroupRebar.GroupType.Name = nameGroup; } } else { TaskDialog.Show("Warning!", "No rebar was hosted by this element, so no any group was created!"); } trans.Commit(); } } } catch (Exception) { TaskDialog.Show("Error!!!", "Co loi xay ra, co the tat ca rebar da co trong 1 group"); throw; } }
public void makeGroupRebarByHost(UIDocument uiDoc) { try { Document doc = uiDoc.Document; string nameGroup = ""; string paraName_1 = ""; string paraName_2 = ""; string paraValue_1 = ""; int paraValue_2 = 1; string warning1 = ""; string warning2 = ""; // Show form using (SettingDialog myInputFormSetting = new SettingDialog()) { myInputFormSetting.ShowDialog(); //if the user hits cancel just drop out of macro if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return; } { //else do all this :) myInputFormSetting.Close(); } if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.OK) { nameGroup = myInputFormSetting.GroupName_Tb1.Text; paraName_1 = myInputFormSetting.Para_1Tb.Text; paraName_2 = myInputFormSetting.Para_2Tb.Text; paraValue_1 = myInputFormSetting.Value1_Tb.Text; paraValue_2 = Convert.ToInt32(myInputFormSetting.Value2_Tb.Text); myInputFormSetting.Close(); } } //List<Reference> myListRef = uiDoc.Selection.PickObjects(ObjectType.Element, new FilterByNumberRebarHostIn()).ToList(); Reference myRef = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByNumberRebarHostIn()); Element myHost = doc.GetElement(myRef); RebarHostData myRbHostData = RebarHostData.GetRebarHostData(myHost); List <Rebar> myListRebar = myRbHostData.GetRebarsInHost() as List <Rebar>; using (Transaction trans_1 = new Transaction(doc, "Change parameter Rebar")) { trans_1.Start(); //Set parameter foreach (Rebar myRebar in myListRebar) { //Partition Parameter Para1 = myRebar.LookupParameter(paraName_1); if (Para1 == null) { warning1 = string.Format("Rebar {0} has no paramater name: {1}", myRebar.Id.ToString(), paraName_1); } else { Para1.Set(paraValue_1); } //Partition Parameter Para2 = myRebar.LookupParameter(paraName_2); if (Para2 == null) { warning2 = string.Format("Rebar {0} has no paramater name: {1}", myRebar.Id.ToString(), paraName_2); } else { Para2.Set(paraValue_2); } } trans_1.Commit(); } if (warning1 != warning2) { TaskDialog.Show("Waring", warning1 + "\n" + warning2); } //Set parameter List <ElementId> myListElementId = new List <ElementId>(); foreach (Rebar myRebar in myListRebar) { myListElementId.Add(myRebar.Id); } using (Transaction trans = new Transaction(doc, "Make group Rebar")) { trans.Start(); if (myListElementId.Count > 0) { Group myGroupRebar = doc.Create.NewGroup(myListElementId); if (nameGroup != "") { myGroupRebar.GroupType.Name = nameGroup; } } else { TaskDialog.Show("Warning!", "No rebar was hosted by this element, so no any group was created!"); } trans.Commit(); } } catch (Exception) { TaskDialog.Show("Error!!!", "Co loi xay ra, co the tat ca rebar da co trong 1 group"); throw; } }
//Get all rebar in section //Trả về 1 danh sách gồm 2 danh sách, danh sách đầu tiên chứa Id của cac rebar section trên dầm (thép chủ trên), // danh sách thứ 2 trả về Id của các rebar phía dưới dầm(thép chủ dưới); public List <List <Rebar> > myListRebarIdSorted() { UIDocument uiDoc = this.ActiveUIDocument; Document doc = uiDoc.Document; View myView = doc.ActiveView; //Pick beam to get min max bound Reference myRefBeam = uiDoc.Selection.PickObject(ObjectType.Element, "Pick host beam..."); Element myBeam = doc.GetElement(myRefBeam); //Boundary of beam BoundingBoxXYZ myBeam_BB = myBeam.get_BoundingBox(myView); XYZ minPointBeam = myBeam_BB.Min; XYZ maxPointBeam = myBeam_BB.Max; XYZ centerPointBeam = (minPointBeam + maxPointBeam) / 2; //Retrive all rebar of beam RebarHostData myRbHostData = RebarHostData.GetRebarHostData(myBeam); List <Rebar> myListRebar = myRbHostData.GetRebarsInHost() as List <Rebar>; //Inter every rebar in ListRebar make section rebar in view List <Rebar> myListRebarInSection = new List <Rebar>(); foreach (Rebar myRebarOfBeam in myListRebar) { if (myRebarOfBeam.IsRebarInSection(myView) && myRebarOfBeam.NumberOfBarPositions > 1) { myListRebarInSection.Add(myRebarOfBeam); } } List <Rebar> listBottomRebar = new List <Rebar>(); List <Rebar> listTopRebar = new List <Rebar>(); if (myListRebarInSection.Count < 1) { TaskDialog.Show("abc", "Has no rebarinsection in view belong to Host picked"); return(null); } else { //Trong mỗi rebar in section, so sánh vị trí tương đối của rebar với trục giữa dầm(Z) foreach (Rebar rebarSet in myListRebarInSection) { // Lấy bounding box của mỗi rebar //Get bouding box of rebarSet BoundingBoxXYZ myRebar_BB = rebarSet.get_BoundingBox(myView); XYZ minPointRebar = myRebar_BB.Min; XYZ maxPointRebar = myRebar_BB.Max; XYZ centerPointRebar = (minPointRebar + maxPointRebar) / 2; if (centerPointRebar.Z <= centerPointBeam.Z) { //myPickPoint = new XYZ(minPointBeam.X, minPointBeam.Y, minPointBeam.Z + (-1*deltaZ*factorDelta)); listBottomRebar.Add(rebarSet); } else { //myPickPoint = new XYZ(maxPointBeam.X, maxPointBeam.Y, maxPointBeam.Z + (deltaZ*factorDelta)); listTopRebar.Add(rebarSet); } } } List <List <Rebar> > rebarListList = new List <List <Rebar> >() { listBottomRebar, listTopRebar }; TaskDialog.Show("abc", "has: " + rebarListList[0].Count() + "; " + rebarListList[1].Count); return(rebarListList); }