Exemplo n.º 1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                m_application = commandData.Application.Application;
                m_document    = commandData.Application.ActiveUIDocument.Document;


                if (!m_document.IsFamilyDocument)
                {
                    message = "无法在非族类文档中使用";
                    return(Result.Failed);
                }


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

                Transaction trans = new Transaction(m_document);
                trans.Start("创建新曲线");

                MakeNewCurve();

                //commandData.Application.ActiveUIDocument.Selection.PickPoint

                trans.Commit();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return(Result.Failed);
            }
            return(Result.Succeeded);
        }
Exemplo n.º 2
0
        /// <summary>
        /// create the extrusions of the air handler system
        /// </summary>
        private void CreateExtrusions()
        {
            Autodesk.Revit.Creation.Application app = m_application.Create;
            CurveArray    curves      = null;
            CurveArrArray profile     = null;
            Plane         plane       = null;
            SketchPlane   sketchPlane = null;

            #region Create the cuboid extrusions

            for (int i = 0; i <= 2; ++i)
            {
                // create the profile
                curves = app.NewCurveArray();
                curves.Append(Line.CreateBound(profileData[i, 0], profileData[i, 1]));
                curves.Append(Line.CreateBound(profileData[i, 1], profileData[i, 2]));
                curves.Append(Line.CreateBound(profileData[i, 2], profileData[i, 3]));
                curves.Append(Line.CreateBound(profileData[i, 3], profileData[i, 0]));
                profile = app.NewCurveArrArray();
                profile.Append(curves);

                // create the sketch plane
                plane       = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]);
                sketchPlane = SketchPlane.Create(m_document, plane);

                // create the extrusion
                extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane,
                                               extrusionOffsets[i, 1]);
                extrusions[i].StartOffset = extrusionOffsets[i, 0];
                m_combineElements.Append(extrusions[i]);
            }

            #endregion

            #region Create the round extrusions

            for (int i = 3; i <= 4; ++i)
            {
                // create the profile
                profile = app.NewCurveArrArray();

                curves = app.NewCurveArray();
                plane  = Plane.CreateByNormalAndOrigin(profileData[i, 0], profileData[i, 1]);
                curves.Append(Arc.Create(plane, arcRadius, 0, Math.PI * 2));
                profile.Append(curves);

                // create the sketch plane
                plane       = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]);
                sketchPlane = SketchPlane.Create(m_document, plane);

                // create the extrusion
                extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane,
                                               extrusionOffsets[i, 1]);
                extrusions[i].StartOffset = extrusionOffsets[i, 0];
                m_combineElements.Append(extrusions[i]);
            }

            #endregion
        }
