コード例 #1
0
        /// <summary>
        /// Calculates the start hook angle for a rebar subelement, from the subelement cache. This is used for Free Form Rebar when the Workshop intructions are Bent.
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="handle">
        /// The IFC handle that may offer parameter overrides.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool GetParameterFromSubelementCache(Element element, IFCAnyHandle handle)
        {
            Parameter param = element.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE);

            if (param == null)
            {
                return(false);
            }

            if (param.Definition == null)
            {
                return(false);
            }

            ElementIdParameterValue paramVal = ParameterUtil.getParameterValueByNameFromSubelementCache(element.Id, handle, param.Definition.Name) as ElementIdParameterValue;

            if (paramVal != null)
            {
                RebarHookType hookType = element.Document.GetElement(paramVal.Value) as RebarHookType;
                if (hookType == null)
                {
                    return(false);
                }

                m_Angle = UnitUtil.ScaleAngle(hookType.HookAngle);

                return(true);
            }
            return(false);
        }
コード例 #2
0
        ///<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);
        }
コード例 #3
0
        /// <summary>
        /// Calculates the start hook angle for a rebar.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="extrusionCreationData">The IFCExtrusionCreationData.</param>
        /// <param name="element">The element to calculate the value.</param>
        /// <param name="elementType">The element type.</param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            RebarBendData bendData = null;

            if (element is Rebar)
            {
                bendData = (element as Rebar).GetBendData();
            }
            else if (element is RebarInSystem)
            {
                bendData = (element as RebarInSystem).GetBendData();
            }

            if (bendData != null)
            {
                if (bendData.HookLength0 > MathUtil.Eps())
                {
                    ElementId hookAtStartTypeId;
                    if (ParameterUtil.GetElementIdValueFromElement(element, BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE, out hookAtStartTypeId) != null)
                    {
                        RebarHookType rebarHookType = element.Document.GetElement(hookAtStartTypeId) as RebarHookType;
                        if (rebarHookType != null)
                        {
                            //HookAngle is measured in radians, so scale directly.
                            m_Angle = rebarHookType.HookAngle * 180 / Math.PI;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #4
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));
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        /// <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
        }
コード例 #9
0
        /// <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));
        }
