public Result Execute(ExternalCommandData commandData,
                              ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.Creation.Application creApp = uiDoc.Document.Application.Create;
            Autodesk.Revit.Creation.Document    creDoc = uiDoc.Document.Create;
            Autodesk.Revit.DB.CurveArray        curves = creApp.NewCurveArray();
            //create rectangular curve: wall length: 60 , wall width: 40
            Line line1 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 0, 0),
                                        new Autodesk.Revit.DB.XYZ(0, 60, 0), true);
            Line line2 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 60, 0),
                                        new Autodesk.Revit.DB.XYZ(0, 60, 40), true);
            Line line3 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 60, 40),
                                        new Autodesk.Revit.DB.XYZ(0, 0, 40), true);
            Line line4 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(0, 0, 40),
                                        new Autodesk.Revit.DB.XYZ(0, 0, 0), true);

            curves.Append(line1);
            curves.Append(line2);
            curves.Append(line3);
            curves.Append(line4);
            //create wall
            creDoc.NewWall(curves, false);

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
        /// <summary>
        /// Create one temporary door instance with this family.
        /// </summary>
        /// <returns>the created door.</returns>
        private FamilyInstance CreateOneInstanceWithThisFamily()
        {
            Autodesk.Revit.DB.Document          doc    = m_app.ActiveUIDocument.Document;
            Autodesk.Revit.Creation.Document    creDoc = doc.Create;
            Autodesk.Revit.Creation.Application creApp = m_app.Application.Create;

            // get one level. A project has at least one level.
            Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).FirstElement() as Level;

            // create one wall as door's host
            Line wallCurve = Line.CreateBound(new Autodesk.Revit.DB.XYZ(0, 0, 0), new Autodesk.Revit.DB.XYZ(100, 0, 0));
            Wall host      = Wall.Create(doc, wallCurve, level.Id, false);

            doc.Regenerate();

            // door symbol.
            List <FamilySymbol> ffs = new List <FamilySymbol>();

            foreach (ElementId elementId in m_family.GetFamilySymbolIds())
            {
                ffs.Add((FamilySymbol)(m_app.ActiveUIDocument.Document.GetElement(elementId)));
            }
            FamilySymbol doorSymbol = ffs[0];

            // create the door
            FamilyInstance createdFamilyInstance = creDoc.NewFamilyInstance(new Autodesk.Revit.DB.XYZ(0, 0, 0), doorSymbol, host, level,
                                                                            StructuralType.NonStructural);

            doc.Regenerate();

            return(createdFamilyInstance);
        }
Exemple #3
0
        /// <summary>
        /// create truss in Revit
        /// </summary>
        /// <returns>new created truss</returns>
        public Autodesk.Revit.DB.Structure.Truss CreateTruss()
        {
            Autodesk.Revit.Creation.Document    createDoc = m_commandData.Application.ActiveUIDocument.Document.Create;
            Autodesk.Revit.Creation.Application createApp = m_commandData.Application.Application.Create;
            //sketchPlane
            Autodesk.Revit.DB.XYZ origin     = new Autodesk.Revit.DB.XYZ(0, 0, 0);
            Autodesk.Revit.DB.XYZ xDirection = new Autodesk.Revit.DB.XYZ(1, 0, 0);
            Autodesk.Revit.DB.XYZ yDirection = new Autodesk.Revit.DB.XYZ(0, 1, 0);
            Plane       plane       = createApp.NewPlane(xDirection, yDirection, origin);
            SketchPlane sketchPlane = createDoc.NewSketchPlane(plane);
            //new base Line
            AnalyticalModel frame1 = column1.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ centerPoint1 = (frame1.GetCurve() as Line).get_EndPoint(0);
            AnalyticalModel       frame2       = column2.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ  centerPoint2 = (frame2.GetCurve() as Line).get_EndPoint(0);
            Autodesk.Revit.DB.XYZ  startPoint   = new Autodesk.Revit.DB.XYZ(centerPoint1.X, centerPoint1.Y, 0);
            Autodesk.Revit.DB.XYZ  endPoint     = new Autodesk.Revit.DB.XYZ(centerPoint2.X, centerPoint2.Y, 0);
            Autodesk.Revit.DB.Line baseLine     = null;

            try
            { baseLine = createApp.NewLineBound(startPoint, endPoint); }
            catch (System.ArgumentException)
            { MessageBox.Show("Two column you selected are too close to create truss."); }

            return(createDoc.NewTruss(m_selectedTrussType, sketchPlane, baseLine));
        }
