Rebar CreateRebar(Document document, FamilyInstance column, RebarBarType barType, RebarHookType hookType) { // Define the rebar geometry information - Line rebar LocationPoint location = column.Location as LocationPoint; XYZ origin = location.Point; XYZ normal = new XYZ(1, 0, 0); // create rebar 9' long XYZ rebarLineEnd = new XYZ(origin.X, origin.Y, origin.Z + 9); Line rebarLine = Line.CreateBound(origin, rebarLineEnd); // Create the line rebar IList <Curve> curves = new List <Curve>(); curves.Add(rebarLine); Rebar rebar = Rebar.CreateFromCurves(document, RebarStyle.StirrupTie, barType, hookType, hookType, column, origin, curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true); if (null != rebar) { // set specific layout for new rebar as fixed number, with 10 bars, distribution path length of 1.5' // with bars of the bar set on the same side of the rebar plane as indicated by normal // and both first and last bar in the set are shown rebar.SetLayoutAsFixedNumber(10, 1.5, true, true, true); } return(rebar); }
/// <summary> /// Create the transverse rebars, according to the transverse rebar location /// </summary> /// <param name="location">location of rebar which need to be created</param> /// <returns>the created rebar, return null if the creation is unsuccessful</returns> public Rebar FillTransverseBar(TransverseRebarLocation location) { // Get the geometry information which support rebar creation RebarGeometry geomInfo = new RebarGeometry(); RebarBarType barType = null; switch (location) { case TransverseRebarLocation.Start: // start transverse rebar case TransverseRebarLocation.End: // end transverse rebar geomInfo = m_geometry.GetTransverseRebar(location, m_transverseEndSpacing); barType = m_transverseEndType; break; case TransverseRebarLocation.Center:// center transverse rebar geomInfo = m_geometry.GetTransverseRebar(location, m_transverseCenterSpacing); barType = m_transverseCenterType; break; default: break; } // create the rebar return(PlaceRebars(barType, m_transverseHookType, m_transverseHookType, geomInfo, RebarHookOrientation.Right, RebarHookOrientation.Left)); }
/// <summary> /// Get the bar diameter from the rebar object. /// </summary> /// <param name="element">The rebar object.</param> /// <returns>The returned bar diameter from the rebar, or a default value.</returns> static double GetBarDiameter(object element) { double bendDiameter = 0.0; if (element is RebarContainerItem) { RebarBendData bendData = (element as RebarContainerItem).GetBendData(); if (bendData != null) { bendDiameter = UnitUtil.ScaleLength(bendData.BarDiameter); } } else if (element is Element) { Element rebarElement = element as Element; Document doc = rebarElement.Document; ElementId typeId = rebarElement.GetTypeId(); RebarBarType elementType = doc.GetElement(rebarElement.GetTypeId()) as RebarBarType; if (elementType != null) { bendDiameter = UnitUtil.ScaleLength(elementType.BarDiameter); } } if (bendDiameter < MathUtil.Eps()) { return(UnitUtil.ScaleLength(1.0 / 12.0)); } return(bendDiameter); }
///<summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, Autodesk.Revit.DB.ElementSet elements) { Transaction trans = new Transaction(revit.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.CreateComplexAreaRein"); trans.Start(); //initialize members m_revit = revit; m_currentDoc = revit.Application.ActiveUIDocument; m_data = new AreaReinData(revit.Application.ActiveUIDocument.Document); try { //check precondition and prepare necessary data to create AreaReinforcement. Reference refer = null; IList <Curve> curves = new List <Curve>(); Floor floor = InitFloor(ref refer, ref curves); //ask for user's input AreaReinData dataOnFloor = new AreaReinData(revit.Application.ActiveUIDocument.Document); CreateComplexAreaReinForm createForm = new CreateComplexAreaReinForm(dataOnFloor); if (createForm.ShowDialog() == DialogResult.OK) { //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves[0]); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z); //create AreaReinforcement by AreaReinforcement.Create() function DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create; ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(revit.Application.ActiveUIDocument.Document); ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(revit.Application.ActiveUIDocument.Document); ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(revit.Application.ActiveUIDocument.Document); AreaReinforcement areaRein = AreaReinforcement.Create(revit.Application.ActiveUIDocument.Document, floor, curves, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId); //set AreaReinforcement and it's AreaReinforcementCurves parameters dataOnFloor.FillIn(areaRein); trans.Commit(); return(Autodesk.Revit.UI.Result.Succeeded); } } catch (ApplicationException appEx) { message = appEx.Message; trans.RollBack(); return(Autodesk.Revit.UI.Result.Failed); } catch { message = "Unknow Errors."; trans.RollBack(); return(Autodesk.Revit.UI.Result.Failed); } trans.RollBack(); return(Autodesk.Revit.UI.Result.Cancelled); }
// Token: 0x0600021B RID: 539 RVA: 0x0000EC80 File Offset: 0x0000CE80 public static string GetSteelQuality(RebarBarType revitReinfType) { double defValue = 500.0.NperMM2ToRevitYieldStrength(); double num = Math.Round(revitReinfType.GetSteelQuality(defValue).RevitYieldStrengthToNperMM2(), 5); return(string.Empty + num); }
/// <summary> /// Create the transverse reinforcement, according to the transverse reinforcement location /// </summary> /// <param name="location">location of rebar which need to be created</param> /// <returns>the created reinforcement, return null if the creation is unsuccessful</returns> public RebarContainerItem FillTransverseItem(RebarContainer cont, TransverseRebarLocation location) { // Get the geometry information which support reinforcement creation RebarGeometry geomInfo = new RebarGeometry(); RebarBarType barType = null; switch (location) { case TransverseRebarLocation.Start: // start transverse reinforcement case TransverseRebarLocation.End: // end transverse reinforcement geomInfo = m_geometry.GetTransverseRebar(location, m_transverseEndSpacing); barType = m_transverseEndType; break; case TransverseRebarLocation.Center:// center transverse reinforcement geomInfo = m_geometry.GetTransverseRebar(location, m_transverseCenterSpacing); barType = m_transverseCenterType; break; default: break; } // create the container item return(PlaceContainerItem(cont, barType, m_transverseHookType, m_transverseHookType, geomInfo, RebarHookOrientation.Left, RebarHookOrientation.Left)); }
private void onMaterialComboChange(Autodesk.Revit.UI.ExtensibleStorage.Framework.SchemaEditorEventArgs e) { resetSchema(e); // update barTypeCombo // update strength field if (schema.Material != null) { double yield = Autodesk.Revit.DB.CodeChecking.Engineering.Concrete.RebarUtility.GetMaterialStructuralAsset(schema.Material).MinimumYieldStress; yield = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(yield, DisplayUnitType.DUT_PASCALS); e.Editor.SetValue("MinimumYieldStress", yield, DisplayUnitType.DUT_PASCALS); IList <ElementId> barsIds = Autodesk.Revit.DB.CodeChecking.Engineering.Concrete.RebarUtility.GetListRebarForMaterial(e.Document, schema.Material.Id); List <RebarBarType> barTypesSource = (from elementId in barsIds select e.Document.GetElement(elementId) as RebarBarType).ToList(); var btypes = barTypesSource.Select(s => new { myDiam = s.BarDiameter, mybType = s }).OrderBy(s => s.myDiam); List <RebarBarType> bars = btypes.Select(s => s.mybType).ToList(); RebarBarType currentBar = schema.RebarBarType; e.Editor.SetAttribute("RebarBarType", Autodesk.Revit.UI.ExtensibleStorage.Framework.Attributes.ComboBoxAttribute.PropertyDataSource, bars, DisplayUnitType.DUT_UNDEFINED); if (currentBar == null || !barsIds.Contains(currentBar.Id)) { e.Editor.SetValue("RebarBarType", null, DisplayUnitType.DUT_UNDEFINED); } else { e.Editor.SetValue("RebarBarType", currentBar, DisplayUnitType.DUT_UNDEFINED); onBarChange(e); } } else { e.Editor.SetValue("MinimumYieldStress", 0.0, DisplayUnitType.DUT_PASCALS); } }
/// <summary> /// Create the rebar at the top of beam, according to the top rebar location /// </summary> /// <param name="location">location of rebar which need to be created</param> /// <returns>the created rebar, return null if the creation is unsuccessful</returns> private Rebar FillTopBar(TopRebarLocation location) { //get the geometry information of the rebar RebarGeometry geomInfo = m_geometry.GetTopRebar(location); RebarHookType startHookType = null; //the start hook type of the rebar RebarHookType endHookType = null; // the end hook type of the rebar RebarBarType rebarType = null; // the rebar type RebarHookOrientation startOrient = RebarHookOrientation.Right; // the start hook orient RebarHookOrientation endOrient = RebarHookOrientation.Left; // the end hook orient // decide the rebar type, hook type and hook orient according to location switch (location) { case TopRebarLocation.Start: startHookType = m_topHookType; // start hook type rebarType = m_topEndType; // rebar type startOrient = GetTopHookOrient(geomInfo, location); // start hook orient break; case TopRebarLocation.Center: rebarType = m_topCenterType; // rebar type break; case TopRebarLocation.End: endHookType = m_topHookType; // end hook type rebarType = m_topEndType; // rebar type endOrient = GetTopHookOrient(geomInfo, location); // end hook orient break; } // create the rebar return(PlaceRebars(rebarType, startHookType, endHookType, geomInfo, startOrient, endOrient)); }
public MyRebarType(Document Doc, double BarDiameter, double BarClass, bool AsCommonLength) { Debug.WriteLine("Try to create MyRebarType, d=" + BarDiameter + " class=" + BarClass); List <RebarBarType> bartypes = new FilteredElementCollector(Doc) .WhereElementIsElementType() .OfClass(typeof(RebarBarType)) .Cast <RebarBarType>() .ToList(); foreach (RebarBarType rbt in bartypes) { #if R2017 || R2018 || R2019 || R2020 || R2021 double diam = rbt.BarDiameter; #else double diam = rbt.BarNominalDiameter; #endif if (Math.Abs(diam - BarDiameter) > 0.00001) { continue; } Parameter classParam = rbt.LookupParameter("Арм.КлассЧисло"); if (classParam == null || !classParam.HasValue) { continue; } double cls = classParam.AsDouble(); if (Math.Abs(cls - BarClass) > 0.00001) { continue; } Parameter commonLengthParam = rbt.LookupParameter("Рзм.ПогМетрыВкл"); if (commonLengthParam == null || !commonLengthParam.HasValue) { continue; } bool commonLengthOn = commonLengthParam.AsInteger() == 1; if (commonLengthOn != AsCommonLength) { continue; } bartype = rbt; isValid = true; Debug.WriteLine("Type found: " + bartype.Name); break; } if (!isValid) { string errmsg = "Не удалось получить тип стержня d" + (BarDiameter * 304.8).ToString("F0") + " класс " + BarClass.ToString("F0"); Debug.WriteLine(errmsg); throw new Exception(errmsg); } }
/// <summary> /// check whether the selected is expected, find all hooktypes in current project /// </summary> /// <param name="selected">selected elements</param> /// <returns>whether the selected AreaReinforcement is expected</returns> private bool PreData() { ElementSet selected = m_commandData.Application.ActiveUIDocument.Selection.Elements; //selected is not only one AreaReinforcement if (selected.Size != 1) { return(false); } foreach (Object o in selected) { m_areaRein = o as AreaReinforcement; } if (null == m_areaRein) { return(false); } //make sure hook type and bar type exist in current project and get them m_hookTypes = new Hashtable(); m_barTypes = new Hashtable(); Document activeDoc = m_commandData.Application.ActiveUIDocument.Document; FilteredElementIterator itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarHookType)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { RebarHookType hookType = itor.Current as RebarHookType; if (null != hookType) { string hookTypeName = hookType.Name; m_hookTypes.Add(hookTypeName, hookType.Id); } } itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarBarType)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { RebarBarType barType = itor.Current as RebarBarType; if (null != barType) { string barTypeName = barType.Name; m_barTypes.Add(barTypeName, barType.Id); } } if (m_hookTypes.Count == 0 || m_barTypes.Count == 0) { return(false); } return(true); }
/// <summary> /// When the user click ok, refresh the data of BeamFramReinMaker and close form /// </summary> private void okButton_Click(object sender, EventArgs e) { // set TopEndRebarType data RebarBarType type = topEndRebarTypeComboBox.SelectedItem as RebarBarType; m_dataBuffer.TopEndRebarType = type; // set TopCenterRebarType data type = topCenterRebarTypeComboBox.SelectedItem as RebarBarType; m_dataBuffer.TopCenterRebarType = type; // set BottomRebarType data type = bottomRebarTypeComboBox.SelectedItem as RebarBarType; m_dataBuffer.BottomRebarType = type; // set TransverseRebarType data type = transverseRebarTypeComboBox.SelectedItem as RebarBarType; m_dataBuffer.TransverseRebarType = type; // set TopHookType data RebarHookType hookType = topBarHookComboBox.SelectedItem as RebarHookType; m_dataBuffer.TopHookType = hookType; // set TransverseHookType data hookType = transverseBarHookComboBox.SelectedItem as RebarHookType; m_dataBuffer.TransverseHookType = hookType; try { // set TransverseEndSpacing data double spacing = Convert.ToDouble(transverseEndSpacingTextBox.Text); m_dataBuffer.TransverseEndSpacing = spacing; // set TransverseCenterSpacing data spacing = Convert.ToDouble(transverseCenterSpacingTextBox.Text); m_dataBuffer.TransverseCenterSpacing = spacing; } catch (FormatException) { // spacing text boxes should only input number information MessageBox.Show("Please input double number in spacing TextBox.", "Revit"); return; } catch (Exception ex) { // other unexpected error, just show the information MessageBox.Show(ex.Message, "Revit"); return; } this.DialogResult = DialogResult.OK; // set dialog result this.Close(); // close the form }
public MyRebarType(RebarBarType BarType) { Name = BarType.Name; bartype = BarType; foreach (Parameter param in BarType.ParametersMap) { string paramName = param.Definition.Name; MyParameterValue mpv = new MyParameterValue(param); ValuesStorage.Add(paramName, mpv); } }
/***************************************************/ public static RebarBarType ElementType(this oM.Physical.Reinforcement.IReinforcingBar bar, Document document, RevitSettings settings = null) { RebarBarType result = bar.ElementType <RebarBarType>(document); if (result == null) { string barTypeName = ((int)(bar.Diameter * 1000)).ToString(); return(new FilteredElementCollector(document).OfClass(typeof(RebarBarType)).Where(x => x.Name == barTypeName).FirstOrDefault() as RebarBarType); } return(result); }
/// <summary> /// create simple AreaReinforcement on vertical straight rectangular wall /// </summary> /// <param name="wall"></param> /// <returns>is successful</returns> private bool CreateAreaReinOnWall(Wall wall) { //make sure selected is basic wall if (wall.WallType.Kind != WallKind.Basic) { TaskDialog.Show("Revit", "Selected wall is not a basic wall."); return(false); } GeomHelper helper = new GeomHelper(); Reference refer = null; IList <Curve> curves = new List <Curve>(); //check whether wall is vertical rectangular and analytical model shape is line if (!helper.GetWallGeom(wall, ref refer, ref curves)) { ApplicationException appEx = new ApplicationException( "Your selection is not a structural straight rectangular wall."); throw appEx; } AreaReinDataOnWall dataOnWall = new AreaReinDataOnWall(); CreateSimpleAreaReinForm createForm = new CreateSimpleAreaReinForm(dataOnWall); //allow use select parameters to create if (createForm.ShowDialog() == DialogResult.OK) { DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create; //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves[0]); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z); //create AreaReinforcement IList <Curve> curveList = new List <Curve>(); foreach (Curve curve in curves) { curveList.Add(curve); } ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(m_revit.Application.ActiveUIDocument.Document); AreaReinforcement areaRein = AreaReinforcement.Create(m_revit.Application.ActiveUIDocument.Document, wall, curveList, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId); dataOnWall.FillIn(areaRein); return(true); } return(false); }
public static int GetRebarClass(RebarBarType barType) { Parameter rebarClassParam = barType.LookupParameter("Арм.КлассЧисло"); if (rebarClassParam == null || !rebarClassParam.HasValue) { throw new Exception("Нет параметра Арм.КлассЧисло в элементе " + barType.Id.IntegerValue.ToString()); } int rebarClass = (int)rebarClassParam.AsDouble(); return(rebarClass); }
/// <summary> /// When the user click ok, refresh the data of BeamFramReinMaker and close form /// </summary> private void okButton_Click(object sender, EventArgs e) { // set TransverseCenterType data RebarBarType type = centerTransverseRebarTypeComboBox.SelectedItem as RebarBarType; m_dataBuffer.TransverseCenterType = type; // set TransverseEndType data type = endTransverseRebarTypeComboBox.SelectedItem as RebarBarType; m_dataBuffer.TransverseEndType = type; // set VerticalRebarType data type = verticalRebarTypeComboBox.SelectedItem as RebarBarType; m_dataBuffer.VerticalRebarType = type; // set TransverseHookType data RebarHookType hookType = transverseRebarHookComboBox.SelectedItem as RebarHookType; m_dataBuffer.TransverseHookType = hookType; // set VerticalRebarNumber data int number = (int)rebarQuantityNumericUpDown.Value; m_dataBuffer.VerticalRebarNumber = number; try { // set TransverseCenterSpacing data double spacing = Convert.ToDouble(centerSpacingTextBox.Text); m_dataBuffer.TransverseCenterSpacing = spacing; // set TransverseEndSpacing data spacing = Convert.ToDouble(endSpacingTextBox.Text); m_dataBuffer.TransverseEndSpacing = spacing; } catch (FormatException) { // spacing text boxes should only input number information TaskDialog.Show("Revit", "Please input double number in spacing TextBox."); return; } catch (Exception ex) { // if other unexpected error, just show the information TaskDialog.Show("Revit", ex.Message); } this.DialogResult = DialogResult.OK; // set dialog result this.Close(); // close the form }
/// <summary> /// A wrap function which used to create the reinforcement. /// </summary> /// <param name="rebarType">The element of RebarBarType</param> /// <param name="startHook">The element of start RebarHookType</param> /// <param name="endHook">The element of end RebarHookType</param> /// <param name="geomInfo">The goemetry information of the rebar</param> /// <param name="startOrient">An Integer defines the orientation of the start hook</param> /// <param name="endOrient">An Integer defines the orientation of the end hook</param> /// <returns></returns> protected RebarContainerItem PlaceContainerItem(RebarContainer cont, RebarBarType rebarType, RebarHookType startHook, RebarHookType endHook, RebarGeometry geomInfo, RebarHookOrientation startOrient, RebarHookOrientation endOrient) { Autodesk.Revit.DB.XYZ normal = geomInfo.Normal; // the direction of reinforcement distribution IList <Curve> curves = geomInfo.Curves; // the shape of the reinforcement curves RebarContainerItem item = cont.AppendItemFromCurves(RebarStyle.Standard, rebarType, startHook, endHook, normal, curves, startOrient, endOrient, false, true); if (2 < geomInfo.RebarNumber && 0 < geomInfo.RebarSpacing) { item.SetLayoutAsNumberWithSpacing(geomInfo.RebarNumber, geomInfo.RebarSpacing, true, true, true); } return(item); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Reference pickedReference = null; try { pickedReference = uidoc.Selection.PickObject(ObjectType.Element, new RebarSelectFilter() , "Pick a Rebar"); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return Result.Cancelled; } Rebar rebar = doc.GetElement(pickedReference) as Rebar; if (!rebar.IsRebarShapeDriven() || rebar.LayoutRule == RebarLayoutRule.Single) { message = "Singe rebar and non-shape driven rebars are not supported."; return Result.Failed; } double rebarDiameter = rebar.GetBendData().BarDiameter; RebarBarType barType = doc.GetElement(rebar.GetTypeId()) as RebarBarType; IList<Curve> transformedCurvesFirst = Utils.GetTransformedCenterLineCurvesAtPostition(rebar, 0); IList<Curve> transformedCurvesLast = Utils.GetTransformedCenterLineCurvesAtPostition(rebar, rebar.NumberOfBarPositions-1); XYZ direction = transformedCurvesFirst.OfType<Line>().First().Direction; List<XYZ> rebarInBendFirstPoints = GetPointInArc(transformedCurvesFirst, rebarDiameter); List<XYZ> rebarInBendLastPoints = GetPointInArc(transformedCurvesLast, rebarDiameter); using (Transaction t1 = new Transaction(doc, "Add rebar in bend")) { t1.Start(); for (int i = 0; i < rebarInBendFirstPoints.Count; i++) { Line newRebarCenterline = Line.CreateBound(rebarInBendFirstPoints[i], rebarInBendLastPoints[i]); IList<Curve> rebarCurve = new List<Curve>(); rebarCurve.Add(newRebarCenterline); Rebar.CreateFromCurves(doc, RebarStyle.Standard, barType, null, null, doc.GetElement(rebar.GetHostId()), direction, rebarCurve, RebarHookOrientation.Left, RebarHookOrientation.Left, true, false); } doc.Regenerate(); t1.Commit(); } return Result.Succeeded; }
private RebarBarType GetRebarBarType(string nameRebarBarType) { RebarBarType rebarBarType = null; FilteredElementCollector rbtCollector = new FilteredElementCollector(doc); rbtCollector.OfClass(typeof(RebarBarType)) .OfCategory(BuiltInCategory.OST_Rebar); foreach (RebarBarType rbt in rbtCollector) { if (rbt.Name == nameRebarBarType) { rebarBarType = rbt; } } return(rebarBarType); }
// Фильт для типаразмеров арматуры по имени private bool IsValidRebarBarType(RebarBarType rebarBarType) { string pattern = @"\w*"; if (Regex.IsMatch(AreaReinforcementType.Name, @"\w*нижняя\w*", RegexOptions.IgnoreCase)) { pattern = @"^standart\w*нижняя\w*"; } if (Regex.IsMatch(AreaReinforcementType.Name, @"\w*верхняя\w*", RegexOptions.IgnoreCase)) { pattern = @"^standart\w*верхняя\w*"; } return(Regex.IsMatch(rebarBarType.Name, pattern, RegexOptions.IgnoreCase)); }
/// <summary> /// Create PathReinforcement on floor /// </summary> /// <param name="points">points used to create PathReinforcement</param> /// <param name="flip">used to specify whether new PathReinforcement is Filp</param> /// <returns>new created PathReinforcement</returns> public override PathReinforcement CreatePathReinforcement(List <Vector4> points, bool flip) { Autodesk.Revit.DB.XYZ p1, p2; Line curve; IList <Curve> curves = new List <Curve>(); for (int i = 0; i < points.Count - 1; i++) { p1 = new Autodesk.Revit.DB.XYZ(points[i].X, points[i].Y, points[i].Z); p2 = new Autodesk.Revit.DB.XYZ(points[i + 1].X, points[i + 1].Y, points[i + 1].Z); curve = Line.CreateBound(p1, p2); curves.Add(curve); } ElementId pathReinforcementTypeId = PathReinforcementType.CreateDefaultPathReinforcementType(m_document); ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(m_document); ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(m_document); return(PathReinforcement.Create(m_document, m_data, curves, flip, pathReinforcementTypeId, rebarBarTypeId, rebarHookTypeId, rebarHookTypeId)); }
private double getDelta_0(Document doc, Rebar myRebar) { //UIDocument uiDoc = this.ActiveUIDocument; //Document doc = uiDoc.Document; //Get diameter of rebar RebarBarType myRbType = doc.GetElement(myRebar.GetTypeId()) as RebarBarType; double myRebarDiameter = myRbType.BarDiameter; // Get host of rebar ElementId myBeamId = myRebar.GetHostId(); Element myBeam = doc.GetElement(myBeamId); if (myBeam.Category.Name != "Structural Framing") { TaskDialog.Show("Loi!", "Hay chon 1 rebar co host la 1 Structural Framing"); return(10000000); } else { //Get location curve of beam LocationCurve lc = myBeam.Location as LocationCurve; Line line = lc.Curve as Line; //Get vector of location cuver beam XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = q - p; // Vector equation of line XYZ middlePoint = myRebar.get_BoundingBox(null).Max.Add(myRebar.get_BoundingBox(null).Min) / 2; // NOTE LAM TRON SO // middlePoint = new XYZ(middlePoint.X,middlePoint.Y), // Math.Round(middlePoint.Z,1)); double delta_0 = Math.Sqrt(Math.Pow(middlePoint.X - p.X, 2) + Math.Pow(middlePoint.Y - p.Y, 2)) - myRebarDiameter / 2; return(delta_0); } }
/// <summary> /// create simple AreaReinforcement on horizontal floor /// </summary> /// <param name="floor"></param> /// <returns>is successful</returns> private bool CreateAreaReinOnFloor(Floor floor) { GeomHelper helper = new GeomHelper(); Reference refer = null; IList <Curve> curves = new List <Curve>(); //check whether floor is horizontal rectangular //and prepare necessary to create AreaReinforcement if (!helper.GetFloorGeom(floor, ref refer, ref curves)) { ApplicationException appEx = new ApplicationException( "Your selection is not a horizontal rectangular slab."); throw appEx; } AreaReinDataOnFloor dataOnFloor = new AreaReinDataOnFloor(); CreateSimpleAreaReinForm createForm = new CreateSimpleAreaReinForm(dataOnFloor); //allow use select parameters to create if (createForm.ShowDialog() == DialogResult.OK) { //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves[0]); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z); //Create AreaReinforcement ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(m_revit.Application.ActiveUIDocument.Document); AreaReinforcement areaRein = AreaReinforcement.Create(m_revit.Application.ActiveUIDocument.Document, floor, curves, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId); //set AreaReinforcement and it's AreaReinforcementCurves parameters dataOnFloor.FillIn(areaRein); return(true); } return(false); }
/// <summary> /// Present the main dialog for user to prepare the parameters for Rebar creation, /// and after that if user click the OK button, a new Rebar will be created. /// </summary> public void Execute() { using (NewRebarForm form = new NewRebarForm(m_rvtUIDoc.Document)) { if (DialogResult.OK == form.ShowDialog()) { RebarBarType barType = form.RebarBarType; RebarShape barShape = form.RebarShape; List <Autodesk.Revit.DB.XYZ> profilePoints = m_geometryData.ProfilePoints; Autodesk.Revit.DB.XYZ origin = profilePoints[0]; Autodesk.Revit.DB.XYZ yVec = profilePoints[1] - origin; Autodesk.Revit.DB.XYZ xVec = profilePoints[3] - origin; m_createdRebar = Rebar.CreateFromRebarShape(m_rvtUIDoc.Document, barShape, barType, m_rebarHost, origin, xVec, yVec); LayoutRebar(); } } }
/// <summary> /// A wrap fuction which used to create the reinforcement. /// </summary> /// <param name="rebarType">The element of RebarBarType</param> /// <param name="startHook">The element of start RebarHookType</param> /// <param name="endHook">The element of end RebarHookType</param> /// <param name="geomInfo">The goemetry information of the rebar</param> /// <param name="startOrient">An Integer defines the orientation of the start hook</param> /// <param name="endOrient">An Integer defines the orientation of the end hook</param> /// <returns></returns> protected Rebar PlaceRebars(RebarBarType rebarType, RebarHookType startHook, RebarHookType endHook, RebarGeometry geomInfo, RebarHookOrientation startOrient, RebarHookOrientation endOrient) { Autodesk.Revit.DB.XYZ normal = geomInfo.Normal; // the direction of rebar distribution IList <Curve> curves = geomInfo.Curves; // the shape of the rebar curves // Invoke the NewRebar() method to create rebar Rebar createdRebar = Rebar.CreateFromCurves(m_revitDoc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, rebarType, startHook, endHook, m_hostObject, normal, curves, startOrient, endOrient, false, true); if (null == createdRebar) // Assert the creation is successful { return(null); } // Change the rebar number and spacing properties to the user wanted SetRebarSpaceAndNumber(createdRebar, geomInfo.RebarNumber, geomInfo.RebarSpacing); return(createdRebar); }
public MyRebarType(Document doc, string typeName) { List <RebarBarType> bartypes = new FilteredElementCollector(doc) .WhereElementIsElementType() .OfClass(typeof(RebarBarType)) .Cast <RebarBarType>() .ToList(); List <RebarBarType> mytypes = bartypes .Where(i => i.Name == typeName) .ToList(); if (mytypes.Count == 0) { bartype = bartypes.First(); } else { bartype = mytypes.First(); isValid = true; } }
/// <summary> /// Get the bar diameters (model and nominal) from the rebar object. /// </summary> /// <param name="element">The rebar object.</param> /// <out param name="nominalDiameter">The nominal diameter.</param> /// <out param name="modelDiameter">The model diameter</param> static void GetBarDiameters(object element, out double nominalDiameter, out double modelDiameter) { nominalDiameter = 0.0; modelDiameter = 0.0; if (element is RebarContainerItem) { RebarBendData bendData = (element as RebarContainerItem).GetBendData(); if (bendData != null) { nominalDiameter = UnitUtil.ScaleLength(bendData.BarNominalDiameter); modelDiameter = UnitUtil.ScaleLength(bendData.BarModelDiameter); } } else if (element is Element) { Element rebarElement = element as Element; Document doc = rebarElement.Document; ElementId typeId = rebarElement.GetTypeId(); RebarBarType elementType = doc.GetElement(rebarElement.GetTypeId()) as RebarBarType; if (elementType != null) { nominalDiameter = UnitUtil.ScaleLength(elementType.BarNominalDiameter); modelDiameter = UnitUtil.ScaleLength(elementType.BarModelDiameter); } } if (nominalDiameter < MathUtil.Eps()) { nominalDiameter = UnitUtil.ScaleLength(1.0 / 12.0); } if (modelDiameter < MathUtil.Eps()) { modelDiameter = UnitUtil.ScaleLength(1.0 / 12.0); } }
public static double getRebarFreeLength(RebarBarType barType, Element elem, double round) { int rebarClass = GetRebarClass(barType); double Rs = GetRebarRsByClass(rebarClass); double n1 = rebarClass > 240 ? 2.5 : 2; #if R2017 || R2018 || R2019 || R2020 || R2021 double barDiameter = barType.BarDiameter; #else double barDiameter = barType.BarNominalDiameter; #endif double n2 = (barDiameter * 304.8) > 33 ? 0.9 : 1; int concreteClass = GetConcreteClass(elem); double Rbt = GetConcreteRbtByClass(concreteClass); double alpha = GetCoeffAlpha(false, true); double length = (alpha * Rs * barDiameter) / (n1 * n2 * Rbt * 4); double lengthRound = round * Math.Round(length / round); return(lengthRound); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { #region Public variables UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; Selection sel = uidoc.Selection; #endregion ElementId defaultRebarBarTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType); RebarBarType bType = doc.GetElement(defaultRebarBarTypeId) as RebarBarType; double delta = bType.BarDiameter; double verSpacing = Convert.ToDouble(Shared.vSpacing); double horSpacing = Convert.ToDouble(Shared.hSpacing); ElementId hookId = null; FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(RebarHookType)); foreach (RebarHookType hType in collector) { if (hType.Id.ToString() == "648153") { hookId = hType.Id; } } using (Transaction tx = new Transaction(doc)) { tx.Start("First trans"); if (Shared.vSpacing == null) { verSpacing = 400; } else { verSpacing = Convert.ToDouble(Shared.vSpacing); } if (Shared.hSpacing == null) { horSpacing = 400; } else { horSpacing = Convert.ToDouble(Shared.hSpacing); } Reference selectedObject = sel.PickObject(ObjectType.Element, "Please select an element to copy."); Element element = doc.GetElement(selectedObject.ElementId); if (elementIsWall(element)) { Wall wall = element as Wall; cleanUp(wall); kA = kInAxis(wall); kM = kInMeters(wall); deltaInAxis = getThisValueInAxis(delta, kM) * 1000; double heightInAxis = getThisValueInAxis(getHeightOf(wall), kM); double lengthInAxis = getLengthInAxisOf(wall); IList <XYZ> wallPoints = new List <XYZ>(); IList <XYZ> insetPoints = new List <XYZ>(); IList <XYZ> wallPointsDelta = new List <XYZ>(); IList <XYZ> insetPointsDelta = new List <XYZ>(); XYZ rightTopFrontPoint = getRightTopFrontPoint(wall); XYZ leftBottomRearPoint = getLeftBottomRearPoint(wall); for (int i = 0; i <= 7; i++) { switch (i) { case 0: { XYZ wallRearPoint0 = leftBottomRearPoint; XYZ deltedWallRearPoint0 = new XYZ(wallRearPoint0.X + deltaInAxis, wallRearPoint0.Y - deltaInAxis, wallRearPoint0.Z); wallPoints.Add(wallRearPoint0); wallPointsDelta.Add(deltedWallRearPoint0); break; } case 1: { XYZ wallRearPoint1 = new XYZ(leftBottomRearPoint.X + lengthInAxis, leftBottomRearPoint.Y, leftBottomRearPoint.Z); XYZ deltedWallRearPoint1 = new XYZ(leftBottomRearPoint.X + lengthInAxis - deltaInAxis, leftBottomRearPoint.Y - deltaInAxis, leftBottomRearPoint.Z); wallPoints.Add(wallRearPoint1); wallPointsDelta.Add(deltedWallRearPoint1); break; } case 2: { XYZ wallRearPoint2 = new XYZ(leftBottomRearPoint.X + lengthInAxis, leftBottomRearPoint.Y, leftBottomRearPoint.Z + heightInAxis); XYZ deltedWallRearPoint2 = new XYZ(leftBottomRearPoint.X + lengthInAxis - deltaInAxis, leftBottomRearPoint.Y - deltaInAxis, leftBottomRearPoint.Z + heightInAxis); wallPoints.Add(wallRearPoint2); wallPointsDelta.Add(deltedWallRearPoint2); break; } case 3: { XYZ wallRearPoint3 = new XYZ(leftBottomRearPoint.X, leftBottomRearPoint.Y, leftBottomRearPoint.Z + heightInAxis); XYZ deltedWallRearPoint3 = new XYZ(leftBottomRearPoint.X + deltaInAxis, leftBottomRearPoint.Y - deltaInAxis, leftBottomRearPoint.Z + heightInAxis); wallPoints.Add(wallRearPoint3); wallPointsDelta.Add(deltedWallRearPoint3); break; } case 4: { XYZ wallFrontPoint4 = new XYZ(rightTopFrontPoint.X - lengthInAxis, rightTopFrontPoint.Y, rightTopFrontPoint.Z - heightInAxis); XYZ deltedWallFrontPoint4 = new XYZ(rightTopFrontPoint.X - lengthInAxis + deltaInAxis, rightTopFrontPoint.Y + deltaInAxis, rightTopFrontPoint.Z - heightInAxis); wallPoints.Add(wallFrontPoint4); wallPointsDelta.Add(deltedWallFrontPoint4); break; } case 5: { XYZ wallFrontPoint5 = new XYZ(rightTopFrontPoint.X, rightTopFrontPoint.Y, rightTopFrontPoint.Z - heightInAxis); XYZ deltedWallFrontPoint5 = new XYZ(rightTopFrontPoint.X - deltaInAxis, rightTopFrontPoint.Y + deltaInAxis, rightTopFrontPoint.Z - heightInAxis); wallPoints.Add(wallFrontPoint5); wallPointsDelta.Add(deltedWallFrontPoint5); break; } case 6: { XYZ wallFrontPoint6 = new XYZ(rightTopFrontPoint.X, rightTopFrontPoint.Y, rightTopFrontPoint.Z); XYZ deltedWallFrontPoint6 = new XYZ(rightTopFrontPoint.X - deltaInAxis, rightTopFrontPoint.Y + deltaInAxis, rightTopFrontPoint.Z); wallPoints.Add(wallFrontPoint6); wallPointsDelta.Add(deltedWallFrontPoint6); break; } case 7: { XYZ wallFrontPoint7 = new XYZ(rightTopFrontPoint.X - lengthInAxis, rightTopFrontPoint.Y, rightTopFrontPoint.Z); XYZ deltedWallFrontPoint7 = new XYZ(rightTopFrontPoint.X - lengthInAxis + deltaInAxis, rightTopFrontPoint.Y + deltaInAxis, rightTopFrontPoint.Z); wallPoints.Add(wallFrontPoint7); wallPointsDelta.Add(deltedWallFrontPoint7); break; } default: { throw new IndexOutOfRangeException(); } } } switch (existsAnyInset(wall)) { case true: { Element inset = getFirstInsetElement(doc, wall); double insetLengthInAxis = getThisValueInAxis(getLengthOf(inset), kM); double insetHeightInAxis = getThisValueInAxis(getHeightOf(inset), kM); XYZ insetRightFrontTopPoint = getRightTopFrontPoint(inset); XYZ insetLeftRearBottomPoint = getLeftBottomRearPoint(inset); for (int i = 0; i <= 7; i++) { switch (i) { case 0: { XYZ insetRearPoint0 = insetLeftRearBottomPoint; XYZ deltedInsetRearPoint0 = new XYZ(insetLeftRearBottomPoint.X, insetLeftRearBottomPoint.Y - deltaInAxis, insetLeftRearBottomPoint.Z); insetPoints.Add(insetRearPoint0); insetPointsDelta.Add(deltedInsetRearPoint0); break; } case 1: { XYZ insetRearPoint1 = new XYZ(insetLeftRearBottomPoint.X + insetLengthInAxis, insetLeftRearBottomPoint.Y, insetLeftRearBottomPoint.Z); XYZ deltedInsetRearPoint1 = new XYZ(insetLeftRearBottomPoint.X + insetLengthInAxis, insetLeftRearBottomPoint.Y - deltaInAxis, insetLeftRearBottomPoint.Z); insetPoints.Add(insetRearPoint1); insetPointsDelta.Add(deltedInsetRearPoint1); break; } case 2: { XYZ insetRearPoint2 = new XYZ(insetLeftRearBottomPoint.X + insetLengthInAxis, insetLeftRearBottomPoint.Y, insetLeftRearBottomPoint.Z + insetHeightInAxis); XYZ deltedInsetRearPoint2 = new XYZ(insetLeftRearBottomPoint.X + insetLengthInAxis, insetLeftRearBottomPoint.Y - deltaInAxis, insetLeftRearBottomPoint.Z + insetHeightInAxis); insetPoints.Add(insetRearPoint2); insetPointsDelta.Add(deltedInsetRearPoint2); break; } case 3: { XYZ insetRearPoint3 = new XYZ(insetLeftRearBottomPoint.X, insetLeftRearBottomPoint.Y, insetLeftRearBottomPoint.Z + insetHeightInAxis); XYZ deltedInsetRearPoint3 = new XYZ(insetLeftRearBottomPoint.X, insetLeftRearBottomPoint.Y - deltaInAxis, insetLeftRearBottomPoint.Z + insetHeightInAxis); insetPoints.Add(insetRearPoint3); insetPointsDelta.Add(deltedInsetRearPoint3); break; } case 4: { XYZ insetFrontPoint4 = new XYZ(insetRightFrontTopPoint.X - insetLengthInAxis, insetRightFrontTopPoint.Y, insetRightFrontTopPoint.Z - insetHeightInAxis); XYZ deltedInsetFrontPoint4 = new XYZ(insetRightFrontTopPoint.X - insetLengthInAxis, insetRightFrontTopPoint.Y + deltaInAxis, insetRightFrontTopPoint.Z - insetHeightInAxis); insetPoints.Add(insetFrontPoint4); insetPointsDelta.Add(deltedInsetFrontPoint4); break; } case 5: { XYZ insetFrontPoint5 = new XYZ(insetRightFrontTopPoint.X, insetRightFrontTopPoint.Y, insetRightFrontTopPoint.Z - insetHeightInAxis); XYZ deltedInsetFrontPoint5 = new XYZ(insetRightFrontTopPoint.X, insetRightFrontTopPoint.Y + deltaInAxis, insetRightFrontTopPoint.Z - insetHeightInAxis); insetPoints.Add(insetFrontPoint5); insetPointsDelta.Add(deltedInsetFrontPoint5); break; } case 6: { XYZ insetFrontPoint6 = new XYZ(insetRightFrontTopPoint.X, insetRightFrontTopPoint.Y, insetRightFrontTopPoint.Z); XYZ deltedInsetFrontPoint6 = new XYZ(insetRightFrontTopPoint.X, insetRightFrontTopPoint.Y + deltaInAxis, insetRightFrontTopPoint.Z); insetPoints.Add(insetFrontPoint6); insetPointsDelta.Add(deltedInsetFrontPoint6); break; } case 7: { XYZ insetFrontPoint7 = new XYZ(insetRightFrontTopPoint.X - insetLengthInAxis, insetRightFrontTopPoint.Y, insetRightFrontTopPoint.Z); XYZ deltedInsetFrontPoint7 = new XYZ(insetRightFrontTopPoint.X - insetLengthInAxis, insetRightFrontTopPoint.Y + deltaInAxis, insetRightFrontTopPoint.Z); insetPoints.Add(insetFrontPoint7); insetPointsDelta.Add(deltedInsetFrontPoint7); break; } default: { throw new IndexOutOfRangeException(); } } } double bottomWallToInsetSpace = getThisValueInMeters(insetPointsDelta[0].Z - wallPointsDelta[0].Z, kA); double topWallToInsetSpace = getThisValueInMeters(wallPointsDelta[3].Z - insetPointsDelta[3].Z, kA); double leftWallToInsetSpace = Math.Abs(getThisValueInMeters(wallPointsDelta[0].X - insetPointsDelta[0].X, kA)); double rightWallToInsetSpace = Math.Abs(getThisValueInMeters(wallPointsDelta[1].X - insetPointsDelta[1].X, kA)); #region rear verticals // left rear wall to left rear inset vertical XYZ point0 = wallPointsDelta[0]; XYZ point1 = new XYZ(insetPointsDelta[0].X - getThisValueInAxis(verSpacing, kM), wallPointsDelta[0].Y, wallPointsDelta[0].Z); creatPathReinforcement(doc, wall, point0, point1, null, false, false, 0, true, 500, 0); // bottom rear inset to bottom rear wall vertical XYZ point2 = new XYZ(insetPointsDelta[0].X, wallPointsDelta[0].Y, wallPointsDelta[0].Z); XYZ point3 = new XYZ(insetPointsDelta[1].X, wallPointsDelta[0].Y, wallPointsDelta[0].Z); creatPathReinforcement(doc, wall, point2, point3, null, false, false, 0, true, 500, bottomWallToInsetSpace); // right rear inset to right rear wall vertical XYZ point4 = new XYZ(insetPointsDelta[1].X + getThisValueInAxis(verSpacing, kM), wallPointsDelta[1].Y, wallPointsDelta[1].Z); XYZ point5 = new XYZ(wallPointsDelta[1].X, wallPointsDelta[1].Y, wallPointsDelta[1].Z); creatPathReinforcement(doc, wall, point4, point5, null, false, false, 0, true, 500, 0); // top rear inset to top rear wall vertical XYZ point6 = insetPointsDelta[3]; XYZ point7 = insetPointsDelta[2]; creatPathReinforcement(doc, wall, point6, point7, null, false, false, 0, true, 500, topWallToInsetSpace); #endregion #region front verticals XYZ point8 = wallPointsDelta[4]; XYZ point9 = new XYZ(insetPointsDelta[4].X - getThisValueInAxis(verSpacing, kM), wallPointsDelta[4].Y, wallPointsDelta[4].Z); creatPathReinforcement(doc, wall, point8, point9, null, false, false, 0, false, 500, 0); // bottom front inset to bottom front wall vertical XYZ point10 = new XYZ(insetPointsDelta[4].X, wallPointsDelta[4].Y, wallPointsDelta[4].Z); XYZ point11 = new XYZ(insetPointsDelta[5].X, wallPointsDelta[4].Y, wallPointsDelta[4].Z); creatPathReinforcement(doc, wall, point10, point11, null, false, false, 0, false, 500, bottomWallToInsetSpace); // right front inset to right front wall vertical XYZ point12 = new XYZ(insetPointsDelta[5].X + getThisValueInAxis(verSpacing, kM), wallPointsDelta[5].Y, wallPointsDelta[5].Z); XYZ point13 = new XYZ(wallPointsDelta[5].X, wallPointsDelta[5].Y, wallPointsDelta[5].Z); creatPathReinforcement(doc, wall, point12, point13, null, false, false, 0, false, 500, 0); // top rear inset to top rear wall vertical XYZ point14 = insetPointsDelta[7]; XYZ point15 = insetPointsDelta[6]; creatPathReinforcement(doc, wall, point14, point15, null, false, false, 0, false, 500, topWallToInsetSpace); #endregion #region rear horizontal XYZ point16 = wallPointsDelta[0]; XYZ point17 = new XYZ(wallPointsDelta[0].X, wallPointsDelta[0].Y, insetPointsDelta[0].Z - getThisValueInAxis(horSpacing, kM)); creatPathReinforcement(doc, wall, point17, point16, null, true, false, 0, false, 0, 0); XYZ circlePoint1 = new XYZ(wallPoints[0].X, wallPoints[0].Y, wallPoints[0].Z + deltaInAxis); XYZ circlePoint2 = new XYZ(wallPoints[0].X, wallPoints[0].Y, insetPoints[0].Z - getThisValueInAxis(horSpacing, kM) + deltaInAxis); createPathReinforcementWithHook(doc, wall, circlePoint2, circlePoint1, hookId, false); createPathReinforcementWithHook(doc, wall, circlePoint2, circlePoint1, hookId, true); //-------------------------------------------------------------------------------------------------------------------// XYZ point18 = insetPointsDelta[0]; XYZ point19 = insetPointsDelta[3]; creatPathReinforcement(doc, wall, point18, point19, null, true, false, 0, false, 0, leftWallToInsetSpace); XYZ circlePoint3 = new XYZ(wallPoints[0].X, wallPoints[0].Y, insetPoints[0].Z + deltaInAxis); XYZ circlePoint4 = new XYZ(wallPoints[3].X, wallPoints[3].Y, insetPoints[3].Z + deltaInAxis); createPathReinforcementWithHook(doc, wall, circlePoint4, circlePoint3, hookId, false); createPathReinforcementWithHook(doc, wall, circlePoint4, circlePoint3, hookId, true); //-------------------------------------------------------------------------------------------------------------------// XYZ point20 = insetPointsDelta[1]; XYZ point21 = insetPointsDelta[2]; creatPathReinforcement(doc, wall, point21, point20, null, true, false, 0, false, 0, rightWallToInsetSpace); XYZ circlePoint5 = new XYZ(wallPoints[1].X, wallPoints[1].Y, insetPoints[1].Z + deltaInAxis); XYZ circlePoint6 = new XYZ(wallPoints[1].X, wallPoints[1].Y, insetPoints[2].Z + deltaInAxis); createPathReinforcementWithHook(doc, wall, circlePoint5, circlePoint6, hookId, false); createPathReinforcementWithHook(doc, wall, circlePoint5, circlePoint6, hookId, true); //-------------------------------------------------------------------------------------------------------------------// XYZ point22 = new XYZ(wallPointsDelta[3].X, wallPointsDelta[3].Y, insetPointsDelta[3].Z + getThisValueInAxis(horSpacing, kM)); XYZ point23 = wallPointsDelta[3]; creatPathReinforcement(doc, wall, point23, point22, null, true, false, 0, false, 0, 0); XYZ circlePoint7 = new XYZ(wallPoints[1].X, wallPoints[1].Y, wallPoints[1].Z + deltaInAxis); XYZ circlePoint8 = new XYZ(wallPoints[1].X, wallPoints[1].Y, insetPoints[1].Z - getThisValueInAxis(horSpacing, kM) + deltaInAxis); createPathReinforcementWithHook(doc, wall, circlePoint7, circlePoint8, hookId, false); createPathReinforcementWithHook(doc, wall, circlePoint7, circlePoint8, hookId, true); //-------------------------------------------------------------------------------------------------------------------// XYZ circlePoint9 = new XYZ(wallPoints[2].X, wallPoints[2].Y, wallPoints[2].Z); XYZ circlePoint10 = new XYZ(wallPoints[2].X, wallPoints[2].Y, insetPoints[2].Z + getThisValueInAxis(horSpacing, kM) + deltaInAxis); createPathReinforcementWithHook(doc, wall, circlePoint10, circlePoint9, hookId, false); createPathReinforcementWithHook(doc, wall, circlePoint10, circlePoint9, hookId, true); //-------------------------------------------------------------------------------------------------------------------// XYZ circlePoint11 = new XYZ(wallPoints[3].X, wallPoints[3].Y, wallPoints[3].Z); XYZ circlePoint12 = new XYZ(wallPoints[3].X, wallPoints[3].Y, insetPoints[3].Z + getThisValueInAxis(horSpacing, kM) + deltaInAxis); createPathReinforcementWithHook(doc, wall, circlePoint11, circlePoint12, hookId, false); createPathReinforcementWithHook(doc, wall, circlePoint11, circlePoint12, hookId, true); //-------------------------------------------------------------------------------------------------------------------// #endregion #region front horizontal XYZ point24 = wallPointsDelta[4]; XYZ point25 = new XYZ(wallPointsDelta[4].X, wallPointsDelta[4].Y, insetPointsDelta[4].Z - getThisValueInAxis(400, kM)); creatPathReinforcement(doc, wall, point25, point24, null, true, false, 0, true, 0, 0); XYZ point26 = insetPointsDelta[4]; XYZ point27 = insetPointsDelta[7]; creatPathReinforcement(doc, wall, point26, point27, null, true, false, 0, true, 0, leftWallToInsetSpace); XYZ point28 = insetPointsDelta[5]; XYZ point29 = insetPointsDelta[6]; creatPathReinforcement(doc, wall, point29, point28, null, true, false, 0, true, 0, rightWallToInsetSpace); XYZ point30 = new XYZ(wallPointsDelta[4].X, wallPointsDelta[7].Y, insetPointsDelta[7].Z + getThisValueInAxis(400, kM)); XYZ point31 = wallPointsDelta[7]; creatPathReinforcement(doc, wall, point31, point30, null, true, false, 0, true, 0, 0); #endregion #region horizontal circled hooks #endregion break; } case false: { //rear horizontal for (double i = wallPoints[3].Z; Math.Abs(i) <= heightInAxis;) { XYZ point1 = new XYZ(wallPoints[3].X, wallPoints[3].Y, i); XYZ point2 = new XYZ(wallPoints[3].X, wallPoints[3].Y, i - getThisValueInAxis(400, kM)); XYZ point3 = new XYZ(wallPoints[3].X, wallPoints[3].Y, wallPoints[3].Z - heightInAxis); if (Math.Abs(i - getThisValueInAxis(400, kM) * 2) > heightInAxis) { double spacing = getThisValueInMeters(point1.Z - point3.Z, kA) / 2; creatPathReinforcement(doc, wall, point1, point3, null, true, true, spacing, true, 0, 0); } else { creatPathReinforcement(doc, wall, point1, point2, null, true, false, 0, true, 0, 0); } i -= getThisValueInAxis(400, kM) * 2; } // front horizontal for (double i = wallPoints[7].Z; Math.Abs(i) <= heightInAxis;) { XYZ point1 = new XYZ(wallPoints[7].X, wallPoints[7].Y, i); XYZ point2 = new XYZ(wallPoints[7].X, wallPoints[7].Y, i - getThisValueInAxis(400, kM)); XYZ point3 = new XYZ(wallPoints[7].X, wallPoints[7].Y, wallPoints[7].Z - heightInAxis); if (Math.Abs(i - getThisValueInAxis(400, kM) * 2) > heightInAxis) { double spacing = getThisValueInMeters(point1.Z - point3.Z, kA) / 2; creatPathReinforcement(doc, wall, point1, point3, null, true, true, spacing, false, 0, 0); } else { creatPathReinforcement(doc, wall, point1, point2, null, true, false, 0, false, 0, 0); } i -= getThisValueInAxis(400, kM) * 2; } // rear vertical for (double i = wallPoints[4].X; i <= wallPoints[5].X;) { XYZ point1 = new XYZ(i, wallPoints[4].Y, wallPoints[4].Z); XYZ point2 = new XYZ(i + getThisValueInAxis(400, kM), wallPoints[4].Y, wallPoints[4].Z); XYZ point3 = new XYZ(wallPoints[5].X, wallPoints[5].Y, wallPoints[5].Z); if (i + getThisValueInAxis(400, kM) * 2 > wallPoints[5].X) { double spacing = getThisValueInMeters(point3.X - point1.X, kA) / 2; creatPathReinforcement(doc, wall, point1, point3, null, false, true, spacing, true, 500, 0); } else { creatPathReinforcement(doc, wall, point1, point2, null, false, false, 0, true, 500, 0); } i += getThisValueInAxis(400, kM) * 2; } // front vertical for (double i = wallPoints[0].X; i <= wallPoints[1].X;) { XYZ point1 = new XYZ(i, wallPoints[0].Y, wallPoints[0].Z); XYZ point2 = new XYZ(i + getThisValueInAxis(400, kM), wallPoints[0].Y, wallPoints[0].Z); XYZ point3 = new XYZ(wallPoints[1].X, wallPoints[1].Y, wallPoints[1].Z); if (i + getThisValueInAxis(400, kM) * 2 > wallPoints[1].X) { double spacing = getThisValueInMeters(point3.X - point1.X, kA) / 2; creatPathReinforcement(doc, wall, point1, point3, null, false, true, spacing, false, 500, 0); } else { creatPathReinforcement(doc, wall, point1, point2, null, false, false, 0, false, 500, 0); } i += getThisValueInAxis(400, kM) * 2; } break; } } } tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// A wrap fuction which used to create the reinforcement. /// </summary> /// <param name="rebarType">The element of RebarBarType</param> /// <param name="startHook">The element of start RebarHookType</param> /// <param name="endHook">The element of end RebarHookType</param> /// <param name="geomInfo">The goemetry information of the rebar</param> /// <param name="startOrient">An Integer defines the orientation of the start hook</param> /// <param name="endOrient">An Integer defines the orientation of the end hook</param> /// <returns></returns> protected Rebar PlaceRebars(RebarBarType rebarType, RebarHookType startHook, RebarHookType endHook, RebarGeometry geomInfo, RebarHookOrientation startOrient, RebarHookOrientation endOrient) { Autodesk.Revit.DB.XYZ normal = geomInfo.Normal; // the direction of rebar distribution IList<Curve> curves = geomInfo.Curves; // the shape of the rebar curves // Invoke the NewRebar() method to create rebar Rebar createdRebar = Rebar.CreateFromCurves(m_revitDoc, Autodesk.Revit.DB.Structure.RebarStyle.Standard, rebarType, startHook, endHook, m_hostObject, normal, curves, startOrient, endOrient, false, true); if (null == createdRebar) // Assert the creation is successful { return null; } // Change the rebar number and spacing properties to the user wanted SetRebarSpaceAndNumber(createdRebar, geomInfo.RebarNumber, geomInfo.RebarSpacing); return createdRebar; }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool"); try { transaction.Start(); ElementSet elems = commandData.Application.ActiveUIDocument.Selection.Elements; #region selection error handle //if user have some wrong selection, give user an Error message if (1 != elems.Size) { message = "please select one PathReinforcement."; return(Autodesk.Revit.UI.Result.Cancelled); } Autodesk.Revit.DB.Element selectElem = null; foreach (Autodesk.Revit.DB.Element e in elems) { selectElem = e; } if (!(selectElem is Autodesk.Revit.DB.Structure.PathReinforcement)) { message = "please select one PathReinforcement."; return(Autodesk.Revit.UI.Result.Cancelled); } #endregion //clear all rebar bar type. if (s_rebarBarTypes.Count > 0) { s_rebarBarTypes.Clear(); } //get all bar type. FilteredElementCollector collector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document); FilteredElementIterator itor = collector.OfClass(typeof(RebarBarType)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { RebarBarType bartype = itor.Current as RebarBarType; if (null != bartype) { Autodesk.Revit.DB.ElementId id = bartype.Id; String name = bartype.Name; s_rebarBarTypes.Add(name, id); } } //Create a form to view the path reinforcement. Autodesk.Revit.DB.Structure.PathReinforcement pathRein = selectElem as Autodesk.Revit.DB.Structure.PathReinforcement; using (PathReinforcementForm form = new PathReinforcementForm(pathRein, commandData)) { form.ShowDialog(); } } catch (Exception e) { transaction.RollBack(); message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } finally { transaction.Commit(); } return(Autodesk.Revit.UI.Result.Succeeded); }
private void Stream(ArrayList data, RebarBarType rebarType) { data.Add(new Snoop.Data.ClassSeparator(typeof(RebarBarType))); // TBD: how to call functions }