コード例 #10
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);
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
0
        //private void setBeJoined(Document doc, Element myBeJoined)
        //{

        //    ICollection<ElementId> myListElemIdsJoined = JoinGeometryUtils.GetJoinedElements(doc, myBeJoined);

        //    using (Transaction trans = new Transaction(doc, "Switch Join"))
        //    {
        //        trans.Start();
        //        foreach (ElementId myElemId in myListElemIdsJoined)
        //        {

        //            if (!JoinGeometryUtils.IsCuttingElementInJoin(doc, doc.GetElement(myElemId), myBeJoined))
        //            {
        //                JoinGeometryUtils.SwitchJoinOrder(doc, doc.GetElement(myElemId), myBeJoined);
        //            }

        //        }

        //        trans.Commit();
        //    }
        //}


        public void Rebar_FromCurve_Top_Func(Document doc, Element myBeam, List <Face> myListFacePicked, double divideFac, double coverBar,
                                             string myRebarShapeName, string myRebarTypeName)
        {
            //BoundingBox beam
            BoundingBoxXYZ myBoundBeam = myBeam.get_BoundingBox(null);
            double         hBeam       = myBoundBeam.Max.Z - myBoundBeam.Min.Z;

            LocationCurve myLocBeam = myBeam.Location as LocationCurve;

            Line myLocLine = myLocBeam.Curve as Line;

            XYZ p = myLocLine.GetEndPoint(0);
            XYZ q = myLocLine.GetEndPoint(1);

            XYZ v = q - p;

            XYZ pE = p - 0.5 * v;
            XYZ vE = q - pE;

            XYZ vRB = new XYZ(v.Y, -1 * v.X, v.Z);

            List <double> myListDisSortFace = getAndSortDisOfEndFaces(myListFacePicked, pE);


            double lengSeg_1 = myListDisSortFace[1] - myListDisSortFace[0];
            double lengSeg_2 = myListDisSortFace[3] - myListDisSortFace[2];

            XYZ ePR1_XY = pE + ((myListDisSortFace[1] - lengSeg_1 / divideFac) / vE.GetLength()) * vE;
            XYZ ePR2_XY = pE + ((myListDisSortFace[2] + lengSeg_2 / divideFac) / vE.GetLength()) * vE;


            XYZ ePR1 = new XYZ(ePR1_XY.X, ePR1_XY.Y, myBoundBeam.Max.Z - coverBar);
            XYZ ePR2 = new XYZ(ePR2_XY.X, ePR2_XY.Y, myBoundBeam.Max.Z - coverBar);

            Line curveOfRebar = Line.CreateBound(ePR1, ePR2);

            //Tang
            List <Curve> myShape = new List <Curve>()
            {
                curveOfRebar
            };

            // RebarShape
            FilteredElementCollector fecRebarShape = new FilteredElementCollector(doc)
                                                     .OfClass(typeof(RebarShape));

            RebarShape myRebarShape = fecRebarShape.Cast <RebarShape>().
                                      First <RebarShape>(myRebarShape2 => myRebarShape2.Name == myRebarShapeName);


            // Rebartype
            FilteredElementCollector fecRebarType = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(RebarBarType));
            RebarBarType myRebarType = fecRebarType.Cast <RebarBarType>().
                                       First <RebarBarType>(myRebarType2 => myRebarType2.Name == myRebarTypeName);



            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));

            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                Rebar myRebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, myRebarType,
                                                       null, null,
                                                       myBeam, vRB,
                                                       myShape,
                                                       RebarHookOrientation.Left, RebarHookOrientation.Right,
                                                       true, false);


                trans.Commit();
            }
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        public void testRebar_FromShape()
        {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;


            // Pick Rebar

            List <int> myListIdCategoryRebar = new List <int>();

            myListIdCategoryRebar.Add((int)BuiltInCategory.OST_StructuralFraming);

            // Select first Element (ex beam)
            Reference myRefBeam = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByIdCategory(myListIdCategoryRebar), "Pick a Beam...");
            //Get element1 from ref
            Element myBeam = doc.GetElement(myRefBeam);


            setBeJoined(myBeam);

            LocationCurve myLocBeam = myBeam.Location as LocationCurve;

            Line centerLinebeam = myLocBeam.Curve as Line;

            XYZ p = centerLinebeam.GetEndPoint(0);
            XYZ q = centerLinebeam.GetEndPoint(1);
            XYZ v = p - q;

            XYZ v1 = v.CrossProduct(p);


            List <Curve> myShape = new List <Curve>()
            {
                centerLinebeam
            };


            // Rebartype
            FilteredElementCollector fec1 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarBarType));


            IEnumerable <RebarBarType> iterRebarBarTypes = fec1.Cast <RebarBarType>();

            RebarBarType myRebarType = iterRebarBarTypes.First();



            // RebarShape
            FilteredElementCollector fec3 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarShape));


            IEnumerable <RebarShape> iterRebarBarShapes = fec3.Cast <RebarShape>();

            RebarShape myRebarShape = iterRebarBarShapes.First();


            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));


            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            XYZ ORIGIN = new XYZ(q.X, q.Y, q.Z - 25 / 304.8);

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                Rebar bar = Rebar.CreateFromRebarShape(doc, myRebarShape, myRebarType, myBeam, ORIGIN, v, new XYZ(0, 0, 1));
                doc.Regenerate();

                List <Curve> myCenterLineOfRebar = bar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0) as List <Curve>;

                trans.Commit();
            }
        }
コード例 #16
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);
        }
コード例 #17
0
        private void Stream(ArrayList data, RebarHookType rebarHookType)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(RebarHookType)));

             // Nothing at this level yet!
        }