Exemple #4
0
        /// <summary>
        /// Create a new curve with the same
        /// geometry in the reverse direction.
        /// </summary>
        /// <param name="orig">The original curve.</param>
        /// <returns>The reversed curve.</returns>
        /// <throws cref="NotImplementedException">If the
        /// curve type is not supported by this utility.</throws>
        static Curve CreateReversedCurve(
            Autodesk.Revit.Creation.Application creapp,
            Curve orig)
        {
            if (!IsSupported(orig))
            {
                throw new NotImplementedException(
                          "CreateReversedCurve for type "
                          + orig.GetType().Name);
            }

            if (orig is Line)
            {
                return(Line.CreateBound(
                           orig.GetEndPoint(1),
                           orig.GetEndPoint(0)));
            }
            else if (orig is Arc)
            {
                return(Arc.Create(orig.GetEndPoint(1),
                                  orig.GetEndPoint(0),
                                  orig.Evaluate(0.5, true)));
            }
            else
            {
                throw new Exception(
                          "CreateReversedCurve - Unreachable");
            }
        }
        /// <summary>
        /// Set profile of truss
        /// </summary>
        /// <param name="commandData">object which contains reference of Revit Application</param>
        public void SetProfile(ExternalCommandData commandData)
        {
            if (m_topChord.Points.Count < 2)
            {
                TaskDialog.Show("Truss API", "Haven't drawn top chord"); return;
            }
            else if (m_bottomChord.Points.Count < 2)
            {
                TaskDialog.Show("Truss API", "Haven't drawn bottom chord"); return;
            }

            Autodesk.Revit.Creation.Document    createDoc = commandData.Application.ActiveUIDocument.Document.Create;
            Autodesk.Revit.Creation.Application createApp = commandData.Application.Application.Create;
            CurveArray curvesTop    = createApp.NewCurveArray();
            CurveArray curvesBottom = createApp.NewCurveArray();

            //get coordinates of top (bottom) chord from lineTool
            GetChordPoints(m_topChord, curvesTop, createApp);
            GetChordPoints(m_bottomChord, curvesBottom, createApp);
            try
            {
                //set profile by top curve and bottom curve drawn by user in picture box
                m_truss.SetProfile(curvesTop, curvesBottom);
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Truss API", ex.Message);
            }

            //re-calculate geometry info after truss profile changed
            GetTrussGeometryInfo();
            ClearChords();
        }
        public static void CreateDimensionElement(
            Document doc,
            Autodesk.Revit.ApplicationServices.Application app,
            Autodesk.Revit.DB.View view,
            XYZ p1,
            Reference r1,
            XYZ p2,
            Reference r2)
        {
            Autodesk.Revit.Creation.Application creApp = app.Create;
            Autodesk.Revit.Creation.Document    creDoc = doc.Create;
            ReferenceArray refArr = new ReferenceArray();

            refArr.Append(r1);
            refArr.Append(r2);

            Line        line = Line.CreateBound(p1, p2);
            Transaction t    = new Transaction(doc, "Dimension Two Walls");

            t.Start();

            Dimension dim = creDoc.NewDimension(doc.ActiveView, line, refArr);

            t.Commit();
        }
