/// <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 = app.NewPlane(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 = new Plane(profileData[i, 0], profileData[i, 1]); curves.Append(Arc.Create(plane, arcRadius, 0, Math.PI * 2)); profile.Append(curves); // create the sketch plane plane = app.NewPlane(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 }
/// <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) { } }
/// <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) { } }