コード例 #18
0
        Stream(ArrayList data, ElementType sym)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(ElementType)));

            // no data at this level yet

            AnnotationSymbolType annoType = sym as AnnotationSymbolType;

            if (annoType != null)
            {
                Stream(data, annoType);
                return;
            }

            AreaReinforcementType areaReinforcementType = sym as AreaReinforcementType;

            if (areaReinforcementType != null)
            {
                Stream(data, areaReinforcementType);
                return;
            }

            AreaTagType areaTagType = sym as AreaTagType;

            if (areaTagType != null)
            {
                Stream(data, areaTagType);
                return;
            }

            BeamSystemType beamSystemType = sym as BeamSystemType;

            if (beamSystemType != null)
            {
                Stream(data, beamSystemType);
                return;
            }

            DimensionType dimType = sym as DimensionType;

            if (dimType != null)
            {
                Stream(data, dimType);
                return;
            }

            //TF
            FabricSheetType fabricST = sym as FabricSheetType;

            if (fabricST != null)
            {
                Stream(data, fabricST);
                return;
            }

            FabricWireType fabricWT = sym as FabricWireType;

            if (fabricWT != null)
            {
                Stream(data, fabricWT);
                return;
            }
            //TFEND

            GroupType groupType = sym as GroupType;

            if (groupType != null)
            {
                Stream(data, groupType);
                return;
            }

            HostObjAttributes hostAtt = sym as HostObjAttributes;

            if (hostAtt != null)
            {
                Stream(data, hostAtt);
                return;
            }

            InsertableObject insObj = sym as InsertableObject;

            if (insObj != null)
            {
                Stream(data, insObj);
                return;
            }

            LevelType levelType = sym as LevelType;

            if (levelType != null)
            {
                Stream(data, levelType);
                return;
            }

            LineAndTextAttrSymbol lineAndTextAttr = sym as LineAndTextAttrSymbol;

            if (lineAndTextAttr != null)
            {
                Stream(data, lineAndTextAttr);
                return;
            }

            LoadTypeBase loadTypeBase = sym as LoadTypeBase;

            if (loadTypeBase != null)
            {
                Stream(data, loadTypeBase);
                return;
            }

            MEPBuildingConstruction mepBldConst = sym as MEPBuildingConstruction;

            if (mepBldConst != null)
            {
                Stream(data, mepBldConst);
                return;
            }

            PathReinforcementType pathReinforcementType = sym as PathReinforcementType;

            if (pathReinforcementType != null)
            {
                Stream(data, pathReinforcementType);
                return;
            }

            RebarBarType rebarBarType = sym as RebarBarType;

            if (rebarBarType != null)
            {
                Stream(data, rebarBarType);
                return;
            }

            RebarCoverType rebarCoverType = sym as RebarCoverType;

            if (rebarCoverType != null)
            {
                Stream(data, rebarCoverType);
                return;
            }

            RebarHookType rebarHookType = sym as RebarHookType;

            if (rebarHookType != null)
            {
                Stream(data, rebarHookType);
                return;
            }

            RebarShape rebarShape = sym as RebarShape;

            if (rebarShape != null)
            {
                Stream(data, rebarShape);
                return;
            }

            RoomTagType roomTagType = sym as RoomTagType;

            if (roomTagType != null)
            {
                Stream(data, roomTagType);
                return;
            }

            SpaceTagType spaceTagType = sym as SpaceTagType;

            if (spaceTagType != null)
            {
                Stream(data, spaceTagType);
                return;
            }

            TrussType trussType = sym as TrussType;

            if (trussType != null)
            {
                Stream(data, trussType);
                return;
            }

            DistributionSysType distSysType = sym as DistributionSysType;

            if (distSysType != null)
            {
                Stream(data, distSysType);
                return;
            }

            MEPCurveType mepCurType = sym as MEPCurveType;

            if (mepCurType != null)
            {
                Stream(data, mepCurType);
                return;
            }

            FluidType fluidType = sym as FluidType;

            if (fluidType != null)
            {
                Stream(data, fluidType);
                return;
            }

            PipeScheduleType pipeSchedType = sym as PipeScheduleType;

            if (pipeSchedType != null)
            {
                Stream(data, pipeSchedType);
                return;
            }

            VoltageType voltType = sym as VoltageType;

            if (voltType != null)
            {
                Stream(data, voltType);
                return;
            }

            WireType wireType = sym as WireType;

            if (wireType != null)
            {
                Stream(data, wireType);
                return;
            }

            ModelTextType modelTxtType = sym as ModelTextType;

            if (modelTxtType != null)
            {
                Stream(data, modelTxtType);
                return;
            }
        }
コード例 #19
0
        Stream(ArrayList data, RebarHookType rebarHookType)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(RebarHookType)));

            // Nothing at this level yet!
        }
コード例 #20
0
ファイル: FramReinMaker.cs プロジェクト: AMEE/revit
        /// <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;
        }