Exemple #7
0
        public Result Execute(ExternalCommandData commandData,
                              ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction trans = new Transaction(commandData.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.ExternalCommandRegistration");

            trans.Start();
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.Creation.Application creApp = uiDoc.Document.Application.Create;
            Autodesk.Revit.Creation.Document    creDoc = uiDoc.Document.Create;
            List <Curve> curves = new List <Curve>();
            //create rectangular curve: wall length: 60 , wall width: 40
            Line line1 = Line.CreateBound(new Autodesk.Revit.DB.XYZ(0, 0, 0),
                                          new Autodesk.Revit.DB.XYZ(0, 60, 0));
            Line line2 = Line.CreateBound(new Autodesk.Revit.DB.XYZ(0, 60, 0),
                                          new Autodesk.Revit.DB.XYZ(0, 60, 40));
            Line line3 = Line.CreateBound(new Autodesk.Revit.DB.XYZ(0, 60, 40),
                                          new Autodesk.Revit.DB.XYZ(0, 0, 40));
            Line line4 = Line.CreateBound(new Autodesk.Revit.DB.XYZ(0, 0, 40),
                                          new Autodesk.Revit.DB.XYZ(0, 0, 0));

            curves.Add(line1);
            curves.Add(line2);
            curves.Add(line3);
            curves.Add(line4);
            //create wall
            Wall.Create(uiDoc.Document, curves, false);

            trans.Commit();
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemple #8
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="revit">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(Autodesk.Revit.UI.ExternalCommandData revit,
                                                ref string message,
                                                ElementSet elements)
        {
            try
            {
                m_application = revit.Application.Application;
                m_document    = revit.Application.ActiveUIDocument.Document;

                // it can support in truss family document only
                if (!m_document.IsFamilyDocument ||
                    m_document.OwnerFamily.FamilyCategory.Id.IntegerValue != (int)BuiltInCategory.OST_Truss)
                {
                    message = "Cannot execute truss creation in non-truss family document";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                m_appCreator    = m_application.Create;
                m_familyCreator = m_document.FamilyCreate;

                Transaction newTran = new Transaction(m_document);
                newTran.Start("NewTrussCurve");

                // Start the truss creation
                MakeNewTruss();

                newTran.Commit();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return(Autodesk.Revit.UI.Result.Failed);
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
        private void GetChordPoints(LineTool chord, CurveArray curves, Autodesk.Revit.Creation.Application createApp)
        {
            //get coordinates of top chord from lineTool
            for (int i = 0; i < chord.Points.Count - 1; i++)
            {
                Point point  = (Point)chord.Points[i];
                Point point2 = (Point)chord.Points[i + 1];

                Autodesk.Revit.DB.XYZ xyz  = new Autodesk.Revit.DB.XYZ(point.X, point.Y, 0);
                Autodesk.Revit.DB.XYZ xyz2 = new Autodesk.Revit.DB.XYZ(point2.X, point2.Y, 0);

                Vector4 v1 = new Vector4(xyz);
                Vector4 v2 = new Vector4(xyz2);

                v1 = m_restoreMatrix.Transform(v1);
                v2 = m_restoreMatrix.Transform(v2);

                try
                {
                    Line line = Line.CreateBound(
                        new Autodesk.Revit.DB.XYZ(v1.X, v1.Y, v1.Z), new Autodesk.Revit.DB.XYZ(v2.X, v2.Y, v2.Z));
                    curves.Append(line);
                }
                catch (System.ArgumentException)
                {
                    TaskDialog.Show("Revit",
                                    "The start point and the end point of the line are too close, please re-draw it.");
                    ClearChords();
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Obtain all data which is necessary for generate floor.
        /// </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>
        public void ObtainData(ExternalCommandData commandData)
        {
            if (null == commandData)
            {
                throw new ArgumentNullException("commandData");
            }

            UIDocument doc = commandData.Application.ActiveUIDocument;

            m_document = doc.Document;
            ElementSet es = new ElementSet();

            foreach (ElementId elementId in doc.Selection.GetElementIds())
            {
                es.Insert(doc.Document.GetElement(elementId));
            }

            ElementSet walls = WallFilter(es);

            m_creApp = commandData.Application.Application.Create;
            Profile  = m_creApp.NewCurveArray();

            FilteredElementIterator iter = (new FilteredElementCollector(doc.Document))
                                           .OfClass(typeof(FloorType))
                                           .GetElementIterator();

            ObtainFloorTypes(iter);
            ObtainProfile(walls);
            ObtainLevel(walls);
            Generate2D();
            Structural = true;
        }
Exemple #11
0
        /// <summary>
        /// create truss in Revit
        /// </summary>
        /// <returns>new created truss</returns>
        public Autodesk.Revit.DB.Structure.Truss CreateTruss()
        {
            Autodesk.Revit.DB.Document          document  = m_commandData.Application.ActiveUIDocument.Document;
            Autodesk.Revit.Creation.Document    createDoc = document.Create;
            Autodesk.Revit.Creation.Application createApp = m_commandData.Application.Application.Create;
            //sketchPlane
            Autodesk.Revit.DB.XYZ origin     = new Autodesk.Revit.DB.XYZ(0, 0, 0);
            Autodesk.Revit.DB.XYZ xDirection = new Autodesk.Revit.DB.XYZ(1, 0, 0);
            Autodesk.Revit.DB.XYZ yDirection = new Autodesk.Revit.DB.XYZ(0, 1, 0);
            Plane       plane       = Plane.CreateByOriginAndBasis(xDirection, yDirection, origin);
            SketchPlane sketchPlane = SketchPlane.Create(document, plane);
            //new base Line
            AnalyticalModel frame1 = column1.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ centerPoint1 = (frame1.GetCurve() as Line).GetEndPoint(0);
            AnalyticalModel       frame2       = column2.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ  centerPoint2 = (frame2.GetCurve() as Line).GetEndPoint(0);
            Autodesk.Revit.DB.XYZ  startPoint   = new Autodesk.Revit.DB.XYZ(centerPoint1.X, centerPoint1.Y, 0);
            Autodesk.Revit.DB.XYZ  endPoint     = new Autodesk.Revit.DB.XYZ(centerPoint2.X, centerPoint2.Y, 0);
            Autodesk.Revit.DB.Line baseLine     = null;

            try
            { baseLine = Line.CreateBound(startPoint, endPoint); }
            catch (System.ArgumentException)
            {
                TaskDialog.Show("Argument Exception", "Two column you selected are too close to create truss.");
            }

            return(Autodesk.Revit.DB.Structure.Truss.Create(document, m_selectedTrussType.Id, sketchPlane.Id, baseLine));
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument    uiDoc = uiApp.ActiveUIDocument;

            _app   = uiApp.Application;
            _doc   = uiDoc.Document;
            creApp = commandData.Application.Application.Create;


            using (Transaction t = new Transaction(_doc))
            {
                t.Start("Create floor");
                CreateFloorInRooms();
                TaskDialog.Show("У тебя получилось", "Ты красавчик!☺☺☺");
                t.Commit();

                t.Start();
                CreateFloorOpenings();

                var res = t.Commit();
            }

            return(Result.Succeeded);
        }
Exemple #13
0
        /// <summary>
        /// Create one temporary door instance with this family.
        /// </summary>
        /// <returns>the created door.</returns>
        private FamilyInstance CreateOneInstanceWithThisFamily()
        {
            Autodesk.Revit.DB.Document          doc    = m_app.ActiveUIDocument.Document;
            Autodesk.Revit.Creation.Document    creDoc = doc.Create;
            Autodesk.Revit.Creation.Application creApp = m_app.Application.Create;

            // get one level. A project has at least one level.
            Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).FirstElement() as Level;

            // create one wall as door's host
            Line wallCurve = creApp.NewLineBound(new Autodesk.Revit.DB.XYZ(0, 0, 0), new Autodesk.Revit.DB.XYZ(100, 0, 0));
            Wall host      = creDoc.NewWall(wallCurve, level, false);

            doc.Regenerate();

            // door symbol.
            FamilySymbolSetIterator doorSymbolIter = m_family.Symbols.ForwardIterator();

            doorSymbolIter.MoveNext();
            FamilySymbol doorSymbol = doorSymbolIter.Current as FamilySymbol;

            // create the door
            FamilyInstance createdFamilyInstance = creDoc.NewFamilyInstance(new Autodesk.Revit.DB.XYZ(0, 0, 0), doorSymbol, host, level,
                                                                            StructuralType.NonStructural);

            doc.Regenerate();

            return(createdFamilyInstance);
        }
Exemple #14
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="element">element</param>
 public FaceExtractor(Element element)
 {
     _element    = element;
     _doc        = element.Document;
     _app        = _doc.Application;
     _appCreator = _app.Create;
     GetFaces();
 }
Exemple #15
0
        private WallCollection GetWallInformation(UIDocument uidoc, Document revitDoc, Application app, Wall wall, WallType WallType)
        {
            Autodesk.Revit.Creation.Document    credoc = revitDoc.Create;
            Autodesk.Revit.Creation.Application creapp = app.Create;
            View view = revitDoc.ActiveView;

            ElementType type  = WallType as ElementType;
            Parameter   b     = type.get_Parameter((BuiltInParameter.WALL_ATTR_WIDTH_PARAM));
            double      width = b.AsDouble() / 2;

            IList <Reference> sideFaces = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior);

            Element e2 = revitDoc.GetElement(sideFaces[0]);

            Face face = e2.GetGeometryObjectFromReference(sideFaces[0]) as Face;

            // The normal of the wall external face.
            XYZ normal = face.ComputeNormal(new UV(0, 0));

            // Offset curve copies for visibility.
            Transform offset = Transform.CreateTranslation(width * normal);

            // If the curve loop direction is counter-
            // clockwise, change its color to RED.


            // Get edge loops as curve loops.
            IList <CurveLoop> curveLoops = face.GetEdgesAsCurveLoops();

            // ExporterIFCUtils class can also be used for
            // non-IFC purposes. The SortCurveLoops method
            // sorts curve loops (edge loops) so that the
            // outer loops come first.
            IList <IList <CurveLoop> > curveLoopLoop = ExporterIFCUtils.SortCurveLoops(curveLoops);
            List <List <Curve> >       Walls         = new List <List <Curve> >();
            WallCollection             WCCC          = new WallCollection();

            foreach (IList <CurveLoop> curveLoops2 in curveLoopLoop)
            {
                foreach (CurveLoop curveLoop2 in curveLoops2)
                {
                    // Check if curve loop is counter-clockwise.

                    CurveArray   curves = creapp.NewCurveArray();
                    List <Curve> CC     = new List <Curve>();
                    foreach (Curve curve in curveLoop2)
                    {
                        curves.Append(curve.CreateTransformed(offset));
                        CC.Add(curve.CreateTransformed(offset));
                    }
                    // Create model lines for an curve loop.
                    Walls.Add(CC);
                    WCCC.AddWall(CC);
                }
            }

            return(WCCC);
        }
Exemple #16
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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
                                                        , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if (null == s_appCreation)
            {
                // share for class Intersection.
                s_appCreation = commandData.Application.Application.Create;
            }

            UIDocument             doc = commandData.Application.ActiveUIDocument;
            CombinableElementArray solids
                = new CombinableElementArray();

            ElementSet es = new ElementSet();

            foreach (ElementId elemId in es)
            {
                es.Insert(doc.Document.GetElement(elemId));
            }
            if (0 < es.Size)
            {
                foreach (Autodesk.Revit.DB.ElementId elementId in doc.Selection.GetElementIds())
                {
                    Autodesk.Revit.DB.Element element = doc.Document.GetElement(elementId);
                    System.Diagnostics.Trace.WriteLine(element.GetType().ToString());

                    GenericForm gf = element as GenericForm;
                    if (null != gf && !gf.IsSolid)
                    {
                        continue;
                    }

                    CombinableElement ce = element as CombinableElement;
                    if (null != ce)
                    {
                        solids.Append(ce);
                    }
                }

                if (solids.Size < 2)
                {
                    message = "At least 2 combinable elements should be selected.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                doc.Document.CombineElements(solids);

                //The selected generic forms are joined, whether or not they overlap.
                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            AutoJoin autojoin = new AutoJoin();

            autojoin.Join(doc.Document);
            //All overlapping generic forms are joined.

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
 public DbUpdater( UIApplication uiapp )
 {
   using( JtTimer pt = new JtTimer( "DbUpdater ctor" ) )
   {
     //_doc = doc;
     _uiapp = uiapp;
     _creapp = _uiapp.Application.Create;
   }
 }
Exemple #18
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            Autodesk.Revit.Creation.Application creApp
                = app.Application.Create;

            try
            {
                // find forms in the model:

                FilteredElementCollector forms = new FilteredElementCollector(doc);
                forms.OfCategory(BuiltInCategory.OST_MassForm); // was OST_MassSurface

                foreach (Form form in forms)
                {
                    // create the divided surface on the loft form:

                    FamilyItemFactory factory = doc.FamilyCreate;
                    Options           options = creApp.NewGeometryOptions();
                    options.ComputeReferences = true;
                    options.View = doc.ActiveView;
                    GeometryElement element = form.get_Geometry(options);

                    //GeometryObjectArray geoObjectArray = element.Objects; // 2012
                    //for( int j = 0; j < geoObjectArray.Size; j++ )
                    //{
                    //  GeometryObject geoObject = geoObjectArray.get_Item( j );

                    foreach (GeometryObject geoObject in element) // 2013
                    {
                        Solid solid = geoObject as Solid;
                        foreach (Face face in solid.Faces)
                        {
                            if (face.Reference != null)
                            {
                                if (null != face)
                                {
                                    //DividedSurface divSurface = factory.NewDividedSurface( face.Reference ); // 2013
                                    DividedSurface divSurface = DividedSurface.Create(doc, face.Reference); // 2014
                                }
                            }
                        }
                    }
                }
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Exemple #19
0
 /// <summary>
 /// Constructor, Store the Revit application
 /// </summary>
 /// <param name="app"></param>
 public FamilyInstanceCreator(Autodesk.Revit.UI.UIApplication app)
 {
     m_revitDoc = app.ActiveUIDocument;
     m_appCreator = app.Application.Create;
     if (!CheckSelectedElementSet())
     {
         throw new Exception("Please select an element with face geometry.");
     }
 }
        /// <summary>
        /// Create a room on a given level.
        /// </summary>
        void CreateRoom(
            Document doc,
            Level level)
        {
            Application app = doc.Application;

            Autodesk.Revit.Creation.Application
                appCreation = app.Create;

            Autodesk.Revit.Creation.Document
                docCreation = doc.Create;

            XYZ pt1 = new XYZ(0, -5, 0);
            XYZ pt2 = new XYZ(0, 5, 0);
            XYZ pt3 = new XYZ(8, 5, 0);
            XYZ pt4 = new XYZ(8, -5, 0);

            Line line1 = Line.CreateBound(pt1, pt2);
            Line line2 = Line.CreateBound(pt2, pt3);
            Line line3 = Line.CreateBound(pt3, pt4);
            Line line4 = Line.CreateBound(pt4, pt1);

            CurveArray curveArr = new CurveArray();

            curveArr.Append(line1);
            curveArr.Append(line2);
            curveArr.Append(line3);
            curveArr.Append(line4);

            docCreation.NewRoomBoundaryLines(
                doc.ActiveView.SketchPlane,
                curveArr, doc.ActiveView);

            // Create a new room

            UV tagPoint = new UV(4, 0);

            Room room = docCreation.NewRoom(
                level, tagPoint);

            if (null == room)
            {
                throw new Exception(
                          "Create a new room failed.");
            }
            room.Number = "42";
            room.Name   = "Lobby";

            // Creation.Document.NewRoomTag( Room, UV, View) is obsolete.
            // Use the NewRoomTag(LinkElementId, UV, ElementId) overload instead.

            //RoomTag tag = docCreation.NewRoomTag( room, tagPoint, doc.ActiveView ); // 2013

            RoomTag tag = docCreation.NewRoomTag(
                new LinkElementId(room.Id), tagPoint,
                doc.ActiveView.Id); // 2014
        }
Exemple #21
0
 public DbUpdater(UIApplication uiapp)
 {
     using (JtTimer pt = new JtTimer("DbUpdater ctor"))
     {
         //_doc = doc;
         _uiapp  = uiapp;
         _creapp = _uiapp.Application.Create;
     }
 }
Exemple #22
0
 /// <summary>
 /// Constructor, Store the Revit application
 /// </summary>
 /// <param name="app"></param>
 public FamilyInstanceCreator(Autodesk.Revit.UI.UIApplication app)
 {
     m_revitDoc   = app.ActiveUIDocument;
     m_appCreator = app.Application.Create;
     if (!CheckSelectedElementSet())
     {
         throw new Exception("Please select an element with face geometry.");
     }
 }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;

            Autodesk.Revit.Creation.Application ac
                = app.Application.Create;

            //CurveArray profile = ac.NewCurveArray(); // 2012
            List <Curve> profile = new List <Curve>(4); // 2012

            double length      = 10;
            double heightStart = 5;
            double heightEnd   = 8;

            XYZ p = XYZ.Zero;
            XYZ q = ac.NewXYZ(length, 0.0, 0.0);

            //profile.Append( ac.NewLineBound( p, q ) ); // 2012
            profile.Add(Line.CreateBound(p, q)); // 2014

            p  = q;
            q += heightEnd * XYZ.BasisZ;

            //profile.Append( ac.NewLineBound( p, q ) ); // 2012
            profile.Add(Line.CreateBound(p, q)); // 2014

            p = q;
            q = ac.NewXYZ(0.0, 0.0, heightStart);

            //profile.Append( ac.NewLineBound( p, q ) ); // 2012
            //profile.Add( ac.NewLineBound( p, q ) ); // 2013
            profile.Add(Line.CreateBound(p, q)); // 2014

            p = q;
            q = XYZ.Zero;

            //profile.Append( ac.NewLineBound( p, q ) ); // 2012
            //profile.Add( ac.NewLineBound( p, q ) ); // 2013
            profile.Add(Line.CreateBound(p, q)); // 2014

            Document doc = app.ActiveUIDocument.Document;

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create Sloped Wall");

                //Wall wall = doc.Create.NewWall( profile, false ); // 2012
                Wall wall = Wall.Create(doc, profile, false); // 2013

                t.Commit();
            }
            return(Result.Succeeded);
        }
Exemple #24
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="revit">An application object that contains data related to revit command.</param>
 public SlabData(UIApplication revit)
 {
     m_revit = revit;
     CreApp = m_revit.Application.Create;
     // Find out all useful elements.
     FindElements();
     // Get all base slabs. If no slab be found, throw an exception and return cancel.
     if (!GetAllBaseSlabs())
         throw new NullReferenceException("No planar slabs at the base of the building.");
 }
Exemple #25
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="elem">Selected element</param>
        /// <param name="commandData">ExternalCommandData</param>
        public Profile(Autodesk.Revit.DB.Element elem, ExternalCommandData commandData)
        {
            m_dataProfile = elem;
            m_commandData = commandData;
            m_appCreator  = m_commandData.Application.Application.Create;
            m_docCreator  = m_commandData.Application.ActiveUIDocument.Document.Create;

            List <List <Edge> > faces = GetFaces(m_dataProfile);

            m_face = GetNeedFace(faces);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication uiapp = commandData.Application;
            Autodesk.Revit.UI.UIDocument    uidoc = uiapp.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Autodesk.Revit.DB.Document doc = uidoc.Document;

            // Build a wall profile for the wall creation
            XYZ[] pts = new XYZ[] {
                XYZ.Zero,
                new XYZ(20, 0, 0),
                new XYZ(20, 0, 15),
                new XYZ(10, 0, 30),
                new XYZ(0, 0, 15)
            };

            // Get application creation object
            Autodesk.Revit.Creation.Application appCreation = app.Create;

            // Create wall profile
            CurveArray profile = new CurveArray();
            XYZ        q       = pts[pts.Length - 1];

            foreach (XYZ p in pts)
            {
                profile.Append(appCreation.NewLineBound(q, p));
                q = p;
            }

            XYZ normal = XYZ.BasisY;

            WallType wallType
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(WallType))
                  .First <Element>()
                  as WallType;

            Level level
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(Level))
                  .First <Element>(e
                                   => e.Name.Equals("Level 1"))
                  as Level;

            Transaction trans = new Transaction(doc);

            trans.Start("Test Gable Wall");
            Wall wall = doc.Create.NewWall(profile, wallType, level, true, normal);

            trans.Commit();

            return(Result.Succeeded);
        }
Exemple #27
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="revit">An application object that contains data related to revit command.</param>
 public SlabData(UIApplication revit)
 {
     m_revit = revit;
     CreApp  = m_revit.Application.Create;
     // Find out all useful elements.
     FindElements();
     // Get all base slabs. If no slab be found, throw an exception and return cancel.
     if (!GetAllBaseSlabs())
     {
         throw new NullReferenceException("No planar slabs at the base of the building.");
     }
 }
        protected List <Curve> GetCircleWallShape(Autodesk.Revit.Creation.Application creApp)
        {
            //calculate size of Structural and NonStructural walls
            int          WallsSize = CreateStructureWall.CreatedWalls.Size + CreatedWalls.Size;
            List <Curve> curves    = new List <Curve>();
            //15: distance from each wall, 40: diameter of circle
            Arc arc  = Arc.Create(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 20));
            Arc arc2 = Arc.Create(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 20));

            curves.Add(arc);
            curves.Add(arc2);
            return(curves);
        }
Exemple #29
0
        Autodesk.Revit.Creation.Document m_docCreator; // buffer of API object

        #endregion Fields

        #region Constructors

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="data">data necessary to initialize object</param>
        public FrameBuilder(FrameData data)
        {
            // initialize members
            if (null == data)
            {
                throw new ArgumentNullException("data",
                    "constructor FrameBuilder(FrameData data)'s parameter shouldn't be null ");
            }
            m_data = data;

            m_appCreator = data.CommandData.Application.Application.Create;
            m_docCreator = data.CommandData.Application.ActiveUIDocument.Document.Create;
        }
Exemple #30
0
        Autodesk.Revit.Creation.Application m_appCreator; // buffer of API object

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="data">data necessary to initialize object</param>
        public FrameBuilder(FrameData data)
        {
            // initialize members
            if (null == data)
            {
                throw new ArgumentNullException("data",
                                                "constructor FrameBuilder(FrameData data)'s parameter shouldn't be null ");
            }
            m_data = data;

            m_appCreator = data.CommandData.Application.Application.Create;
            m_docCreator = data.CommandData.Application.ActiveUIDocument.Document.Create;
        }
        /// <summary>
        /// External command mainline method for non-VSTA solution.
        /// </summary>
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            Create = app.Application.Create;

            return(NewSpotElevation(doc)
        ? Result.Succeeded
        : Result.Failed);
        }
Exemple #32
0
        protected CurveArray GetTriangleWallShape(Autodesk.Revit.Creation.Application creApp)
        {
            //calculate size of Structural and NonStructural walls
            int        WallsSize = CreateStructureWall.CreatedWalls.Size + CreatedWalls.Size;
            CurveArray curves    = creApp.NewCurveArray();
            //15: distance from each wall, 40: height of triangle
            Line line1 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 0), true);
            Line line2 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40), true);
            Line line3 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 0), true);

            curves.Append(line1);
            curves.Append(line2);
            curves.Append(line3);
            return(curves);
        }
        protected List <Curve> GetTriangleWallShape(Autodesk.Revit.Creation.Application creApp)
        {
            //calculate size of Structural and NonStructural walls
            int          WallsSize = CreateStructureWall.CreatedWalls.Size + CreatedWalls.Size;
            List <Curve> curves    = new List <Curve>();
            //15: distance from each wall, 40: height of triangle
            Line line1 = Line.CreateBound(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 0));
            Line line2 = Line.CreateBound(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 0), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40));
            Line line3 = Line.CreateBound(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 20, 40), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 0));

            curves.Add(line1);
            curves.Add(line2);
            curves.Add(line3);
            return(curves);
        }