Exemplo n.º 3
0
        /// <summary>
        /// Batch creation of Walls
        /// </summary>
        /// <returns>If batch creation succeeds, return true; otherwise, return false</returns>
        private bool CreateWalls()
        {
            try
            {
                if (null == m_level)
                {
                    return(false);
                }

                Autodesk.Revit.Creation.Application appCreation = m_cmdData.Application.Application.Create;
                for (int i = 1; i < 11; i++)
                {
                    // Create wall's profile which is a combination of rectangle and arc

                    IList <Curve> curveArray = new List <Curve>();
                    // Create three lines for rectangle part of profile.
                    Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(i * 10, -80, 15);
                    Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(i * 10, -80, 0);
                    Autodesk.Revit.DB.XYZ pt3 = new Autodesk.Revit.DB.XYZ(i * 10, -90, 0);
                    Autodesk.Revit.DB.XYZ pt4 = new Autodesk.Revit.DB.XYZ(i * 10, -90, 15);
                    Line line1 = Line.CreateBound(pt1, pt2);
                    Line line2 = Line.CreateBound(pt2, pt3);
                    Line line3 = Line.CreateBound(pt3, pt4);

                    // Create arc part of profile.
                    Autodesk.Revit.DB.XYZ pointInCurve = new Autodesk.Revit.DB.XYZ(i * 10, -85, 20);
                    Arc arc = Arc.Create(pt4, pt1, pointInCurve);

                    if (null == line1 || null == line2 || null == line3 || null == arc)
                    {
                        continue;
                    }
                    curveArray.Add(line1);
                    curveArray.Add(line2);
                    curveArray.Add(line3);
                    curveArray.Add(arc);
                    Wall.Create(m_doc, curveArray, true);
                }

                for (int i = 1; i < 11; i++)
                {
                    Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(i * 10, -110, 0);
                    Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(i * 10, -120, 0);
                    Line line = Line.CreateBound(pt1, pt2);
                    Wall.Create(m_doc, line, m_level.Id, true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        private void CreateWall()
        {
            RevitCreation.Application createApp = m_commandData.Application.Application.Create;
            RevitCreation.Document    createDoc = m_commandData.Application.ActiveUIDocument.Document.Create;

            RevitDB.Line geometryLine = RevitDB.Line.CreateBound(m_startPoint, m_endPoint);
            if (null == geometryLine)
            {
                throw new Exception("Create the geometry line failed.");
            }

            RevitDB.Wall createdWall = RevitDB.Wall.Create(m_commandData.Application.ActiveUIDocument.Document,
                                                           geometryLine, m_createType.Id, m_createlevel.Id,
                                                           15, m_startPoint.Z + m_createlevel.Elevation, true, true);
            if (null == createdWall)
            {
                throw new Exception("Create the wall failed.");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a wall with the collected data or the data read from journal
        /// </summary>
        private void CreateWall()
        {
            // Get the create classes.
            Creation.Application createApp = m_commandData.Application.Application.Create;
            Creation.Document    createDoc = m_commandData.Application.ActiveUIDocument.Document.Create;

            // Create geometry line(curve)
            Line geometryLine = Line.CreateBound(m_startPoint, m_endPoint);

            if (null == geometryLine)           // assert the creation is successful
            {
                throw new Exception("Create the geometry line failed.");
            }

            // Create the wall using the wall type, level and created geometry line
            Wall createdWall = Wall.Create(m_commandData.Application.ActiveUIDocument.Document, geometryLine, m_createType.Id, m_createlevel.Id,
                                           15, m_startPoint.Z + m_createlevel.Elevation, true, true);

            if (null == createdWall)            // assert the creation is successful
            {
                throw new Exception("Create the wall failed.");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get common informations for batch creation
        /// </summary>
        private void PreCreate()
        {
            try
            {
                Autodesk.Revit.Creation.Application appCreation = m_cmdData.Application.Application.Create;

                //Try to get Level named "Level 1" which will be used in most creations
                m_level = (from elem in
                           new FilteredElementCollector(m_doc).OfClass(typeof(Level)).ToElements()
                           let level = elem as Level
                                       where level != null && "Level 1" == level.Name
                                       select level).First();

                //If ViewPlan "Level 1" does not exist, try to create one.
                if (null != m_level)
                {
                    ElementId AreaSchemeId = new FilteredElementCollector(m_doc).OfClass(typeof(AreaScheme)).FirstOrDefault(a => a.Name == "Rentable").Id;
                    try
                    {
                        m_viewPlan      = ViewPlan.CreateAreaPlan(m_doc, AreaSchemeId, m_level.Id);
                        m_viewPlan.Name = "Level 1";
                    }
                    catch
                    {
                    }
                }

                if (null == m_level && null == m_viewPlan)
                {
                    return;
                }



                //List of Curve is used to store Area's boundary lines
                List <Curve> curves = new List <Curve>();

                Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(-4, 95, 0);
                Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(-106, 95, 0);
                Line line = Line.CreateBound(pt1, pt2);
                curves.Add(line);
                pt1  = new Autodesk.Revit.DB.XYZ(-4, 105, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(-106, 105, 0);
                line = Line.CreateBound(pt1, pt2);
                curves.Add(line);


                for (int i = 0; i < 11; i++)
                {
                    pt1  = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 94, 0);
                    pt2  = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 106, 0);
                    line = Line.CreateBound(pt1, pt2);
                    if (null != line)
                    {
                        curves.Add(line);
                    }
                }

                // Create Area Boundary Line for Area
                // It is necessary if need to create closed region for Area
                // But for Room, it is not necessary.
                Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, 0);
                Autodesk.Revit.DB.XYZ norm   = new Autodesk.Revit.DB.XYZ(0, 0, 1);
                Plane plane = appCreation.NewPlane(norm, origin);
                if (null != plane)
                {
                    SketchPlane sketchPlane = SketchPlane.Create(m_doc, plane);
                    if (null != sketchPlane)
                    {
                        foreach (Curve curve in curves)
                        {
                            m_doc.Create.NewAreaBoundaryLine(sketchPlane, curve, m_viewPlan);
                        }
                    }
                }


                //Create enclosed region using Walls for Room
                pt1  = new Autodesk.Revit.DB.XYZ(5, -5, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(55, -5, 0);
                line = Line.CreateBound(pt1, pt2);
                Wall.Create(m_doc, line, m_level.Id, true);

                pt1  = new Autodesk.Revit.DB.XYZ(5, 5, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(55, 5, 0);
                line = Line.CreateBound(pt1, pt2);
                Wall.Create(m_doc, line, m_level.Id, true);

                for (int i = 0; i < 6; i++)
                {
                    pt1  = new Autodesk.Revit.DB.XYZ(5 + i * 10, -5, 0);
                    pt2  = new Autodesk.Revit.DB.XYZ(5 + i * 10, 5, 0);
                    line = Line.CreateBound(pt1, pt2);
                    Wall.Create(m_doc, line, m_level.Id, true);
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Batch creation of Walls
        /// </summary>
        /// <returns>If batch creation succeeds, return true; otherwise, return false</returns>
        private bool CreateWalls()
        {
            try
            {
                if (null == m_level)
                {
                    return(false);
                }

                //Create ProfiledWallCreationData for Walls' batch creation
                List <ProfiledWallCreationData>     profiledWallCreationDatas = new List <ProfiledWallCreationData>();
                Autodesk.Revit.Creation.Application appCreation = m_cmdData.Application.Application.Create;
                for (int i = 1; i < 11; i++)
                {
                    // Create wall's profile which is a combination of rectangle and arc
                    CurveArray curveArray = appCreation.NewCurveArray();

                    // Create three lines for rectangle part of profile.
                    Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(i * 10, -80, 15);
                    Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(i * 10, -80, 0);
                    Autodesk.Revit.DB.XYZ pt3 = new Autodesk.Revit.DB.XYZ(i * 10, -90, 0);
                    Autodesk.Revit.DB.XYZ pt4 = new Autodesk.Revit.DB.XYZ(i * 10, -90, 15);
                    Line line1 = appCreation.NewLine(pt1, pt2, true);
                    Line line2 = appCreation.NewLine(pt2, pt3, true);
                    Line line3 = appCreation.NewLine(pt3, pt4, true);

                    // Create arc part of profile.
                    Autodesk.Revit.DB.XYZ pointInCurve = new Autodesk.Revit.DB.XYZ(i * 10, -85, 20);
                    Arc arc = appCreation.NewArc(pt4, pt1, pointInCurve);

                    if (null == line1 || null == line2 || null == line3 || null == arc)
                    {
                        continue;
                    }
                    curveArray.Append(line1);
                    curveArray.Append(line2);
                    curveArray.Append(line3);
                    curveArray.Append(arc);

                    ProfiledWallCreationData profiledWallCreationData = new ProfiledWallCreationData(curveArray, true);
                    if (null != profiledWallCreationData)
                    {
                        profiledWallCreationDatas.Add(profiledWallCreationData);
                    }
                }

                //Create RectangularWallCreationData for Walls' batch creation
                List <RectangularWallCreationData> rectangularWallCreationDatas = new List <RectangularWallCreationData>();
                for (int i = 1; i < 11; i++)
                {
                    Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(i * 10, -110, 0);
                    Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(i * 10, -120, 0);
                    Line line = appCreation.NewLine(pt1, pt2, true);
                    RectangularWallCreationData rectangularWallCreationData = null;
                    if (null != line)
                    {
                        rectangularWallCreationData = new RectangularWallCreationData(line, m_level, true);
                    }
                    if (null != rectangularWallCreationData)
                    {
                        rectangularWallCreationDatas.Add(rectangularWallCreationData);
                    }
                }

                // Create Walls
                if (0 == profiledWallCreationDatas.Count || 0 == rectangularWallCreationDatas.Count)
                {
                    return(false);
                }
                m_doc.Create.NewWalls(profiledWallCreationDatas);
                m_doc.Create.NewWalls(rectangularWallCreationDatas);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get common informations for batch creation
        /// </summary>
        private void PreCreate()
        {
            try
            {
                Autodesk.Revit.Creation.Application appCreation = m_cmdData.Application.Application.Create;

                //Try to get Level named "Level 1" which will be used in most creations
                m_level = (from elem in
                           new FilteredElementCollector(m_doc).OfClass(typeof(Level)).ToElements()
                           let level = elem as Level
                                       where level != null && "Level 1" == level.Name
                                       select level).First();

                //If ViewPlan "Level 1" does not exist, try to create one.
                if (null != m_level)
                {
                    try
                    {
                        m_viewPlan = m_doc.Create.NewAreaViewPlan("Level 1", m_level, AreaElemType.BOMAArea);
                    }
                    catch
                    {
                    }
                }

                if (null == m_level && null == m_viewPlan)
                {
                    return;
                }

                //Create RectangularWallCreationData for Walls' batch creation
                List <RectangularWallCreationData> rectangularWallCreationDatas = new List <RectangularWallCreationData>();

                //List of Curve is used to store Area's boundary lines
                List <Curve> curves = new List <Curve>();

                Autodesk.Revit.DB.XYZ pt1 = new Autodesk.Revit.DB.XYZ(-4, 95, 0);
                Autodesk.Revit.DB.XYZ pt2 = new Autodesk.Revit.DB.XYZ(-106, 95, 0);
                Line line = appCreation.NewLine(pt1, pt2, true);
                RectangularWallCreationData rectangularWallCreationData = null;
                if (null != line)
                {
                    rectangularWallCreationData = new RectangularWallCreationData(line, m_level, true);
                    curves.Add(line);
                }
                if (null != rectangularWallCreationData)
                {
                    rectangularWallCreationDatas.Add(rectangularWallCreationData);
                }

                pt1  = new Autodesk.Revit.DB.XYZ(-4, 105, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(-106, 105, 0);
                line = appCreation.NewLine(pt1, pt2, true);
                if (null != line)
                {
                    rectangularWallCreationData = new RectangularWallCreationData(line, m_level, true);
                    curves.Add(line);
                }
                if (null != rectangularWallCreationData)
                {
                    rectangularWallCreationDatas.Add(rectangularWallCreationData);
                }

                for (int i = 0; i < 11; i++)
                {
                    pt1  = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 94, 0);
                    pt2  = new Autodesk.Revit.DB.XYZ(-5 - i * 10, 106, 0);
                    line = appCreation.NewLine(pt1, pt2, true);
                    if (null != line)
                    {
                        rectangularWallCreationData = new RectangularWallCreationData(line, m_level, true);
                        curves.Add(line);
                    }
                    if (null != rectangularWallCreationData)
                    {
                        rectangularWallCreationDatas.Add(rectangularWallCreationData);
                    }
                }

                // Create Area Boundary Line for Area
                // It is necessary if need to create closed region for Area
                // But for Room, it is not necessary.
                Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, 0);
                Autodesk.Revit.DB.XYZ norm   = new Autodesk.Revit.DB.XYZ(0, 0, 1);
                Plane plane = appCreation.NewPlane(norm, origin);
                if (null != plane)
                {
                    SketchPlane sketchPlane = m_doc.Create.NewSketchPlane(plane);
                    if (null != sketchPlane)
                    {
                        foreach (Curve curve in curves)
                        {
                            m_doc.Create.NewAreaBoundaryLine(sketchPlane, curve, m_viewPlan);
                        }
                    }
                }


                //Create enclosed region using Walls for Room
                pt1  = new Autodesk.Revit.DB.XYZ(5, -5, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(55, -5, 0);
                line = appCreation.NewLine(pt1, pt2, true);
                rectangularWallCreationData = null;
                if (null != line)
                {
                    rectangularWallCreationData = new RectangularWallCreationData(line, m_level, true);
                }
                if (null != rectangularWallCreationData)
                {
                    rectangularWallCreationDatas.Add(rectangularWallCreationData);
                }

                pt1  = new Autodesk.Revit.DB.XYZ(5, 5, 0);
                pt2  = new Autodesk.Revit.DB.XYZ(55, 5, 0);
                line = appCreation.NewLine(pt1, pt2, true);
                if (null != line)
                {
                    rectangularWallCreationData = new RectangularWallCreationData(line, m_level, true);
                }
                if (null != rectangularWallCreationData)
                {
                    rectangularWallCreationDatas.Add(rectangularWallCreationData);
                }

                for (int i = 0; i < 6; i++)
                {
                    pt1  = new Autodesk.Revit.DB.XYZ(5 + i * 10, -5, 0);
                    pt2  = new Autodesk.Revit.DB.XYZ(5 + i * 10, 5, 0);
                    line = appCreation.NewLine(pt1, pt2, true);
                    if (null != line)
                    {
                        rectangularWallCreationData = new RectangularWallCreationData(line, m_level, true);
                    }
                    if (null != rectangularWallCreationData)
                    {
                        rectangularWallCreationDatas.Add(rectangularWallCreationData);
                    }
                }

                // Call Wall batch creation method to create Walls
                m_doc.Create.NewWalls(rectangularWallCreationDatas);
            }
            catch (Exception)
            {
            }
        }