コード例 #21
0
        public void testRebar_FromCurve()
        {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

//			// prompt select face
//
//			Reference myRef = uiDoc.Selection.PickObject(ObjectType.Face);
//
//			// Get element by pickface
//			Element e = doc.GetElement(myRef) as Element;
//
//
//			//Get GeoObject from element;
//			GeometryObject myGeoObj =  e.GetGeometryObjectFromReference(myRef) as Face;
//
//			//Get face from element Object:
//			Face myPickedFace = myGeoObj as Face;
//
//			XYZ myNorVecFace = myPickedFace.ComputeNormal(new UV(0,0));



            List <int> myListIdCategoryRebar = new List <int>();

            myListIdCategoryRebar.Add((int)BuiltInCategory.OST_StructuralFraming);

            // Select first Element (ex beam)
            Reference myRefBeam = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByIdCategory(myListIdCategoryRebar), "Pick a Beam...");
            //Get element1 from ref
            Element myBeam = doc.GetElement(myRefBeam);

            setBeJoined(myBeam);

            LocationCurve myLocBeam = myBeam.Location as LocationCurve;

            List <XYZ> myEndPoints = getPointCenterTopLine(myBeam);

            XYZ p1 = myEndPoints[0];
            XYZ p2 = myEndPoints[1];


            Line centerLineBeam = Line.CreateBound(p1, p2);



            XYZ p = centerLineBeam.GetEndPoint(0);
            XYZ q = centerLineBeam.GetEndPoint(1);
            XYZ v = p - q;


            XYZ v1 = new XYZ(v.Y, -1 * v.X, v.Z);


            XYZ p1_Rb = new XYZ(p1.X, p1.Y, p1.Z - 25 / 304.8);
            XYZ p2_Rb = new XYZ(p2.X, p2.Y, p2.Z - 25 / 304.8);

            Line curveOfRebar = Line.CreateBound(p1, p2);


            List <Curve> myShape = new List <Curve>()
            {
                curveOfRebar
            };


            // Rebartype
            FilteredElementCollector fec1 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarBarType));


            IEnumerable <RebarBarType> iterRebarBarTypes = fec1.Cast <RebarBarType>();

            RebarBarType myRebarType = iterRebarBarTypes.First();


            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));


            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                Rebar myRebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, myRebarType,
                                                       myRebarHookType,
                                                       myRebarHookType, myBeam,
                                                       v1, myShape,
                                                       RebarHookOrientation.Left, RebarHookOrientation.Left,
                                                       true, false);

                trans.Commit();
            }
        }
コード例 #22
0
        public void testRebar_FromCurve_Bot_Func(Document doc, Element myBeam, List <Face> myListFacePicked, double divideFac, double coverBar,
                                                 string myRebarShapeName, string myRebarTypeName)
        {
            LocationCurve myLocBeam = myBeam.Location as LocationCurve;

            List <XYZ> myEndPoints = getPointCenterBottomLine(doc, myBeam);

            XYZ p1 = myEndPoints[0];
            XYZ p2 = myEndPoints[1];

            XYZ    Vp1p2      = p2 - p1;
            double p1p2Length = Vp1p2.GetLength();

            // Cover bar thickness = 25
            //			double coverBar = 25/304.8;

            XYZ p1_Rb = p1 + coverBar / p1p2Length * Vp1p2;

            XYZ p2_Rb = p1 + (1 - coverBar / p1p2Length) * Vp1p2;

            p1_Rb = new XYZ(p1_Rb.X, p1_Rb.Y, p1_Rb.Z + coverBar);
            p2_Rb = new XYZ(p2_Rb.X, p2_Rb.Y, p2_Rb.Z + coverBar);



            Line centerLineBeam = Line.CreateBound(p1_Rb, p2_Rb);

            XYZ v  = p2_Rb - p1_Rb;
            XYZ p  = p1_Rb - 0.1 * v;
            XYZ v1 = new XYZ(v.Y, -1 * v.X, v.Z);
            XYZ v2 = p2_Rb - p;

            List <double> myListDisSortFace = getAndSortDisOfEndFaces(myListFacePicked, p);

            double lengSeg = myListDisSortFace[myListDisSortFace.Count() - 1] - myListDisSortFace[0];
            //		    double divideFac = 6;

            XYZ ePR1 = p + ((myListDisSortFace[0] + lengSeg / divideFac) / v2.GetLength()) * v2;
            XYZ ePR2 = p + ((myListDisSortFace[myListDisSortFace.Count() - 1] - lengSeg / divideFac) / v2.GetLength()) * v2;

            Line curveOfRebar = Line.CreateBound(ePR1, ePR2);


            List <Curve> myShape = new List <Curve>()
            {
                curveOfRebar
            };

            // RebarShape
            FilteredElementCollector fecRebarShape = new FilteredElementCollector(doc)
                                                     .OfClass(typeof(RebarShape));

            RebarShape myRebarShape = fecRebarShape.Cast <RebarShape>().
                                      First <RebarShape>(myRebarShape2 => myRebarShape2.Name == myRebarShapeName);


            // Rebartype
            FilteredElementCollector fecRebarType = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(RebarBarType));
            RebarBarType myRebarType = fecRebarType.Cast <RebarBarType>().
                                       First <RebarBarType>(myRebarType2 => myRebarType2.Name == myRebarTypeName);



            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));

            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                //				Rebar myRebar = Rebar.CreateFromCurvesAndShape(doc, myRebarShape, myRebarType,
                //				                                               null, null,
                //				                                               myBeam,v1,
                //				                                               myShape,
                //				                                               RebarHookOrientation.Left,
                //				                                               RebarHookOrientation.Left);
                Rebar myRebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, myRebarType,
                                                       null, null,
                                                       myBeam, v1,
                                                       myShape,
                                                       RebarHookOrientation.Left, RebarHookOrientation.Right,
                                                       true, false);


                trans.Commit();
            }
        }