Exemple #34
0
 /// <summary>
 /// Creates a new CurvedStairsRunConfiguration at the specified location and orientation.
 /// </summary>
 /// <param name="riserNumber">The number of risers in the run.</param>
 /// <param name="bottomElevation">The bottom elevation.</param>
 /// <param name="desiredTreadDepth">The desired tread depth.</param>
 /// <param name="width">The width.</param>
 /// <param name="innerRadius">The radius of the innermost edge of the run.</param>
 /// <param name="appCreate">The Revit API application creation object.</param>
 /// <param name="transform">The transformation (location and orientation).</param>
 public CurvedStairsRunComponent(int riserNumber, double bottomElevation,
                                 double desiredTreadDepth, double width,
                                 double innerRadius, Autodesk.Revit.Creation.Application appCreate,
                                 Transform transform) :
     base(transform)
 {
     m_riserNumber       = riserNumber;
     m_bottomElevation   = bottomElevation;
     m_innerRadius       = innerRadius;
     m_outerRadius       = innerRadius + width;
     m_incrementAngle    = desiredTreadDepth / (m_innerRadius + width / 2.0);
     m_includedAngle     = m_incrementAngle * (riserNumber - 1);
     m_desiredTreadDepth = desiredTreadDepth;
     m_center            = new XYZ(0, 0, bottomElevation);
     m_appCreate         = appCreate;
 }
