Esempio n. 1
0
        /// <summary>
        /// Create the transverse rebars, according to the location of transverse rebars
        /// </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();

            switch (location)
            {
            case TransverseRebarLocation.Start: // start transverse rebar
            case TransverseRebarLocation.End:   // end transverse rebar
                geomInfo = m_geometry.GetTransverseRebar(location, m_transverseEndSpacing);
                break;

            case TransverseRebarLocation.Center:// center transverse rebar
                geomInfo = m_geometry.GetTransverseRebar(location, m_transverseCenterSpacing);
                break;
            }

            RebarHookOrientation startHook = RebarHookOrientation.Right;
            RebarHookOrientation endHook   = RebarHookOrientation.Left;

            if (!GeomUtil.IsInRightDir(geomInfo.Normal))
            {
                startHook = RebarHookOrientation.Left;
                endHook   = RebarHookOrientation.Right;
            }

            // create the rebar
            return(PlaceRebars(m_transverseType, m_transverseHookType, m_transverseHookType,
                               geomInfo, startHook, endHook));
        }
Esempio n. 2
0
        /// <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));
        }
Esempio n. 3
0
        /// <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);
        }
        /// <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);
        }
Esempio n. 5
0
        /// <summary>
        /// Present a dialog to customize a RebarShape.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createShapeButton_Click(object sender, EventArgs e)
        {
            // Make sure the name is not null or empty.
            if (string.IsNullOrEmpty(nameTextBox.Text.Trim()))
            {
                TaskDialog.Show("Revit", "Please give a name to create a rebar shape.");
                return;
            }

            // Make sure the input name is started with letter and
            // just contains letters, numbers and underlines.
            Regex regex = new Regex("^[a-zA-Z]\\w+$");

            if (!regex.IsMatch(nameTextBox.Text.Trim()))
            {
                TaskDialog.Show("Revit", "Please input the name starting with letter and just containing letters, numbers and underlines. String is " + nameTextBox.Text.ToString());
                nameTextBox.Focus();
                return;
            }

            // Create a RebarShapeDefinition.
            RebarShapeDef shapeDef = null;

            if (byArcradioButton.Checked)
            {
                // Create arc shape.
                RebarShapeDefinitionByArc     arcShapeDefinition = null;
                RebarShapeDefinitionByArcType arcType            = (RebarShapeDefinitionByArcType)Enum.Parse(typeof(RebarShapeDefinitionByArcType), arcTypecomboBox.Text);
                if (arcType != RebarShapeDefinitionByArcType.Spiral)
                {
                    arcShapeDefinition = new RebarShapeDefinitionByArc(m_rvtDoc, arcType);
                }
                else
                {
                    // Set default value for Spiral-Shape definition.
                    arcShapeDefinition = new RebarShapeDefinitionByArc(m_rvtDoc, 10.0, 3.0, 0, 0);
                }
                shapeDef = new RebarShapeDefByArc(arcShapeDefinition);
            }
            else if (bySegmentsradioButton.Checked)
            {
                // Create straight segments shape.
                int segmentCount = 0;
                if (int.TryParse(segmentCountTextBox.Text, out segmentCount) && segmentCount > 0)
                {
                    shapeDef = new RebarShapeDefBySegment(new RebarShapeDefinitionBySegments(m_rvtDoc, segmentCount));
                }
                else
                {
                    TaskDialog.Show("Revit", "Please input a valid positive integer as segments count.");
                    return;
                }
            }

            int startHookAngle = 0;
            int endHookAngle   = 0;
            RebarHookOrientation startHookOrientation = RebarHookOrientation.Left;
            RebarHookOrientation endHookOrientation   = RebarHookOrientation.Left;

            bool doCreate = false;

            using (NewRebarShapeForm form = new NewRebarShapeForm(m_rvtDoc, shapeDef))
            {
                // Present a form to customize the shape.
                if (DialogResult.OK == form.ShowDialog())
                {
                    doCreate = true;
                    if (form.NeedSetHooks)
                    {
                        // Set hooks for rebar shape.
                        startHookAngle       = form.StartHookAngle;
                        endHookAngle         = form.EndHookAngle;
                        startHookOrientation = form.StartHookOrientation;
                        endHookOrientation   = form.EndHookOrientation;
                    }
                }
            }

            if (doCreate)
            {
                // Create the RebarShape.
                RebarShape createdRebarShape = RebarShape.Create(m_rvtDoc, shapeDef.RebarshapeDefinition, null,
                                                                 RebarStyle.Standard, StirrupTieAttachmentType.InteriorFace,
                                                                 startHookAngle, startHookOrientation,
                                                                 endHookAngle, endHookOrientation,
                                                                 0);
                createdRebarShape.Name = nameTextBox.Text.Trim();

                // Add the created shape to the candidate list.
                m_rebarShapes.Add(createdRebarShape);
                m_shapesBinding.ResetBindings(false);
                shapesComboBox.SelectedItem = createdRebarShape;
            }
        }