コード例 #23
-1
        public void testRebar_FromShapeAndCurve_Bot()
        {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;


            List <int> myListIdCategoryRebar = new List <int>();

            myListIdCategoryRebar.Add((int)BuiltInCategory.OST_StructuralFraming);

            // Select first Element (ex beam)
            Reference myRefBeam = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByIdCategory(myListIdCategoryRebar), "Pick a Beam...");
            //Get element1 from ref
            Element myBeam = doc.GetElement(myRefBeam);

            setBeJoined(myBeam);
//			doc.Regenerate();

            LocationCurve myLocBeam = myBeam.Location as LocationCurve;

            List <XYZ> myEndPoints = getPointCenterBottomLine(myBeam);

            XYZ p1 = myEndPoints[0];
            XYZ p2 = myEndPoints[1];

            XYZ    Vp1p2      = p2 - p1;
            double p1p2Length = Vp1p2.GetLength();

            // Cover bar thickness = 25
            double coverBar = 25 / 304.8;

            XYZ p1_Rb = p1 + coverBar / p1p2Length * Vp1p2;

            XYZ p2_Rb = p1 + (1 - coverBar / p1p2Length) * Vp1p2;

            p1_Rb = new XYZ(p1_Rb.X, p1_Rb.Y, p1_Rb.Z + coverBar);
            p2_Rb = new XYZ(p2_Rb.X, p2_Rb.Y, p2_Rb.Z + coverBar);

            Line curveOfRebar = Line.CreateBound(p1_Rb, p2_Rb);


            List <Curve> myShape = new List <Curve>()
            {
                curveOfRebar
            };


            Line centerLineBeam = Line.CreateBound(p1, p2);


            XYZ p = centerLineBeam.GetEndPoint(0);
            XYZ q = centerLineBeam.GetEndPoint(1);
            XYZ v = p - q;


            XYZ v1 = new XYZ(v.Y, -1 * v.X, v.Z);


            // RebarShape
            FilteredElementCollector fec3 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarShape));


            IEnumerable <RebarShape> iterRebarBarShapes = fec3.Cast <RebarShape>();

            RebarShape myRebarShape = iterRebarBarShapes.First();


            // Rebartype
            FilteredElementCollector fec1 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarBarType));



            IEnumerable <RebarBarType> iterRebarBarTypes = fec1.Cast <RebarBarType>();

            RebarBarType myRebarType = iterRebarBarTypes.First();



            // Hooktype
            FilteredElementCollector fec2 = new FilteredElementCollector(doc)
                                            .OfClass(typeof(RebarHookType));

            IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>();

            RebarHookType myRebarHookType = iterRebarHookTypes.First();

            using (Transaction trans = new Transaction(doc, "rebar test"))

            {
                trans.Start();
                Rebar myRebar = Rebar.CreateFromCurvesAndShape(doc, myRebarShape, myRebarType,
                                                               null, null,
                                                               myBeam, v1,
                                                               myShape,
                                                               RebarHookOrientation.Left,
                                                               RebarHookOrientation.Left);
                //myRebar.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(4,1,true, true, true);
                trans.Commit();
            }
        }