Exemple #35
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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
            , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if (null == s_appCreation)
            {
                // share for class Intersection.
                s_appCreation = commandData.Application.Application.Create;
            }

            UIDocument doc = commandData.Application.ActiveUIDocument;
            CombinableElementArray solids
                = new CombinableElementArray();

            if (0 < doc.Selection.Elements.Size)
            {
                foreach (Autodesk.Revit.DB.Element element in doc.Selection.Elements)
                {
                    System.Diagnostics.Trace.WriteLine(element.GetType().ToString());

                    GenericForm gf = element as GenericForm;
                    if (null != gf && !gf.IsSolid)
                        continue;

                    CombinableElement ce = element as CombinableElement;
                    if (null != ce)
                        solids.Append(ce);
                }

                if (solids.Size < 2)
                {
                    message = "At least 2 combinable elements should be selected.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                doc.Document.CombineElements(solids);

                //The selected generic forms are joined, whether or not they overlap.
                return Autodesk.Revit.UI.Result.Succeeded;
            }

            AutoJoin autojoin = new AutoJoin();
            autojoin.Join(doc.Document);
            //All overlapping generic forms are joined.

            return Autodesk.Revit.UI.Result.Succeeded;
        }
Exemple #36
0
        List<SketchPlane> m_sketchArray; // Store the SketchPlane references

        #endregion Fields

        #region Constructors

        /// <summary>
        /// The default constructor
        /// </summary>
        /// <param name="revit">The reference of the application in revit</param>
        public ModelLines(Autodesk.Revit.UI.UIApplication revit)
        {
            // Store the reference of the application for further use.
            m_revit = revit;
            // Get the create references
            m_createApp = m_revit.Application.Create;       // Creation.Application
            m_createDoc = m_revit.ActiveUIDocument.Document.Create;// Creation.Document

            // Construct all the ModelCurveArray instances for model lines
            m_lineArray = new ModelCurveArray();
            m_arcArray = new ModelCurveArray();
            m_ellipseArray = new ModelCurveArray();
            m_hermiteArray = new ModelCurveArray();
            m_nurbArray = new ModelCurveArray();

            // Construct the sketch plane list data
            m_sketchArray = new List<SketchPlane>();

            // Construct the information list data
            m_informationMap = new List<ModelCurveCounter>();
        }
