Esempio n. 1
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                foreach (Element elem in revitDoc.Selection.Elements)
                {
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false)[0];

                        // calculate necessary arguments
                        Autodesk.Revit.DB.XYZ origin = new XYZ(
                            curve.get_EndPoint(0).X + curve.Length,
                            curve.get_EndPoint(0).Y,
                            curve.get_EndPoint(0).Z);// draw the text at the right size
                        Autodesk.Revit.DB.XYZ baseVec = new Autodesk.Revit.DB.XYZ(1, 0, 0);
                        Autodesk.Revit.DB.XYZ upVec   = new Autodesk.Revit.DB.XYZ(0, 0, 1);
                        double lineWidth = curve.Length / 50;
                        string strText   = "This is " + rebar.Category.Name + " : " + rebar.Name;

                        // create the text
                        Transaction t = new Transaction(revitDoc.Document);
                        t.Start("Create new textnote");
                        Autodesk.Revit.DB.TextNote text = revitDoc.Document.Create.NewTextNote(view, origin, baseVec, upVec, lineWidth,
                                                                                               Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_LEFT, strText);
                        text.Width = curve.Length; // set the text width
                        t.Commit();
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Tag the beam's start and end.
        /// </summary>
        /// <param name="tagMode">Mode of tag</param>
        /// <param name="tagSymbol">Tag symbol wrapper</param>
        /// <param name="leader">Whether the tag has leader</param>
        /// <param name="tagOrientation">Orientation of tag</param>
        public void CreateTag(TagMode tagMode,
                              FamilySymbolWrapper tagSymbol, bool leader,
                              TagOrientation tagOrientation)
        {
            foreach (FamilyInstance beam in m_beamList)
            {
                //Get the start point and end point of the selected beam.
                Autodesk.Revit.DB.LocationCurve location = beam.Location as Autodesk.Revit.DB.LocationCurve;
                Autodesk.Revit.DB.Curve         curve    = location.Curve;

                Transaction t = new Transaction(m_revitDoc.Document);
                t.Start("Create new tag");
                //Create tag on the beam's start and end.
                IndependentTag tag1 = m_docCreator.NewTag(
                    m_view, beam, leader, tagMode, tagOrientation, curve.get_EndPoint(0));
                IndependentTag tag2 = m_docCreator.NewTag(
                    m_view, beam, leader, tagMode, tagOrientation, curve.get_EndPoint(1));

                //Change the tag's object Type.
                tag1.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                tag2.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                t.Commit();
            }
        }
Esempio n. 3
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // Get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                foreach (Element elem in revitDoc.Selection.Elements)
                {
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false)[0];

                        // create a rebar tag at the first end point of the first curve
                        Transaction t = new Transaction(revitDoc.Document);
                        t.Start("Create new tag");
                        IndependentTag tag = revitDoc.Document.Create.NewTag(view, rebar, true,
                                                                             Autodesk.Revit.DB.TagMode.TM_ADDBY_CATEGORY,
                                                                             Autodesk.Revit.DB.TagOrientation.Horizontal, curve.get_EndPoint(0));
                        t.Commit();
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }