public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; ISelectionFilter beamFilter = new CategorySelectionFilter("Walls"); IList <Reference> refs = uidoc.Selection.PickObjects(ObjectType.Element, beamFilter, "Select some walls"); uidoc.Selection.SetElementIds(refs.Select(x => doc.GetElement(x).Id).ToList()); return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; View activeView = doc.ActiveView; ISelectionFilter beamFilter = new CategorySelectionFilter("Structural Framing"); IList <Reference> refs = uidoc.Selection.PickObjects(ObjectType.Element, beamFilter, "Select some beams"); int count = 0; int errors = 0; using (var form = new FormAddOpening(doc)) { /* * string catName = form.inputCategoryName; * * Dictionary<string, FamilySymbol> allCategories = Helpers.SelectFamilies(doc, catName); * * * * foreach (string el in allCategories.Keys) * { * form.familyName.Add(el); * } */ form.ShowDialog(); if (form.DialogResult == winforms.DialogResult.Cancel) { return(Result.Cancelled); } string[] distance = form.distances.Split(' '); using (Transaction t = new Transaction(doc, "Place Opening")) { t.Start(); foreach (string s in distance) { foreach (Reference r in refs) { try { Helpers.PlaceOpening(doc, r, Int16.Parse(s), form.choosenFamily, form.formPosition, form.formVoidWidth, form.formVoidHeight); count += 1; } catch (Exception ex) { errors += 1; TaskDialog.Show("Error", "Uh-oh something went wrong\n" + ex.Message); } } } t.Commit(); } //close transaction } //close form return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; ISelectionFilter beamFilter = new CategorySelectionFilter("Structural Framing"); IList <Reference> refsBeams = uidoc.Selection.PickObjects(ObjectType.Element, beamFilter, "Select Beams"); using (var form = new FormJoin()) { form.ShowDialog(); if (form.DialogResult == winForm.DialogResult.Cancel) { return(Result.Cancelled); } using (Transaction t = new Transaction(doc, "Edit Beam Join")) { t.Start(); foreach (Reference r in refsBeams) { FamilyInstance ele = doc.GetElement(r) as FamilyInstance; if (form.allowStartValue) { StructuralFramingUtils.AllowJoinAtEnd(ele, 0); } if (form.allowEndValue) { StructuralFramingUtils.AllowJoinAtEnd(ele, 1); } if (form.disallowStartValue) { StructuralFramingUtils.DisallowJoinAtEnd(ele, 0); } if (form.disallowEndValue) { StructuralFramingUtils.DisallowJoinAtEnd(ele, 1); } if (form.miterStart) { ele.ExtensionUtility.set_Extended(0, true); } if (form.miterEnd) { ele.ExtensionUtility.set_Extended(1, true); } } t.Commit(); }//close using return(Result.Succeeded); }//close form using }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; ISelectionFilter beamFilter = new CategorySelectionFilter("Structural Framing"); ISelectionFilter lineFilter = new LineSelectionFilter(); IList <Reference> refsBeams = uidoc.Selection.PickObjects(ObjectType.Element, beamFilter, "Select Beams"); IList <Reference> refsLines = uidoc.Selection.PickObjects(ObjectType.Element, lineFilter, "Select Lines"); int countRectangular = 0; int countCircular = 0; string errors = ""; using (Transaction t = new Transaction(doc, "Place Opening")) { t.Start(); foreach (Reference beamRef in refsBeams) { try { // List<double> distances = PlaceOpeningIntersect.IntersectionPoint(doc, beamRef, refsLines); // dictionary of distances from start, penos [width, depth] Dictionary <double, int[]> penoSizes = VoidByLineHelpers.IntersectionPoint(doc, beamRef, refsLines); // remove beams without openings if (penoSizes.Keys.Count > 0) { foreach (double d in penoSizes.Keys) { if (penoSizes[d][0] > 0) { Helpers.PlaceOpening(doc, beamRef, Convert.ToInt16(d), "Web_Peno_R", "start", penoSizes[d][0], penoSizes[d][1]); countRectangular += 1; } else { Helpers.PlaceOpening(doc, beamRef, Convert.ToInt16(d), "Web_Peno_C", "start", penoSizes[d][0], penoSizes[d][1]); countCircular += 1; } } } else if (penoSizes.Count == 0) { errors += beamRef.ElementId + Environment.NewLine; } } catch { TaskDialog.Show("Error", "Uh-oh something went wrong"); } } t.Commit(); }//close transaction if (errors == "") { TaskDialog.Show("result", string.Format("{0} rectangular voids created \n {1} circular voids created", countRectangular, countCircular)); } else { TaskDialog.Show("result", string.Format("{0} rectangular voids created \n{1} circular voids created \n" + "Intersection not found between the lines and the beams Id:\n{2}" + "Are they placed at the same level?", countRectangular, countCircular, errors)); } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; ISelectionFilter beamFilter = new CategorySelectionFilter("Structural Framing"); ISelectionFilter refPlaneFilter = new RefPlaneFilter(); IList <Reference> refsBeams = uidoc.Selection.PickObjects(ObjectType.Element, beamFilter, "Select Beams"); IList <Reference> refsLines = uidoc.Selection.PickObjects(ObjectType.Element, refPlaneFilter, "Select Reference Planes"); Debug.WriteLine($"{refsBeams.Count} beams selected"); Debug.WriteLine("Reference plances selected"); int countRectangular = 0; int countCircular = 0; string errors = ""; //revit family name string webPenoRectangular = "Web_Peno_Rectangular"; string webPenoCircular = "Web_Peno_Circular"; List <Dimension> lockDimensions = new List <Dimension>(); using (Transaction t = new Transaction(doc, "Place Dummy Opening")) { t.Start(); foreach (Reference beamRef in refsBeams) { FamilyInstance tempPeno = Helpers.PlaceOpening(doc, beamRef, 0, webPenoRectangular, "mid", 100, 100); doc.Delete(tempPeno.Id); } t.Commit(); } using (Transaction t = new Transaction(doc, "Place Opening")) { t.Start(); foreach (Reference beamRef in refsBeams) { //List<double> distances = PlaceOpeningIntersect.IntersectionPoint(doc, beamRef, refsLines); // dictionary of distances from start, penos [width, depth] Debug.WriteLine($"***Beam reference {beamRef.ElementId}***"); List <Tuple <double, int[], ReferencePlane> > penoSizes = VoidByLineHelpers.IntersectionLinePlane(doc, beamRef, refsLines); foreach (var item in penoSizes) { try { // remove beams without openings if (item.Item1 > 0) { double d = item.Item1; Debug.WriteLine($"Distance from start: {d.ToString()}"); Debug.WriteLine($"Peno sizes: {item.Item2[0]}x{item.Item2[1]}"); Debug.WriteLine($"Reference plane Id: {item.Item3.Id}"); FamilyInstance openingInstance = null; if (item.Item2[0] > 0) { openingInstance = Helpers.PlaceOpening(doc, beamRef, Convert.ToInt16(d), webPenoRectangular, "start", item.Item2[0], item.Item2[1]); Debug.WriteLine($"Opening Instance id: {openingInstance.Id}"); countRectangular += 1; } else { openingInstance = Helpers.PlaceOpening(doc, beamRef, Convert.ToInt16(d), webPenoCircular, "start", item.Item2[0], item.Item2[1]); countCircular += 1; } //if (VoidByLineHelpers.IsParallel(openingInstance, item.Item3)) //{ // VoidByLineHelpers.DrawDimension(doc, item.Item3, openingInstance, 0); //} FamilyInstance fi = openingInstance; ReferencePlane rp = item.Item3; Element ln = doc.GetElement(beamRef); LocationCurve lc = ln.Location as LocationCurve; #if REVIT2017 #endif #if REVIT2019 IList <Reference> fir1 = fi.GetReferences(FamilyInstanceReferenceType.WeakReference); ReferenceArray rea = new ReferenceArray(); rea.Append(fir1.First()); rea.Append(rp.GetReference()); Line lnie = lc.Curve as Line; //Dimension align = doc.Create.NewAlignment(doc.ActiveView, rp.GetReference(), fir1.First()); lockDimensions.Add(doc.Create.NewDimension(doc.ActiveView, lnie, rea)); //dim.IsLocked = true; #endif } else if (penoSizes.Count == 0) { errors += beamRef.ElementId + Environment.NewLine; } } catch { TaskDialog.Show("Error", "Uh-oh something went wrong"); } } } t.Commit(); }//close transaction using (Transaction t = new Transaction(doc, "Lock dimensions")) { t.Start(); if (lockDimensions.Count > 0) { foreach (Dimension d in lockDimensions) { d.IsLocked = true; } } t.Commit(); } if (errors == "") { TaskDialog.Show("result", string.Format("{0} rectangular voids created \n {1} circular voids created", countRectangular, countCircular)); } else { TaskDialog.Show("result", string.Format("{0} rectangular voids created \n{1} circular voids created \n" + "Intersection not found between the lines and the beams Id:\n{2}" + "Is the Subcategory parameter empty? Are they placed at the same level?", countRectangular, countCircular, errors)); } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; View activeView = doc.ActiveView; ISelectionFilter openingFilter = new CategorySelectionFilter("Structural Connections"); ISelectionFilter refPlanesFilter = new CategorySelectionFilter("Reference Planes"); IList <Reference> openings = uidoc.Selection.PickObjects(ObjectType.Element, openingFilter, "Select openings"); List <FamilyInstance> fa = new List <FamilyInstance>(); foreach (Reference refe in openings) { FamilyInstance fi = doc.GetElement(refe) as FamilyInstance; fa.Add(fi); } var grouped = fa.GroupBy(x => x.Host.Id); double offset = 315 / 304.8; //Reference refPlaneLine = uidoc.Selection.PickObjects(ObjectType.Element,refPlanesFilter, "Select a ref plane").First(); IList <Reference> refPlaneLine = uidoc.Selection.PickObjects(ObjectType.Element, refPlanesFilter, "Select a ref plane"); var enu = grouped.GetEnumerator(); using (Transaction t = new Transaction(doc, "Lock dim")) { t.Start(); while (enu.MoveNext()) { foreach (FamilyInstance item in enu.Current) { offset += 315 / 304.8; foreach (Reference refPlaneReference in refPlaneLine) { ReferencePlane refP = doc.GetElement(refPlaneReference) as ReferencePlane; #if REVIT2019 if (VoidByLineHelpers.IsParallel(item, refP)) { VoidByLineHelpers.DrawDimension(doc, refPlaneReference, item, offset); } #elif REVIT2017 #endif } } offset = 0; } t.Commit(); } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; ISelectionFilter columnFilter = new CategorySelectionFilter("Structural Columns"); IList <Reference> r = uidoc.Selection.PickObjects(ObjectType.Element, columnFilter, "Select columns"); List <Element> myElements = new List <Element>(); int s = 0; foreach (var e in r) { myElements.Add(doc.GetElement(e)); } using (var form = new FormCreateSections()) { form.ShowDialog(); if (form.DialogResult == winForm.DialogResult.Cancel) { return(Result.Cancelled); } using (Transaction tx = new Transaction(doc)) { try { tx.Start("Create Section"); if (form.sectionOrientation == "Long") { foreach (Element e in myElements) { Helpers.CreateColumnSection(doc, e, form.sectionPositionOffset, form.farClipOffset, form.bottomLevel, form.topLevel, form.flipDirection, form.columnParameter); s += 1; } } else { TaskDialog.Show("Warning", "Not implemented yet"); } TaskDialog.Show("Result", $"{s.ToString()} sections created"); //tx.Commit(); return(Result.Succeeded); } catch (Exception ex) { TaskDialog.Show("r", ex.Message); return(Result.Failed); } finally { tx.Commit(); } } //close transaction } //close winform } //close execute