Exemple #37
0
        /// <summary>
        /// Obtain all data which is necessary for generate floor.
        /// </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>
        public void ObtainData(ExternalCommandData commandData)
        {
            if (null == commandData)
            {
                throw new ArgumentNullException("commandData");
            }

            UIDocument doc = commandData.Application.ActiveUIDocument;
            ElementSet walls = WallFilter(doc.Selection.Elements);
            m_creApp = commandData.Application.Application.Create;
            Profile = m_creApp.NewCurveArray();

            FilteredElementIterator iter = (new FilteredElementCollector(doc.Document)).OfClass(typeof(FloorType)).GetElementIterator();
            ObtainFloorTypes(iter);
            ObtainProfile(walls);
            ObtainLevel(walls);
            Generate2D();
            Structural = true;
        }
        /// <summary>
        /// Creates a SimpleSweptSolidAnalyzer and computes the swept solid.
        /// </summary>
        /// <param name="solid">The solid geometry.</param>
        /// <param name="normal">The normal of the reference plane that a path might lie on.</param>
        /// <returns>The analyzer.</returns>
        public static SimpleSweptSolidAnalyzer Create(Autodesk.Revit.Creation.Application creation, Solid solid, XYZ normal)
        {
            if (solid == null || normal == null)
                throw new ArgumentNullException();

            m_appCreation = creation;

            ICollection<Face> faces = new List<Face>();
            foreach (Face face in solid.Faces)
            {
                faces.Add(face);
            }
            return Create(faces, normal);
        }