Esempio n. 6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document  doc = commandData.Application.ActiveUIDocument.Document;
            Selection sel = commandData.Application.ActiveUIDocument.Selection;

            if (sel.GetElementIds().Count == 0)
            {
                message = "Выберите арматурные стержни";
                return(Result.Failed);
            }

            Rebar bar = doc.GetElement(sel.GetElementIds().First()) as Rebar;

            if (bar == null)
            {
                message = "Выберите арматурные стержни";
                return(Result.Failed);
            }
#if R2017
            XYZ normal = bar.Normal;
#else
            RebarShapeDrivenAccessor acc = bar.GetShapeDrivenAccessor();
            XYZ normal = acc.Normal;
#endif
            RebarBarType barType = doc.GetElement(bar.GetTypeId()) as RebarBarType;

            int        rebarStyleNumber = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_STYLE).AsInteger();
            RebarStyle rebarStyle       = (RebarStyle)rebarStyleNumber;

            RebarHookType hookTypeStart   = null;
            ElementId     hookStartTypeId = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE).AsElementId();
            if (hookStartTypeId != null)
            {
                hookTypeStart = doc.GetElement(hookStartTypeId) as RebarHookType;
            }

            RebarHookType hookTypeEnd   = null;
            ElementId     hookEndTypeId = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_END_TYPE).AsElementId();
            if (hookEndTypeId != null)
            {
                hookTypeEnd = doc.GetElement(hookEndTypeId) as RebarHookType;
            }


            RebarBendData        rbd         = bar.GetBendData();
            RebarHookOrientation hookOrient0 = rbd.HookOrient0;
            RebarHookOrientation hookOrient1 = rbd.HookOrient1;

            Element host = doc.GetElement(bar.GetHostId());

            List <Curve> curves    = bar.GetCenterlineCurves(false, true, true, MultiplanarOption.IncludeOnlyPlanarCurves, 0).ToList();
            int          barsCount = bar.NumberOfBarPositions;

            List <ElementId> newRebarIds = new List <ElementId>();
            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("Explode rebar set");
                for (int i = 0; i < barsCount; i++)
                {
#if R2017
                    Transform barOffset = bar.GetBarPositionTransform(i);
#else
                    Transform barOffset = acc.GetBarPositionTransform(i);
#endif
                    XYZ offset = barOffset.Origin;

                    Rebar newRebar = Rebar.CreateFromCurves(doc, rebarStyle, barType, hookTypeStart, hookTypeEnd, host, normal, curves,
                                                            hookOrient0, hookOrient1, true, false);
                    doc.Regenerate();
                    ElementTransformUtils.MoveElement(doc, newRebar.Id, offset);
                    newRebarIds.Add(newRebar.Id);
                }

                doc.Delete(bar.Id);

                tr.Commit();
            }

            sel.SetElementIds(newRebarIds);

            return(Result.Succeeded);
        }
Esempio n. 7
0
        /// <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;
        }