Exemple #39
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="elem">Selected element</param>
        /// <param name="commandData">ExternalCommandData</param>
        public Profile(Autodesk.Revit.DB.Element elem, ExternalCommandData commandData)
        {
            m_dataProfile = elem;
            m_commandData = commandData;
            m_appCreator = m_commandData.Application.Application.Create;
            m_docCreator = m_commandData.Application.ActiveUIDocument.Document.Create;

            List<List<Edge>> faces = GetFaces(m_dataProfile);
            m_face = GetNeedFace(faces);
        }
 public Creator( Document doc )
 {
     _doc = doc;
       _credoc = doc.Create;
       _creapp = doc.Application.Create;
 }
Exemple #41
0
 /// <summary>
 /// The constructor of CreateExtrusion
 /// </summary>
 /// <param name="app">the application</param>
 /// <param name="doc">the document</param>
 public CreateExtrusion(Application app, Document doc)
 {
     m_document = doc;
     m_appCreator = app.Create;
     m_familyCreator = doc.FamilyCreate;
 }
Exemple #42
0
 /// <summary>
 /// The construct of ExtrusionRoofManager class.
 /// </summary>
 /// <param name="commandData">A reference to the commandData.</param>
 public ExtrusionRoofManager(ExternalCommandData commandData)
 {
     m_commandData = commandData;
     m_creationDoc = m_commandData.Application.ActiveUIDocument.Document.Create;
     m_creationApp = m_commandData.Application.Application.Create;
 }
Exemple #43
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="commandData">object which contains reference to Revit Application</param>
 protected Profile(ExternalCommandData commandData)
 {
     m_commandData = commandData;
     m_appCreator = m_commandData.Application.Application.Create;
     m_docCreator = m_commandData.Application.ActiveUIDocument.Document.Create;
 }
Exemple #44
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="revit">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(Autodesk.Revit.UI.ExternalCommandData revit,
                                                              ref string message,
                                                              ElementSet elements)
        {
            try
            {
                m_application = revit.Application.Application;
                m_document = revit.Application.ActiveUIDocument.Document;

                // it can support in truss family document only
                if (!m_document.IsFamilyDocument
                    || m_document.OwnerFamily.FamilyCategory.Id.IntegerValue != (int)BuiltInCategory.OST_Truss)
                {
                    message = "Cannot execute truss creation in non-truss family document";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                m_appCreator = m_application.Create;
                m_familyCreator = m_document.FamilyCreate;

                Transaction newTran = new Transaction(m_document);
                newTran.Start("NewTrussCurve");

                // Start the truss creation
                MakeNewTruss();

                newTran.Commit();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return Autodesk.Revit.UI.Result.Failed;
            }
            return Autodesk.Revit.UI.Result.Succeeded;
        }