public IExternalCommand.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application revit = commandData.Application; Document curDoc = revit.ActiveDocument; //配置几何曲线 CurveArray curves = new CurveArray(); if (null == curves) { message = "Create the curves failed."; return IExternalCommand.Result.Failed; } XYZ first = new XYZ(0, 0, 0); XYZ second = new XYZ(10, 0, 0); XYZ third = new XYZ(10, 10, 0); XYZ fourth = new XYZ(0, 10, 0); curves.Append(revit.Create.NewLine(ref first, ref second, true)); curves.Append(revit.Create.NewLine(ref second, ref third, true)); curves.Append(revit.Create.NewLine(ref third, ref fourth, true)); curves.Append(revit.Create.NewLine(ref fourth, ref first, true)); // 利用几何曲线,类型,标高等创建地板对象 Floor createdFloor = curDoc.Create.NewFloor(curves, true); if (null == createdFloor) { message = "Create floor failed.!"; return IExternalCommand.Result.Failed; } return IExternalCommand.Result.Succeeded; }
private void NewMethod(FloorType floorType, CurveArray curves, Level level1) { RoomFilter filter = new RoomFilter(); FilteredElementCollector collector = new FilteredElementCollector(_doc); IList <Element> rooms = collector.WherePasses(filter).ToElements(); int n = rooms.Count(); foreach (Room room in rooms) { IList <IList <BoundarySegment> > segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions()); CurveArray roomsCurves = new CurveArray(); // Array to hold curv data collected from room boundreis roomsCurves.Clear(); SpatialElementBoundaryOptions bo = new SpatialElementBoundaryOptions(); SketchPlane sp = _doc.ActiveView.SketchPlane; foreach (IList <BoundarySegment> lstBs in room.GetBoundarySegments(bo)) { foreach (BoundarySegment bs in lstBs) { roomsCurves.Append(bs.GetCurve()); } } _doc.Create.NewFloor(roomsCurves, floorType, level1, false); } //_doc.Create.NewFloor(curves, floorType, level1, true); }
private static Autodesk.Revit.DB.Floor CreateFloor(IEnumerable<Value> edges, FloorType floorType, Autodesk.Revit.DB.Level level) { var ca = new CurveArray(); edges.ToList().ForEach(x => ca.Append((Curve) ((Value.Container) x).Item)); var floor = dynRevitSettings.Doc.Document.Create.NewFloor(ca, floorType, level, false); return floor; }
internal void CreateFloors(List <List <Point> > jsonReact, Document newDoc) { foreach (List <Point> floorPoints in jsonReact) { CurveArray floor = new CurveArray(); int lastPointOnFloor = floorPoints.Count - 1; for (int pointNum = 0; pointNum <= lastPointOnFloor; pointNum++) { XYZ startPoint = new XYZ(floorPoints[pointNum].Coord.X, floorPoints[pointNum].Coord.Y, floorPoints[pointNum].Coord.Z); XYZ endPoint; if (pointNum == lastPointOnFloor) { endPoint = new XYZ(floorPoints[0].Coord.X, floorPoints[0].Coord.Y, floorPoints[0].Coord.Z); } else { endPoint = new XYZ(floorPoints[pointNum + 1].Coord.X, floorPoints[pointNum + 1].Coord.Y, floorPoints[pointNum + 1].Coord.Z); } Curve partOfFloor = Line.CreateBound(startPoint, endPoint); floor.Append(partOfFloor); } using (Transaction floorTrans = new Transaction(newDoc, "Create a floor")) { floorTrans.Start(); newDoc.Create.NewFloor(floor, false); floorTrans.Commit(); } } }
/// <summary> /// /// </summary> /// <param name="pts"></param> private void CreatePolyline(IList <XYZ> pts) { if (m_sketchPlane == null) { XYZ zAxis = GeomUtils.kZAxis; XYZ origin = GeomUtils.kOrigin; Plane plane = m_app.Application.Create.NewPlane(zAxis, origin); m_sketchPlane = SketchPlane.Create(m_app.ActiveUIDocument.Document, plane); } Line line; XYZ startPt; XYZ endPt; CurveArray curveArray = new CurveArray(); for (int i = 0; i < (pts.Count - 1); ++i) { startPt = pts[i]; endPt = pts[i + 1]; line = Line.CreateBound(startPt, endPt); curveArray.Append(line); } m_app.ActiveUIDocument.Document.Create.NewModelCurveArray(curveArray, m_sketchPlane); }
private bool ConvertHbCurveArrArray(HbCurveArrArray hbCurveArrArray, CurveArrArray curveArrArray) { try { foreach (HbCurveArray hbCurveArray in hbCurveArrArray) { CurveArray curveArray = new CurveArray(); foreach (HbCurve hbCurve in hbCurveArray) { Curve curve = null; if (!ConvertHbCurve(hbCurve, ref curve)) { curveArrArray = null; return(false); } curveArray.Append(curve); } curveArrArray.Append(curveArray); } return(true); } catch { curveArrArray = null; return(false); } }
private void CreateFloor(Level targetLevel, List <List <LINE> > NewBeamGroup, FloorType floor_type) { List <CurveArray> floorCurves = new List <CurveArray>(); foreach (List <LINE> Beams in NewBeamGroup) { CurveArray curveArray = new CurveArray(); //floorCurves.Add(curveArray); try { foreach (LINE beam in Beams) { curveArray.Append(Line.CreateBound(beam.GetStartPoint(), beam.GetEndPoint())); } using (Transaction trans = new Transaction(this.revitDoc)) { FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions(); FailureHandler failureHandler = new FailureHandler(); failureHandlingOptions.SetFailuresPreprocessor(failureHandler); failureHandlingOptions.SetClearAfterRollback(false); trans.SetFailureHandlingOptions(failureHandlingOptions); trans.Start("Create Floors"); this.revitDoc.Create.NewFloor(curveArray, floor_type, targetLevel, false); trans.Commit(); } } catch (Exception) { } } }
public Result Execute( ExternalCommandData revit, ref string message, ElementSet elements) { UIApplication uiapp = revit.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; using (Transaction tx = new Transaction(doc)) { tx.Start("Create Sloped Slab"); double width = 19.685039400; double length = 59.055118200; double height = 9.84251968503937; XYZ[] pts = new XYZ[] { new XYZ(0.0, 0.0, height), new XYZ(width, 0.0, height), new XYZ(width, length, height), new XYZ(0, length, height) }; CurveArray profile = uiapp.Application.Create.NewCurveArray(); Line line = null; int n = pts.GetLength(0); XYZ q = pts[n - 1]; foreach (XYZ p in pts) { line = Line.CreateBound(q, p); profile.Append(line); q = p; } Level level = new FilteredElementCollector(doc) .OfClass(typeof(Level)) .Where <Element>( e => e.Name.Equals("CreateSlopedSlab")) .FirstOrDefault <Element>() as Level; if (null == level) { level = doc.Create.NewLevel(height); level.Name = "Sloped Slab"; } Floor floor = doc.Create.NewSlab( profile, level, line, 0.5, true); tx.Commit(); } return(Result.Succeeded); }
public void CreateHelix() { double increment = 0.1; double current = 0; XYZ startPt; XYZ endPt; XYZ zAxis = GeomUtils.kZAxis; XYZ origin = GeomUtils.kOrigin; Line line; Plane plane = m_revitApp.Application.Create.NewPlane(zAxis, origin); SketchPlane sketchPlane = SketchPlane.Create(m_revitApp.ActiveUIDocument.Document, plane); CurveArray curveArray = new CurveArray(); startPt = new XYZ(Math.Cos(current), Math.Sin(current), current); current += increment; while (current <= GeomUtils.kTwoPi) { endPt = new XYZ(Math.Cos(current), Math.Sin(current), current); line = Line.CreateBound(startPt, endPt); curveArray.Append(line); startPt = endPt; current += increment; } m_revitApp.ActiveUIDocument.Document.Create.NewModelCurveArray(curveArray, sketchPlane); }
//public void CreateModelLine( XYZ p, XYZ q ) //{ // if( p.IsAlmostEqualTo( q ) ) // { // throw new ArgumentException( // "Expected two different points." ); // } // Line line = Line.CreateBound( p, q ); // if( null == line ) // { // throw new Exception( // "Geometry line creation failed." ); // } // _credoc.NewModelCurve( line, // NewSketchPlanePassLine( line ) ); //} /// <summary> /// Return a new sketch plane containing the given curve. /// Update, later: please note that the Revit API provides /// an overload of the NewPlane method taking a CurveArray /// argument, which could presumably be used instead. /// </summary> SketchPlane NewSketchPlaneContainCurve( Curve curve) { XYZ p = curve.GetEndPoint(0); XYZ normal = GetCurveNormal(curve); Plane plane = _creapp.NewPlane(normal, p); #if DEBUG if (!(curve is Line)) { CurveArray a = _creapp.NewCurveArray(); a.Append(curve); Plane plane2 = _creapp.NewPlane(a); Debug.Assert(Util.IsParallel(plane2.Normal, plane.Normal), "expected equal planes"); Debug.Assert(Util.IsZero(plane2.SignedDistanceTo( plane.Origin)), "expected equal planes"); } #endif // DEBUG //return _credoc.NewSketchPlane( plane ); // 2013 return(SketchPlane.Create(_doc, plane)); // 2014 }
//public CreateFloorEventHandler(List<Element> rooms, Element floorType, Element level, SpatialElementBoundaryOptions option, float offset, bool isStructural) //{ // m_rooms = rooms; // m_floorType = floorType; // m_level = level; // m_option = option; // m_offset = offset; // m_isStructural = isStructural; //} public void Execute(UIApplication app) { try { uiDocument = app.ActiveUIDocument; document = uiDocument.Document; using (Transaction ts = new Transaction(document, "根据房间创建楼板")) { ICollection <ElementId> newFloorCollection = new List <ElementId>(); string floorInfo = ""; if (ts.Start() == TransactionStatus.Started) { foreach (Room r in Rooms) { CurveArray roomBoundary = new CurveArray(); IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundarySegments = r.GetBoundarySegments(Option); if (boundarySegments != null) { var first = boundarySegments.FirstOrDefault(); if (first == null) { floorInfo += "******************************\n******************************\n" + "错误 : 房间(ID " + r.Id + " )未生成" + "\n******************************\n******************************\n"; continue; } foreach (Autodesk.Revit.DB.BoundarySegment bs in first) { Curve curve = bs.GetCurve(); roomBoundary.Append(curve); } } Floor newFloor = document.Create.NewFloor(roomBoundary, FloorType as FloorType, Level as Level, IsStructural); newFloorCollection.Add(newFloor.Id); floorInfo += "楼板类型 : " + newFloor.FloorType.Name + "\n标高 : " + document.GetElement(newFloor.LevelId).Name + "\nID : " + newFloor.Id + "\n------------------------------\n"; } if (Level != null || Offset != 0.0f) { ModifyElementsOffset(newFloorCollection, Offset); } } if (ts.Commit() == TransactionStatus.Committed) { if (newFloorCollection.Count > 0) { uiDocument.Selection.SetElementIds(newFloorCollection); floorInfo = $"--- Design by Liu.SC ---\n共生成楼板{newFloorCollection.Count}个,信息如下:\n**********************************\n------------------------------\n" + floorInfo + "**********************************\n已添加进当前选择集!"; TaskDialog.Show("提示", floorInfo); } else { TaskDialog.Show("提示", "没有生成楼板"); } } } } catch (Exception ex) { TaskDialog.Show("Error - Create Floor", ex.Message + "\nTargetSite:" + ex.TargetSite.ToString() + "\nStackTrace:" + ex.StackTrace); } }
private static void CreateFloors(SketchItParams jsonDeserialized, Document newDoc) { foreach (List <Point> floorPoints in jsonDeserialized.Floors) { CurveArray floor = new CurveArray(); int lastPointOnFloor = floorPoints.Count - 1; for (int pointNum = 0; pointNum <= lastPointOnFloor; pointNum++) { XYZ startPoint = new XYZ(floorPoints[pointNum].X, floorPoints[pointNum].Y, floorPoints[pointNum].Z); XYZ endPoint; if (pointNum == lastPointOnFloor) { endPoint = new XYZ(floorPoints[0].X, floorPoints[0].Y, floorPoints[0].Z); } else { endPoint = new XYZ(floorPoints[pointNum + 1].X, floorPoints[pointNum + 1].Y, floorPoints[pointNum + 1].Z); } Curve partOfFloor = Line.CreateBound(startPoint, endPoint); floor.Append(partOfFloor); } using (Transaction floorTrans = new Transaction(newDoc, "Create a floor")) { floorTrans.Start(); newDoc.Create.NewFloor(floor, false); floorTrans.Commit(); } } }
/// <summary> /// Draw the trapezoid wire-frame with Revit Model curves. /// It's for debug use, to help developer see the exact location. /// </summary> /// <param name="revitDoc">Revit DB Document</param> public void Draw(Document revitDoc) { XYZ topDir = (Top.GetEndPoint(1) - Top.GetEndPoint(0)).Normalize(); XYZ verticalDir = (Vertical.GetEndPoint(0) - Vertical.GetEndPoint(1)).Normalize(); XYZ normal = topDir.CrossProduct(verticalDir); SketchPlane sketchplane = SketchPlane.Create(revitDoc, Plane.CreateByNormalAndOrigin(normal, Vertical.GetEndPoint(0))); CurveArray curves = new CurveArray(); curves.Append(Top.Clone()); curves.Append(Vertical.Clone()); curves.Append(Bottom.Clone()); curves.Append(Slanted.Clone()); revitDoc.Create.NewModelCurveArray(curves, sketchplane); }
/// <summary> /// Create a Revit Floor given it's curve outline and Level /// </summary> /// <param name="outline"></param> /// <param name="floorType"></param> /// <param name="level"></param> /// <returns>The floor</returns> public static Floor ByOutlineTypeAndLevel(Curve[] outline, FloorType floorType, Level level) { if (outline == null) { throw new ArgumentNullException("outline"); } if (floorType == null) { throw new ArgumentNullException("floorType"); } if (level == null) { throw new ArgumentNullException("level"); } if (outline.Count() < 3) { throw new Exception("Outline must have at least 3 edges to enclose an area."); } var ca = new CurveArray(); outline.ToList().ForEach(x => ca.Append(x.ToRevitType())); return(new Floor(ca, floorType.InternalFloorType, level.InternalLevel)); }
/// <summary> /// Create a Revit Floor given it's curve outline and Level /// </summary> /// <param name="outline"></param> /// <param name="floorType"></param> /// <param name="level"></param> /// <returns>The floor</returns> public static Floor ByOutlineTypeAndLevel(PolyCurve outline, FloorType floorType, Level level) { if (outline == null) { throw new ArgumentNullException("outline"); } if (floorType == null) { throw new ArgumentNullException("floorType"); } if (level == null) { throw new ArgumentNullException("level"); } if (!outline.IsClosed) { throw new ArgumentException("The input PolyCurve is not closed"); } var ca = new CurveArray(); outline.Curves().ForEach(x => ca.Append(x.ToRevitType())); return(new Floor(ca, floorType.InternalFloorType, level.InternalLevel)); }
CreateHelix() { double increment = 0.1; double current = 0; XYZ startPt; XYZ endPt; XYZ zAxis = GeomUtils.kZAxis; XYZ origin = GeomUtils.kOrigin; Line line; Plane plane = m_revitApp.Application.Create.NewPlane(zAxis, origin); SketchPlane sketchPlane = SketchPlane.Create(m_revitApp.ActiveUIDocument.Document, plane); CurveArray curveArray = new CurveArray(); startPt = new XYZ(Math.Cos(current), Math.Sin(current), current); current += increment; while (current <= GeomUtils.kTwoPi) { endPt = new XYZ(Math.Cos(current), Math.Sin(current), current); line = Line.CreateBound(startPt, endPt); curveArray.Append(line); startPt = endPt; current += increment; } m_revitApp.ActiveUIDocument.Document.Create.NewModelCurveArray(curveArray, sketchPlane); }
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(); } } }
/// <summary> /// The method is used to create a CurveArray along to an origin CurveArray and an offset value /// </summary> /// <param name="origin">the original CurveArray</param> /// <param name="offset">the offset value</param> /// <returns>CurveArray</returns> public CurveArray CreateCurveArrayByOffset(CurveArray origin, double offset) { Line line; Line temp; int counter = 0; CurveArray curveArr = m_appCreator.NewCurveArray(); Autodesk.Revit.DB.XYZ offsetx = new Autodesk.Revit.DB.XYZ(offset, 0, 0); Autodesk.Revit.DB.XYZ offsetz = new Autodesk.Revit.DB.XYZ(0, 0, offset); Autodesk.Revit.DB.XYZ p0 = new Autodesk.Revit.DB.XYZ(); Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ();; Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ(); Autodesk.Revit.DB.XYZ p3 = new Autodesk.Revit.DB.XYZ(); foreach (Curve curve in origin) { temp = curve as Line; if (temp != null) { if (counter == 0) { p0 = temp.GetEndPoint(0).Subtract(offsetz).Subtract(offsetx); } else if (counter == 1) { p1 = temp.GetEndPoint(0).Subtract(offsetz).Add(offsetx); } else if (counter == 2) { p2 = temp.GetEndPoint(0).Add(offsetx).Add(offsetz); } else { p3 = temp.GetEndPoint(0).Subtract(offsetx).Add(offsetz); } } counter++; } line = Line.CreateBound(p0, p1); curveArr.Append(line); line = Line.CreateBound(p1, p2); curveArr.Append(line); line = Line.CreateBound(p2, p3); curveArr.Append(line); line = Line.CreateBound(p3, p0); curveArr.Append(line); return(curveArr); }
/// <summary> /// Generate a Transform instance which as Transform property of BoundingBoxXYZ, /// when the user select a floor, this method will be called /// </summary> /// <returns>the reference of Transform, return null if it can't be generated</returns> Transform GenerateFloorTransform() { Transform transform = null; Floor floor = m_currentComponent as Floor; // First get the Analytical Model lines AnalyticalPanel model = null; Document document = floor.Document; AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); if (assocManager != null) { ElementId associatedElementId = assocManager.GetAssociatedElementId(floor.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalPanel) { model = associatedElement as AnalyticalPanel; } } } if (null == model) { m_errorInformation = "Please select a structural floor."; return(transform); } CurveArray curves = m_project.Document.Application.Create.NewCurveArray(); IList <Curve> curveList = model.GetOuterContour().ToList(); foreach (Curve curve in curveList) { curves.Append(curve); } if (null == curves || true == curves.IsEmpty) { m_errorInformation = "The program should never go here."; return(transform); } // Now I am sure I can create a transform instance. transform = Transform.Identity; // Third find the middle point of the floor and set it as Origin property. Autodesk.Revit.DB.XYZ midPoint = XYZMath.FindMiddlePoint(curves); transform.Origin = midPoint; // At last find out the directions of the created view, and set it as Basis property. Autodesk.Revit.DB.XYZ basisZ = XYZMath.FindFloorViewDirection(curves); Autodesk.Revit.DB.XYZ basisX = XYZMath.FindRightDirection(basisZ); Autodesk.Revit.DB.XYZ basisY = XYZMath.FindUpDirection(basisZ); transform.set_Basis(0, basisX); transform.set_Basis(1, basisY); transform.set_Basis(2, basisZ); return(transform); }
public static void Convert(CurveLoop sourceCurves, out CurveArray targetCurves) { targetCurves = new CurveArray(); foreach (Curve c in sourceCurves) { targetCurves.Append(c); } }
public static void Convert(IEnumerable <Curve> sourceCurves, out CurveArray targetCurves) { targetCurves = new CurveArray(); foreach (Curve c in sourceCurves) { targetCurves.Append(c); } }
public static void Convert(EdgeArray sourceCurves, out CurveArray targetCurves) { targetCurves = new CurveArray(); foreach (Edge ed in sourceCurves) { targetCurves.Append(ed.AsCurve()); } }
protected CurveArray GetSquareWallShape(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: wall length 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, 40, 40), true); Line line3 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 40, 40), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 40), true); Line line4 = creApp.NewLine(new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 40), new Autodesk.Revit.DB.XYZ(WallsSize * 15, 0, 0), true); curves.Append(line1); curves.Append(line2); curves.Append(line3); curves.Append(line4); return(curves); }
CurveArray ClosedPathCurveArray(XYZ[] pts, double[] angles) { CurveArray profile = new CurveArray(); for (int i = 0; i < pts.Length; i++) { if (angles[i] == 0) { profile.Append(Line.CreateBound(pts[i], pts[(i + 1) % pts.Length])); } else { profile.Append(ArcFromPointsAngle(pts[i], pts[(i + 1) % pts.Length], angles[i])); } } return(profile); }
/// <summary> /// Credits: Grevit /// Creates a new Sketch Plane from a Curve /// https://github.com/grevit-dev/Grevit/blob/3c7a5cc198e00dfa4cc1e892edba7c7afd1a3f84/Grevit.Revit/Utilities.cs#L402 /// </summary> /// <param name="curve">Curve to get plane from</param> /// <returns>Plane of the curve</returns> private SketchPlane NewSketchPlaneFromCurve(DB.Curve curve, Document doc) { XYZ startPoint = curve.GetEndPoint(0); XYZ endPoint = curve.GetEndPoint(1); // If Start end Endpoint are the same check further points. int i = 2; while (startPoint == endPoint && endPoint != null) { endPoint = curve.GetEndPoint(i); i++; } // Plane to return DB.Plane plane; // If Z Values are equal the Plane is XY if (startPoint.Z == endPoint.Z) { plane = CreatePlane(XYZ.BasisZ, startPoint); } // If X Values are equal the Plane is YZ else if (startPoint.X == endPoint.X) { plane = CreatePlane(XYZ.BasisX, startPoint); } // If Y Values are equal the Plane is XZ else if (startPoint.Y == endPoint.Y) { plane = CreatePlane(XYZ.BasisY, startPoint); } // Otherwise the Planes Normal Vector is not X,Y or Z. // We draw lines from the Origin to each Point and use the Plane this one spans up. else { CurveArray curves = new CurveArray(); curves.Append(curve); curves.Append(DB.Line.CreateBound(new XYZ(0, 0, 0), startPoint)); curves.Append(DB.Line.CreateBound(endPoint, new XYZ(0, 0, 0))); plane = DB.Plane.CreateByThreePoints(startPoint, new XYZ(0, 0, 0), endPoint); } return(SketchPlane.Create(doc, plane)); }
public void CreateWalls (Document doc, HouseObject house, List <WallType> autoTypes, Level baseLevel) { foreach (A_Floor floor in house.Floors) { ///Create the walls. foreach (A_Wall wa in floor.Walls) { WallType currentWt = null; XYZ p1 = new XYZ(wa.P1.X, wa.P1.Y, 0); XYZ p2 = new XYZ(wa.P2.X, wa.P2.Y, 0); Curve c = Line.CreateBound(p1, p2); ///Find the right wall type. ///If the type doesnt exist,create a new one. try { currentWt = autoTypes .First(at => at.Width - wa.Thickness < 0.0001); } catch { ///Duplicate a new walltype; float wallWidthMm = Helper.Feet2Mm(wa.Thickness); currentWt = AutoWallTypes[0].Duplicate ("AutoWall-" + wallWidthMm) as WallType; ///Set the width of the new type; CompoundStructure cStru = CompoundStructure .CreateSingleLayerCompoundStructure (MaterialFunctionAssignment.Structure, wa.Thickness, currentWt.GetCompoundStructure().GetMaterialId(0)); currentWt.SetCompoundStructure(cStru); ///Add it to collection. AutoWallTypes.Add(currentWt); } ///Create the individual wall wa.Wall = Wall.Create(doc, c, currentWt.Id, baseLevel.Id, floor.Height, 0, false, true); ActiveForm.UpdateProgress(wallWorkLoad); } ///Create the floor. CurveArray floorCrv = new CurveArray(); foreach (A_Room outer in floor.Outers) { foreach (A_Contour con in outer.Meta.Contours) { floorCrv.Append(Line.CreateBound (new XYZ(con.P1.X, con.P1.Y, baseLevel.Elevation), new XYZ(con.P2.X, con.P2.Y, baseLevel.Elevation))); } doc.Create.NewFloor(floorCrv, false); } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; /* Level level = new FilteredElementCollector(doc) * .OfCategory(BuiltInCategory.OST_Levels) * .WhereElementIsNotElementType() * .Cast<Level>().First(x => x.Name == "Ground Floor");*/ XYZ p1 = new XYZ(-10, -10, 0); XYZ p2 = new XYZ(10, -10, 0); XYZ p3 = new XYZ(15, 0, 0); XYZ p4 = new XYZ(10, 10, 0); XYZ p5 = new XYZ(-10, 10, 0); List <Curve> curves = new List <Curve>(); Line l1 = Line.CreateBound(p1, p2); Arc l2 = Arc.Create(p2, p4, p3); Line l3 = Line.CreateBound(p4, p5); Line l4 = Line.CreateBound(p5, p1); curves.Add(l1); curves.Add(l2); curves.Add(l3); curves.Add(l4); CurveLoop crvLoop = CurveLoop.Create(curves); double offset = UnitUtils.ConvertToInternalUnits(135, DisplayUnitType.DUT_MILLIMETERS); CurveLoop offsetcrv = CurveLoop.CreateViaOffset(crvLoop, offset, new XYZ(0, 0, 1)); CurveArray cArray = new CurveArray(); foreach (Curve c in offsetcrv) { cArray.Append(c); } try { using (Transaction trans = new Transaction(doc, "Place Family")) { trans.Start(); doc.Create.NewFloor(cArray, false); trans.Commit(); } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } return(Result.Succeeded); }
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); }
/// <summary> /// Create arc element by three points /// </summary> /// <param name="app">revit application</param> /// <param name="ptA">point a</param> /// <param name="ptB">point b</param> /// <param name="ptC">point c</param> /// <returns></returns> public static ModelCurve MakeArc(UIApplication app, Autodesk.Revit.DB.XYZ ptA, Autodesk.Revit.DB.XYZ ptB, Autodesk.Revit.DB.XYZ ptC) { Document doc = app.ActiveUIDocument.Document; Arc arc = app.Application.Create.NewArc(ptA, ptB, ptC); // Create three lines and a plane by the points Line line1 = app.Application.Create.NewLine(ptA, ptB, true); Line line2 = app.Application.Create.NewLine(ptB, ptC, true); Line line3 = app.Application.Create.NewLine(ptC, ptA, true); CurveArray ca = new CurveArray(); ca.Append(line1); ca.Append(line2); ca.Append(line3); Plane plane = app.Application.Create.NewPlane(ca); SketchPlane skplane = doc.FamilyCreate.NewSketchPlane(plane); // Create arc here ModelCurve modelcurve = doc.FamilyCreate.NewModelCurve(arc, skplane); return modelcurve; }
private static Autodesk.Revit.DB.Floor CreateFloor(IEnumerable <Value> edges, FloorType floorType, Autodesk.Revit.DB.Level level) { var ca = new CurveArray(); edges.ToList().ForEach(x => ca.Append((Curve)((Value.Container)x).Item)); var floor = dynRevitSettings.Doc.Document.Create.NewFloor(ca, floorType, level, false); return(floor); }
// =========================================== // (1.2a) create a simple L-shaped profile // =========================================== CurveArrArray createProfileLShape() { // // define a simple L-shape profile // // 5 tw 4 // +-+ // | | 3 h = height // d | +---+ 2 // +-----+ td // 0 1 // 6 w // // sizes (hard coded for simplicity) // note: these need to match reference plane. otherwise, alignment won't work. // as an exercise, try changing those values and see how it behaves. // double w = mmToFeet(600.0); // those are hard coded for simplicity here. in practice, you may want to find out from the references) double d = mmToFeet(600.0); double tw = mmToFeet(150.0); // thickness added for Lab2 double td = mmToFeet(150.0); // define vertices // const int nVerts = 6; // the number of vertices XYZ[] pts = new XYZ[] { new XYZ(-w / 2.0, -d / 2.0, 0.0), new XYZ(w / 2.0, -d / 2.0, 0.0), new XYZ(w / 2.0, (-d / 2.0) + td, 0.0), new XYZ((-w / 2.0) + tw, (-d / 2.0) + td, 0.0), new XYZ((-w / 2.0) + tw, d / 2.0, 0.0), new XYZ(-w / 2.0, d / 2.0, 0.0), new XYZ(-w / 2.0, -d / 2.0, 0.0) }; // the last one is to make the loop simple // define a loop. define individual edges and put them in a curveArray // CurveArray pLoop = _app.Create.NewCurveArray(); for (int i = 0; i < nVerts; ++i) { //Line line = _app.Create.NewLineBound(pts[i], pts[i + 1]); // Revit 2013 Line line = Line.CreateBound(pts[i], pts[i + 1]); // Revit 2014 pLoop.Append(line); } // then, put the loop in the curveArrArray as a profile // CurveArrArray pProfile = _app.Create.NewCurveArrArray(); pProfile.Append(pLoop); // if we come here, we have a profile now. return(pProfile); }
public void CreateFloors(Document document, FloorsFinishesSetup floorsFinishesSetup, Transaction tx) { tx.Start(Tools.LangResMan.GetString("floorFinishes_transactionName", Tools.Cult)); foreach (Room room in floorsFinishesSetup.SelectedRooms) { if (room != null) { if (room.UnboundedHeight != 0) { //Get all finish properties double height; if (floorsFinishesSetup.RoomParameter == null) { height = floorsFinishesSetup.FloorHeight; } else { Parameter roomParameter = room.get_Parameter(floorsFinishesSetup.RoomParameter.Definition); height = roomParameter.AsDouble(); } SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions(); IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundarySegments = room.GetBoundarySegments(opt); CurveArray curveArray = new CurveArray(); if (boundarySegments.Count != 0) { foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundarySegments.First()) { curveArray.Append(boundSeg.GetCurve()); } //Retrive room info Level rmLevel = document.GetElement(room.LevelId) as Level; Parameter param = room.get_Parameter(BuiltInParameter.ROOM_HEIGHT); double rmHeight = param.AsDouble(); if (curveArray.Size != 0) { Floor floor = document.Create.NewFloor(curveArray, floorsFinishesSetup.SelectedFloorType, rmLevel, false); //Change some param on the floor param = floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM); param.Set(height); } } } } } tx.Commit(); }
void createScene(Document doc) { //get 0.000 level FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection<Element> collection = collector.OfClass(typeof(Level)).ToElements(); Level lvl = null; foreach (Element elem in collection) { if (elem is Level) { lvl = (Level) elem; break; //need only one of existing levels } } if (lvl == null) lvl = Level.Create(doc, 0d); XYZ start = new XYZ(0, 0, 0); XYZ end = new XYZ(0, 100, 0); XYZ right = new XYZ(25, 100, 0); XYZ left = new XYZ(25, 0, 0); Line wallNorth = Line.CreateBound(start, end); Line wallEast = Line.CreateBound(end, right); Line wallSouth = Line.CreateBound(right, left); Line wallWest = Line.CreateBound(left, start); //subtransaction to be added Wall.Create(doc, wallNorth, lvl.Id, false); Wall.Create(doc, wallEast, lvl.Id, false); Wall.Create(doc, wallSouth, lvl.Id, false); Wall.Create(doc, wallWest, lvl.Id, false); //create ceiling //delete front walls CurveArray flrScetch = new CurveArray(); flrScetch.Append(wallNorth); flrScetch.Append(wallEast); flrScetch.Append(wallSouth); flrScetch.Append(wallWest); //doc.Create.NewFloor(flrScetch, false); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //【获取文档】 UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; //【通过APP打开族文件】 Application app = commandData.Application.Application; string rftPath = @"C:\ProgramData\Autodesk\RVT 2020\Family Templates\Chinese\公制柱.rft"; Document docRfa = app.NewFamilyDocument(rftPath); //【创建几何】 double width = 2.5 / 0.3048; double height = 10 / 0.3048; XYZ point1 = new XYZ(width, width, 0); XYZ point2 = new XYZ(-width, width, 0); XYZ point3 = new XYZ(-width, -width, 0); XYZ point4 = new XYZ(width, -width, 0); CurveArray curveArray = new CurveArray(); curveArray.Append(Line.CreateBound(point1, point2)); curveArray.Append(Line.CreateBound(point2, point3)); curveArray.Append(Line.CreateBound(point3, point4)); curveArray.Append(Line.CreateBound(point4, point1)); CurveArrArray curveArrArray = new CurveArrArray(); curveArrArray.Append(curveArray); //【创建草图平面】 SketchPlane sketchPlane = new FilteredElementCollector(docRfa).OfClass(typeof(SketchPlane)).First(x => x.Name == "低于参照标高") as SketchPlane; //【开始创建】 Transaction trans = new Transaction(docRfa, "创建柱族"); trans.Start(); Extrusion extrusion = docRfa.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, height); trans.Commit(); //【载入到项目中】 Family rfa = docRfa.LoadFamily(doc); docRfa.Close(false); //False的意思是关闭族文件但是不保存族 trans = new Transaction(doc, "载入族"); trans.Start(); rfa.Name = "编程创建的柱子"; trans.Commit(); return(Result.Succeeded); }
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; }
/// <summary> /// create beam system according to given profile and property /// </summary> public void CreateBeamSystem() { Autodesk.Revit.Creation.Document docCreation = m_data.CommandData.Application.ActiveUIDocument.Document.Create; // create CurveArray and insert Lines in order CurveArray curves = new CurveArray(); foreach (Line line in m_data.Lines) { curves.Append(line); } // create beam system takes closed profile consist of lines BeamSystem aBeamSystem = docCreation.NewBeamSystem(curves, m_data.CommandData.Application.ActiveUIDocument.Document.ActiveView.SketchPlane); // set created beam system's layout rule and beam type property aBeamSystem.LayoutRule = m_data.Param.Layout; aBeamSystem.BeamType = m_data.Param.BeamType; }
/// <summary> /// Recursively traverse the GeometryElement obtained from this Element, collecting the Curves /// </summary> /// <param name="geomElem"></param> /// <param name="curves"></param> private static void GetCurves(IEnumerable<Autodesk.Revit.DB.GeometryObject> geomElem, ref CurveArray curves) { foreach (Autodesk.Revit.DB.GeometryObject geomObj in geomElem) { var curve = geomObj as Autodesk.Revit.DB.Curve; if (null != curve) { curves.Append(curve); continue; } //If this GeometryObject is Instance, call AddCurve var geomInst = geomObj as GeometryInstance; if (null != geomInst) { var transformedGeomElem // curves transformed into project coords = geomInst.GetSymbolGeometry(geomInst.Transform.Inverse); GetCurves(transformedGeomElem, ref curves); } } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; // Retrieve selected floors, or all floors, if nothing is selected: List<Element> floors = new List<Element>(); if( !Util.GetSelectedElementsOrAll( floors, uidoc, typeof( Floor ) ) ) { Selection sel = uidoc.Selection; message = ( 0 < sel.Elements.Size ) ? "Please select some floor elements." : "No floor elements found."; return Result.Failed; } // Determine top face of each selected floor: int nNullFaces = 0; List<Face> topFaces = new List<Face>(); Options opt = app.Application.Create.NewGeometryOptions(); foreach( Floor floor in floors ) { GeometryElement geo = floor.get_Geometry( opt ); //GeometryObjectArray objects = geo.Objects; // 2012 foreach( GeometryObject obj in geo ) { Solid solid = obj as Solid; if( solid != null ) { PlanarFace f = GetTopFace( solid ); if( null == f ) { Debug.WriteLine( Util.ElementDescription( floor ) + " has no top face." ); ++nNullFaces; } topFaces.Add( f ); } } } // Create new floors from the top faces found // before creating the new floor, we would obviously // apply whatever modifications are required to the // new floor profile: Autodesk.Revit.Creation.Application creApp = app.Application.Create; Autodesk.Revit.Creation.Document creDoc = doc.Create; int i = 0; int n = topFaces.Count - nNullFaces; Debug.Print( "{0} top face{1} found.", n, Util.PluralSuffix( n ) ); foreach( Face f in topFaces ) { Floor floor = floors[i++] as Floor; if( null != f ) { EdgeArrayArray eaa = f.EdgeLoops; CurveArray profile; #region Attempt to include inner loops #if ATTEMPT_TO_INCLUDE_INNER_LOOPS bool use_original_loops = true; if( use_original_loops ) { profile = Convert( eaa ); } else #endif // ATTEMPT_TO_INCLUDE_INNER_LOOPS #endregion // Attempt to include inner loops { profile = new CurveArray(); // Only use first edge array, // the outer boundary loop, // skip the further items // representing holes: EdgeArray ea = eaa.get_Item( 0 ); foreach( Edge e in ea ) { IList<XYZ> pts = e.Tessellate(); int m = pts.Count; XYZ p = pts[0]; XYZ q = pts[m - 1]; Line line = Line.CreateBound( p, q ); profile.Append( line ); } } //Level level = floor.Level; // 2013 Level level = doc.GetElement( floor.LevelId ) as Level; // 2014 floor = creDoc.NewFloor( profile, floor.FloorType, level, true ); XYZ v = new XYZ( 5, 5, 0 ); //doc.Move( floor, v ); // 2011 ElementTransformUtils.MoveElement( doc, floor.Id, v ); // 2012 } } return Result.Succeeded; }
/// <summary> /// Convert an EdgeArrayArray to a CurveArray, /// possibly including multiple loops. /// All non-linear segments are approximated by /// the edge curve tesselation. /// </summary> CurveArray Convert( EdgeArrayArray eaa ) { CurveArray ca = new CurveArray(); List<XYZ> pts = new List<XYZ>(); XYZ q; string s; int iLoop = 0; foreach( EdgeArray ea in eaa ) { q = null; s = string.Empty; pts.Clear(); foreach( Edge e in ea ) { IList<XYZ> a = e.Tessellate(); bool first = true; //XYZ p0 = null; foreach( XYZ p in a ) { if( first ) { if( null == q ) { s += Util.PointString( p ); pts.Add( p ); } else { Debug.Assert( p.IsAlmostEqualTo( q ), "expected connected sequential edges" ); } first = false; //p0 = p; q = p; } else { s += " --> " + Util.PointString( p ); //ca.Append( Line.get_Bound( q, p ) ); pts.Add( p ); q = p; } } //ca.Append( Line.get_Bound( q, p0 ) ); } Debug.Print( "{0}: {1}", iLoop++, s ); // test case: break after first edge loop, // which we assume to be the outer: //break; { // try reversing all the inner loops: if( 1 < iLoop ) { pts.Reverse(); } bool first = true; foreach( XYZ p in pts ) { if( first ) { first = false; } else { ca.Append( Line.get_Bound( q, p ) ); } q = p; } } } return ca; }
/// <summary> /// Create a new swept blend form using arcs to /// define circular start and end profiles and an /// arc path. The NewSweptBlend method requires /// the input profiles to be in the XY plane. /// </summary> public void CreateNewSweptBlendArc( Document doc ) { Debug.Assert( doc.IsFamilyDocument, "this method will only work in a family document" ); Application app = doc.Application; Autodesk.Revit.Creation.Application creapp = app.Create; Autodesk.Revit.Creation.FamilyItemFactory credoc = doc.FamilyCreate; #region Original code for Revit 2012 #if COMPILE_ORIGINAL_CODE XYZ pnt1 = new XYZ( 0, -1, 0 ); XYZ pnt2 = new XYZ( 1, 0, 0 ); XYZ pnt3 = new XYZ( 0, 1, 0 ); XYZ pnt4 = new XYZ( -1, 0, 0 ); Arc aArc1 = creapp.NewArc( pnt1, pnt3, pnt2 ); Arc aArc2 = creapp.NewArc( pnt3, pnt1, pnt4 ); CurveArrArray arrarr1 = new CurveArrArray(); SweepProfile bottomProfile = creapp.NewCurveLoopsProfile( arrarr1 ); CurveArray arr1 = new CurveArray(); arr1.Append( aArc1 ); arr1.Append( aArc2 ); XYZ pnt6 = new XYZ( 0, -2, 0 ); XYZ pnt7 = new XYZ( 2, 0, 0 ); XYZ pnt8 = new XYZ( 0, 2, 0 ); XYZ pnt9 = new XYZ( -2, 0, 0 ); Arc aArc3 = creapp.NewArc( pnt6, pnt8, pnt7 ); Arc aArc4 = creapp.NewArc( pnt8, pnt6, pnt9 ); CurveArrArray arrarr2 = new CurveArrArray(); CurveArray arr2 = new CurveArray(); arr2.Append( aArc3 ); arr2.Append( aArc4 ); arrarr2.Append( arr2 ); SweepProfile topProfile = creapp.NewCurveLoopsProfile( arrarr2 ); XYZ pnt10 = new XYZ( 0, 0, 0 ); XYZ pnt11 = new XYZ( 0, 5, 0 ); XYZ pnt122 = new XYZ( 2.5, 2.5, 0 ); Arc testArc = creapp.NewArc( pnt10, pnt11, pnt122 ); Curve curve = (Curve) testArc; Plane geometryPlane = creapp.NewPlane( XYZ.BasisZ, XYZ.Zero ); SketchPlane sketchPlane = doc.NewSketchPlane( geometryPlane ); SweptBlend aSweptBlend = doc.NewSweptBlend( true, curve, sketchPlane, bottomProfile, topProfile ); #endif // COMPILE_ORIGINAL_CODE #endregion // Original code for Revit 2012 XYZ px = XYZ.BasisX; XYZ py = XYZ.BasisY; Arc arc1 = Arc.Create( -px, px, -py ); Arc arc2 = Arc.Create( px, -px, py ); CurveArray arr1 = new CurveArray(); arr1.Append( arc1 ); arr1.Append( arc2 ); CurveArrArray arrarr1 = new CurveArrArray(); arrarr1.Append( arr1 ); SweepProfile bottomProfile = creapp.NewCurveLoopsProfile( arrarr1 ); px += px; py += py; Arc arc3 = Arc.Create( -px, px, -py ); Arc arc4 = Arc.Create( px, -px, py ); CurveArray arr2 = new CurveArray(); arr2.Append( arc3 ); arr2.Append( arc4 ); CurveArrArray arrarr2 = new CurveArrArray(); arrarr2.Append( arr2 ); SweepProfile topProfile = creapp.NewCurveLoopsProfile( arrarr2 ); XYZ p0 = XYZ.Zero; XYZ p5 = 5 * XYZ.BasisY; XYZ pmid = new XYZ( 2.5, 2.5, 0 ); Arc testArc = Arc.Create( p0, p5, pmid ); Plane geometryPlane = creapp.NewPlane( XYZ.BasisZ, XYZ.Zero ); SketchPlane sketchPlane = SketchPlane.Create( doc, geometryPlane ); SweptBlend aSweptBlend = credoc.NewSweptBlend( true, testArc, sketchPlane, bottomProfile, topProfile ); }
private static void AddCurvesToArray(CurveArray crvArr, FSharpList<Value> lst) { dynRevitSettings.Doc.RefreshActiveView(); foreach (Value vInner in lst) { var c = (vInner as Value.Container).Item as Curve; crvArr.Append(c); } }
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 = createApp.NewLineBound( 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) { MessageBox.Show( "The start point and the end point of the line are too close, please re-draw it."); ClearChords(); } } }
/// <summary> /// Create Arc Grids /// </summary> /// <param name="failureReasons">ArrayList contains failure reasons</param> /// <returns>Number of grids failed to create</returns> private int CreateArcGrids(ref ArrayList failureReasons) { int errorCount = 0; // Curve array which stores all curves for batch creation CurveArray curves = new CurveArray(); for (int i = 0; i < m_arcNumber; ++i) { try { Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ (m_xOrigin, m_yOrigin, 0); double radius = m_arcFirstRadius + i * m_arcSpacing; // In Revit UI user can select a circle to create a grid, but actually two grids // (One from 0 to 180 degree and the other from 180 degree to 360) will be created. // In RevitAPI using NewGrid method with a circle as its argument will raise an exception. // Therefore in this sample we will create two arcs from the upper and lower parts of the // circle, and then create two grids on the base of the two arcs to accord with UI. if (m_endDegree - m_startDegree == 2 * Values.PI) // Create circular grids { Arc upperArcToCreate; Arc lowerArcToCreate; upperArcToCreate = TransformArc(origin, radius, 0, Values.PI, m_arcFirstBubbleLoc); if (i == 0) { Grid gridUpper; gridUpper = NewGrid(upperArcToCreate); if (gridUpper != null) { try { // Set label of first grid gridUpper.Name = m_arcFirstLabel; } catch (System.ArgumentException) { ShowMessage(resManager.GetString("FailedToSetLabel") + m_arcFirstLabel + "!", resManager.GetString("FailureCaptionSetLabel")); } } } else { curves.Append(upperArcToCreate); } lowerArcToCreate = TransformArc(origin, radius, Values.PI, 2 * Values.PI, m_arcFirstBubbleLoc); curves.Append(lowerArcToCreate); } else // Create arc grids { // Each arc grid will has extension degree of 15 degree double extensionDegree = 15 * Values.DEGTORAD; Grid grid; Arc arcToCreate; if (m_lineNumber != 0) { // If the range of arc degree is too close to a circle, the arc grids will not have // extension degrees. // Also the room for bubble should be considered, so a room size of 3 * extensionDegree // is reserved here if (m_endDegree - m_startDegree < 2 * Values.PI - 3 * extensionDegree) { double startDegreeWithExtension = m_startDegree - extensionDegree; double endDegreeWithExtension = m_endDegree + extensionDegree; arcToCreate = TransformArc(origin, radius, startDegreeWithExtension, endDegreeWithExtension, m_arcFirstBubbleLoc); } else { try { arcToCreate = TransformArc(origin, radius, m_startDegree, m_endDegree, m_arcFirstBubbleLoc); } catch (System.ArgumentException) { String failureReason = resManager.GetString("EndPointsTooClose"); if (!failureReasons.Contains(failureReason)) { failureReasons.Add(failureReason); } errorCount++; continue; } } } else { try { arcToCreate = TransformArc(origin, radius, m_startDegree, m_endDegree, m_arcFirstBubbleLoc); } catch (System.ArgumentException) { String failureReason = resManager.GetString("EndPointsTooClose"); if (!failureReasons.Contains(failureReason)) { failureReasons.Add(failureReason); } errorCount++; continue; } } if (i == 0) { grid = NewGrid(arcToCreate); if (grid != null) { try { grid.Name = m_arcFirstLabel; } catch (System.ArgumentException) { ShowMessage(resManager.GetString("FailedToSetLabel") + m_arcFirstLabel + "!", resManager.GetString("FailureCaptionSetLabel")); } } } else { curves.Append(arcToCreate); } } } catch (Exception) { ++errorCount; continue; } } // Create grids with curves CreateGrids(curves); return errorCount; }
/// <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 }
/// <summary> /// Create a new swept blend form. /// The NewSweptBlend method requires the /// input profile to be in the XY plane. /// </summary> public void CreateNewSweptBlend( Document doc ) { Debug.Assert( doc.IsFamilyDocument, "this method will only work in a family document" ); Application app = doc.Application; Autodesk.Revit.Creation.Application creapp = app.Create; CurveArrArray curvess0 = creapp.NewCurveArrArray(); CurveArray curves0 = new CurveArray(); XYZ p00 = creapp.NewXYZ( 0, 7.5, 0 ); XYZ p01 = creapp.NewXYZ( 0, 15, 0 ); // changing Z to 1 in the following line fails: XYZ p02 = creapp.NewXYZ( -1, 10, 0 ); //curves0.Append( creapp.NewLineBound( p00, p01 ) ); // 2013 curves0.Append( Line.CreateBound( p00, p01 ) ); // 2014 curves0.Append( Line.CreateBound( p01, p02 ) ); curves0.Append( Line.CreateBound( p02, p00 ) ); curvess0.Append( curves0 ); CurveArrArray curvess1 = creapp.NewCurveArrArray(); CurveArray curves1 = new CurveArray(); XYZ p10 = creapp.NewXYZ( 7.5, 0, 0 ); XYZ p11 = creapp.NewXYZ( 15, 0, 0 ); // changing the Z value in the following line fails: XYZ p12 = creapp.NewXYZ( 10, -1, 0 ); curves1.Append( Line.CreateBound( p10, p11 ) ); curves1.Append( Line.CreateBound( p11, p12 ) ); curves1.Append( Line.CreateBound( p12, p10 ) ); curvess1.Append( curves1 ); SweepProfile sweepProfile0 = creapp.NewCurveLoopsProfile( curvess0 ); SweepProfile sweepProfile1 = creapp.NewCurveLoopsProfile( curvess1 ); XYZ pnt10 = new XYZ( 5, 0, 0 ); XYZ pnt11 = new XYZ( 0, 20, 0 ); Curve curve = Line.CreateBound( pnt10, pnt11 ); XYZ normal = XYZ.BasisZ; SketchPlane splane = CreateSketchPlane( doc, normal, XYZ.Zero ); try { SweptBlend sweptBlend = doc.FamilyCreate.NewSweptBlend( true, curve, splane, sweepProfile0, sweepProfile1 ); } catch( Exception ex ) { Util.ErrorMsg( "NewSweptBlend exception: " + ex.Message ); } }
/// <summary> /// /// </summary> /// <param name="pts"></param> private void CreatePolyline(IList<XYZ> pts) { if (m_sketchPlane == null) { XYZ zAxis = GeomUtils.kZAxis; XYZ origin = GeomUtils.kOrigin; Plane plane = m_app.Application.Create.NewPlane(zAxis, origin); m_sketchPlane = SketchPlane.Create(m_app.ActiveUIDocument.Document, plane); } Line line; XYZ startPt; XYZ endPt; CurveArray curveArray = new CurveArray(); for (int i = 0; i < (pts.Count - 1); ++i) { startPt = pts[i]; endPt = pts[i + 1]; line = Line.CreateBound(startPt, endPt); curveArray.Append(line); } m_app.ActiveUIDocument.Document.Create.NewModelCurveArray(curveArray, m_sketchPlane); }
/// <summary> /// Creates a new Revit Slab /// </summary> /// <param name="slab"></param> /// <returns></returns> public static Element Create(this Grevit.Types.Slab slab) { // Create a List of Curves for the ouline List<Curve> curves = new List<Curve>(); // Translate Grevit Curves to Revit Curves for (int i = 0; i < slab.surface.profile[0].outline.Count; i++) { foreach (Curve curve in Utilities.GrevitCurvesToRevitCurves(slab.surface.profile[0].outline[i])) curves.Add(curve); } // Get the two slope points XYZ slopePointBottom = slab.bottom.ToXYZ(); XYZ slopeTopPoint = slab.top.ToXYZ(); // get a Z Value from an outline point to check if the slope points are in this plane double outlineZCheckValue = curves[0].GetEndPoint(0).Z; // If one of the points is not in the same Z plane // Create new points replacing the Z value if (!slopePointBottom.Z.Equals(outlineZCheckValue) || !slopeTopPoint.Z.Equals(outlineZCheckValue)) { slopePointBottom = new XYZ(slopePointBottom.X, slopePointBottom.Y, outlineZCheckValue); slopeTopPoint = new XYZ(slopeTopPoint.X, slopeTopPoint.Y, outlineZCheckValue); } // Create a new slope line between the points Autodesk.Revit.DB.Line slopeLine = Autodesk.Revit.DB.Line.CreateBound(slopePointBottom, slopeTopPoint); // Sort the outline curves contiguous Utilities.SortCurvesContiguous(GrevitBuildModel.document.Application.Create, curves); // Create a new surve array for creating the slab CurveArray outlineCurveArray = new CurveArray(); foreach (Curve c in curves) outlineCurveArray.Append(c); // get the supposed level Element levelElement = GrevitBuildModel.document.GetLevelByName(slab.levelbottom,slopePointBottom.Z); if (levelElement != null) { // Create a new slab return GrevitBuildModel.document.Create.NewSlab(outlineCurveArray, (Autodesk.Revit.DB.Level)levelElement, slopeLine, slab.slope, slab.structural); } return null; }
/// <summary> /// Create a Line /// </summary> /// <param name="line"></param> /// <returns></returns> public static Element Create(this Grevit.Types.RevitLine line) { // get revit curves from grevit curve foreach (Curve c in Utilities.GrevitCurvesToRevitCurves(line.curve)) { if (line.isModelCurve) GrevitBuildModel.document.Create.NewModelCurve(c, Utilities.NewSketchPlaneFromCurve(GrevitBuildModel.document, c)); if (line.isDetailCurve) GrevitBuildModel.document.Create.NewDetailCurve(GrevitBuildModel.document.ActiveView, c); if (line.isRoomBounding) { CurveArray tmpca = new CurveArray(); tmpca.Append(c); GrevitBuildModel.document.Create.NewRoomBoundaryLines(Utilities.NewSketchPlaneFromCurve(GrevitBuildModel.document, c), tmpca, GrevitBuildModel.document.ActiveView); } } return null; }
/// <summary> /// Get all selected lines and arcs /// </summary> /// <param name="document">Revit's document</param> /// <returns>CurveArray contains all selected lines and arcs</returns> private static CurveArray GetSelectedCurves(Document document) { CurveArray selectedCurves = new CurveArray(); UIDocument newUIdocument = new UIDocument(document); ElementSet elements = newUIdocument.Selection.Elements; foreach (Autodesk.Revit.DB.Element element in elements) { if ((element is ModelLine) || (element is ModelArc)) { ModelCurve modelCurve = element as ModelCurve; Curve curve = modelCurve.GeometryCurve; if (curve != null) { selectedCurves.Append(curve); } } else if ((element is DetailLine) || (element is DetailArc)) { DetailCurve detailCurve = element as DetailCurve; Curve curve = detailCurve.GeometryCurve; if (curve != null) { selectedCurves.Append(curve); } } } return selectedCurves; }
List<RevitParameter> ILyrebirdService.GetParameters(RevitObject revitFamily, string typeName) { lock (_locker) { TaskContainer.Instance.EnqueueTask(uiApp => { var doc = uiApp.ActiveUIDocument.Document; parameters = new List<RevitParameter>(); if (revitFamily.CategoryId == -2000011) { // do stuff for walls FilteredElementCollector wallCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); wallCollector.OfClass(typeof(WallType)); wallCollector.OfCategory(BuiltInCategory.OST_Walls); foreach (WallType wt in wallCollector) { if (wt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in wt.Parameters) { if(!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); Wall wall = null; try { Curve c = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); if (l != null) wall = Wall.Create(doc, c, l.Id, false); } catch (Exception exception) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(exception.Message); } if (wall != null) { foreach (Parameter p in wall.Parameters) { //if(!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000032) { // get parameters for floors FilteredElementCollector floorCollector = new FilteredElementCollector(doc); floorCollector.OfClass(typeof(FloorType)); floorCollector.OfCategory(BuiltInCategory.OST_Floors); foreach (FloorType ft in floorCollector) { if (ft.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in ft.Parameters) { if(!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); Floor floor = null; try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); floor = doc.Create.NewFloor(profile, false); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (floor != null) { foreach (Parameter p in floor.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000035) { // get parameters for a roof FilteredElementCollector roofCollector = new FilteredElementCollector(doc); roofCollector.OfClass(typeof(RoofType)); roofCollector.OfCategory(BuiltInCategory.OST_Roofs); foreach (RoofType rt in roofCollector) { if (rt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in rt.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); FootPrintRoof roof = null; try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); ModelCurveArray curveArrayMapping = new ModelCurveArray(); roof = doc.Create.NewFootPrintRoof(profile, l, rt, out curveArrayMapping); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (roof != null) { foreach (Parameter p in roof.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000240) { // Level Families FilteredElementCollector levelCollector = new FilteredElementCollector(doc); levelCollector.OfClass(typeof(LevelType)); levelCollector.OfCategory(BuiltInCategory.OST_Levels); foreach (LevelType lt in levelCollector) { if (lt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in lt.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp level")) { t.Start(); Level lvl = null; try { lvl = doc.Create.NewLevel(-1000.22); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (lvl != null) { foreach (Parameter p in lvl.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000220) { // Grid Families FilteredElementCollector gridCollector = new FilteredElementCollector(doc); gridCollector.OfClass(typeof(GridType)); gridCollector.OfCategory(BuiltInCategory.OST_Grids); foreach (GridType gt in gridCollector) { if (gt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in gt.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp grid")) { t.Start(); Grid grid = null; try { Line ln = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 1, 0)); grid = doc.Create.NewGrid(ln); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (grid != null) { foreach (Parameter p in grid.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000051) { // leave parameters empty } else { // Regular family. Proceed to get all parameters FilteredElementCollector familyCollector = new FilteredElementCollector(doc); familyCollector.OfClass(typeof(Family)); foreach (Family f in familyCollector) { if (f.Name == revitFamily.FamilyName) { ISet<ElementId> fsIds = f.GetFamilySymbolIds(); foreach (ElementId fsid in fsIds) { FamilySymbol fs = doc.GetElement(fsid) as FamilySymbol; if (fs.Name == typeName) { List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in fs.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } List<Parameter> instanceParams = new List<Parameter>(); // temporary create an instance of the family to get instance parameters using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); FamilyInstance fi = null; // Get the hosting type int hostType = f.get_Parameter(BuiltInParameter.FAMILY_HOSTING_BEHAVIOR).AsInteger(); if (hostType == 0) { // Typical } else if (hostType == 1) { // Wall hosted // Temporary wall Wall wall = null; Curve c = Line.CreateBound(new XYZ(-20, 0, 0), new XYZ(20, 0, 0)); FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); try { if (l != null) wall = Wall.Create(doc, c, l.Id, false); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (wall != null) { fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, wall as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } else if (hostType == 2) { // Floor Hosted // temporary floor Floor floor = null; FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); floor = doc.Create.NewFloor(profile, false); } catch (Exception ex) { // Failed to create the floor, no instance parameters will be found Debug.WriteLine(ex.Message); } if (floor != null) { fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, floor as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } else if (hostType == 3) { // Ceiling Hosted (might be difficult) // Try to find a ceiling FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); FilteredElementCollector ceilingCollector = new FilteredElementCollector(doc); Ceiling ceiling = ceilingCollector.OfClass(typeof(Ceiling)).ToElements().OfType<Ceiling>().FirstOrDefault(); if (ceiling != null) { // Find a point on the ceiling Options opt = new Options(); opt.ComputeReferences = true; GeometryElement ge = ceiling.get_Geometry(opt); List<List<XYZ>> verticePoints = new List<List<XYZ>>(); foreach (GeometryObject go in ge) { Solid solid = go as Solid; if (null == solid || 0 == solid.Faces.Size) { continue; } PlanarFace planarFace = null; double faceArea = 0; foreach (Face face in solid.Faces) { PlanarFace pf = null; try { pf = face as PlanarFace; } catch { } if (pf != null) { if (pf.Area > faceArea) { planarFace = pf; } } } if (planarFace != null) { Mesh mesh = planarFace.Triangulate(); int triCnt = mesh.NumTriangles; MeshTriangle bigTriangle = null; for (int tri = 0; tri < triCnt; tri++) { if (bigTriangle == null) { bigTriangle = mesh.get_Triangle(tri); } else { MeshTriangle mt = mesh.get_Triangle(tri); double area = Math.Abs(((mt.get_Vertex(0).X * (mt.get_Vertex(1).Y - mt.get_Vertex(2).Y)) + (mt.get_Vertex(1).X * (mt.get_Vertex(2).Y - mt.get_Vertex(0).Y)) + (mt.get_Vertex(2).X * (mt.get_Vertex(0).Y - mt.get_Vertex(1).Y))) / 2); double bigTriArea = Math.Abs(((bigTriangle.get_Vertex(0).X * (bigTriangle.get_Vertex(1).Y - bigTriangle.get_Vertex(2).Y)) + (bigTriangle.get_Vertex(1).X * (bigTriangle.get_Vertex(2).Y - bigTriangle.get_Vertex(0).Y)) + (bigTriangle.get_Vertex(2).X * (bigTriangle.get_Vertex(0).Y - bigTriangle.get_Vertex(1).Y))) / 2); if (area > bigTriArea) { bigTriangle = mt; } } } if (bigTriangle != null) { double test = Math.Abs(((bigTriangle.get_Vertex(0).X * (bigTriangle.get_Vertex(1).Y - bigTriangle.get_Vertex(2).Y)) + (bigTriangle.get_Vertex(1).X * (bigTriangle.get_Vertex(2).Y - bigTriangle.get_Vertex(0).Y)) + (bigTriangle.get_Vertex(2).X * (bigTriangle.get_Vertex(0).Y - bigTriangle.get_Vertex(1).Y))) / 2); } try { List<XYZ> ptList = new List<XYZ>(); ptList.Add(bigTriangle.get_Vertex(0)); ptList.Add(bigTriangle.get_Vertex(1)); ptList.Add(bigTriangle.get_Vertex(2)); verticePoints.Add(ptList); } catch { } break; } } if (verticePoints.Count > 0) { List<XYZ> vertices = verticePoints[0]; XYZ midXYZ = vertices[1] + (0.5 * (vertices[2] - vertices[1])); XYZ centerPt = vertices[0] + (0.666667 * (midXYZ - vertices[0])); if (ceiling != null) { fi = doc.Create.NewFamilyInstance(centerPt, fs, ceiling as Element, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } } } else if (hostType == 4) { // Roof Hosted // Temporary roof FootPrintRoof roof = null; FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); FilteredElementCollector roofTypeCollector = new FilteredElementCollector(doc); RoofType rt = roofTypeCollector.OfClass(typeof(RoofType)).ToElements().OfType<RoofType>().FirstOrDefault(); try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); ModelCurveArray roofProfile = new ModelCurveArray(); roof = doc.Create.NewFootPrintRoof(profile, l, rt, out roofProfile); } catch (Exception ex) { // Failed to create the roof, no instance parameters will be found Debug.WriteLine(ex.Message); } if (roof != null) { fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, roof as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } else if (hostType == 5) { // temporary floor Floor floor = null; FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); floor = doc.Create.NewFloor(profile, false); } catch (Exception ex) { // Failed to create the floor, no instance parameters will be found Debug.WriteLine(ex.Message); } // Find a face on the floor to host to. Face face = FindFace(XYZ.Zero, XYZ.BasisZ, doc); if (face != null) { fi = doc.Create.NewFamilyInstance(face, XYZ.Zero, new XYZ(0, -1, 0), fs); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } // Create a typical family instance try { fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } catch (Exception ex) { Debug.WriteLine(ex.Message); } // TODO: Try creating other family instances like walls, sketch based, ... and getting the instance params if (fi != null) { foreach (Parameter p in fi.Parameters) { if (!p.IsReadOnly) instanceParams.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instanceParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instanceParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } } } break; } } } }); } return parameters; }
private CurveArray GetCurveArray(IEnumerable<LyrebirdCurve> curves) { CurveArray crvArray = new CurveArray(); int i = 0; foreach (LyrebirdCurve lbc in curves) { if (lbc.CurveType == "Circle") { XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT)); XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT)); XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT)); XYZ pt4 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[3].Z, lengthDUT)); XYZ pt5 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[4].Z, lengthDUT)); Arc arc1 = Arc.Create(pt1, pt3, pt2); Arc arc2 = Arc.Create(pt3, pt5, pt4); crvArray.Append(arc1); crvArray.Append(arc2); } else if (lbc.CurveType == "Arc") { XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT)); XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT)); XYZ pt3 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[2].Z, lengthDUT)); Arc arc = Arc.Create(pt1, pt3, pt2); crvArray.Append(arc); } else if (lbc.CurveType == "Line") { XYZ pt1 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[0].Z, lengthDUT)); XYZ pt2 = new XYZ(UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].X, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lbc.ControlPoints[1].Z, lengthDUT)); Line line = Line.CreateBound(pt1, pt2); crvArray.Append(line); } else if (lbc.CurveType == "Spline") { List<XYZ> controlPoints = new List<XYZ>(); List<double> weights = lbc.Weights; List<double> knots = lbc.Knots; foreach (LyrebirdPoint lp in lbc.ControlPoints) { XYZ pt = new XYZ(UnitUtils.ConvertToInternalUnits(lp.X, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Y, lengthDUT), UnitUtils.ConvertToInternalUnits(lp.Z, lengthDUT)); controlPoints.Add(pt); } try { if (lbc.Degree == 3) { NurbSpline spline = NurbSpline.Create(controlPoints, weights, knots, lbc.Degree, false, true); crvArray.Append(spline); } else { HermiteSpline spline = HermiteSpline.Create(controlPoints, false); crvArray.Append(spline); } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } i++; } return crvArray; }
/// <summary> /// get necessary data when create AreaReinforcement on a horizontal floor /// </summary> /// <param name="floor">floor on which to create AreaReinforcemen</param> /// <param name="refer">reference of the horizontal face on the floor</param> /// <param name="curves">curves compose the horizontal face of the floor</param> /// <returns>is successful</returns> public bool GetFloorGeom(Floor floor, ref Reference refer, ref CurveArray curves) { //get horizontal face reference FaceArray faces = GeomUtil.GetFaces(floor); foreach (Face face in faces) { if (GeomUtil.IsHorizontalFace(face)) { refer = face.Reference; break; } } //no proper reference if (null == refer) { return false; } //check the analytical model profile is rectangular AnalyticalModel model = floor.GetAnalyticalModel(); if (null == model) { return false; } IList<Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves); curves = m_currentDoc.Application.Create.NewCurveArray(); foreach (Curve curve in curveList) { curves.Append(curve); } if (!GeomUtil.IsRectangular(curves)) { return false; } return true; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; using( Transaction tx = new Transaction( doc ) ) { tx.Start( "NewExtrusionRoof" ); RoofType fs = new FilteredElementCollector( doc ) .OfClass( typeof( RoofType ) ) .Cast<RoofType>() .FirstOrDefault<RoofType>( a => null != a ); Level lvl = new FilteredElementCollector( doc ) .OfClass( typeof( Level ) ) .Cast<Level>() .FirstOrDefault<Level>( a => null != a ); double x = 1; XYZ origin = new XYZ( x, 0, 0 ); XYZ vx = XYZ.BasisY; XYZ vy = XYZ.BasisZ; SketchPlane sp = SketchPlane.Create( doc, //new Autodesk.Revit.DB.Plane( vx, vy, origin ) // 2016 Plane.CreateByOriginAndBasis( origin, vx, vy ) );// 2017 CurveArray ca = new CurveArray(); XYZ[] pts = new XYZ[] { new XYZ( x, 1, 0 ), new XYZ( x, 1, 1 ), new XYZ( x, 2, 1 ), new XYZ( x, 2, 2 ), new XYZ( x, 3, 2 ), new XYZ( x, 3, 3 ), new XYZ( x, 4, 3 ), new XYZ( x, 4, 4 ) }; int n = pts.Length; for( int i = 1; i < n; ++i ) { ca.Append( Line.CreateBound( pts[i - 1], pts[i] ) ); } doc.Create.NewModelCurveArray( ca, sp ); View v = doc.ActiveView; ReferencePlane rp = doc.Create.NewReferencePlane2( origin, origin + vx, origin + vy, v ); rp.Name = "MyRoofPlane"; ExtrusionRoof er = doc.Create.NewExtrusionRoof( ca, rp, lvl, fs, 0, 3 ); Debug.Print( "Extrusion roof element id: " + er.Id.ToString() ); tx.Commit(); } return Result.Succeeded; }
/// <summary> /// Given an edge Array converts it to a curveArray /// </summary> /// <param name="edgeArray">edgeArray to convert</param> /// <param name="curveArray">curveArray to fill</param> /// <returns>a curveArray</returns> public static CurveArray ToCurveArray(EdgeArray edgeArray, CurveArray curveArray) { EdgeArrayIterator edgeArrayIter = edgeArray.ForwardIterator(); while (edgeArrayIter.MoveNext()) { Edge edge = edgeArrayIter.Current as Edge; XYZ startPt = edge.Tessellate()[0]; XYZ endPt = edge.Tessellate()[1]; Line curve = Line.CreateBound(startPt, endPt); curveArray.Append(curve); } return curveArray; }
static Blend CreateBlend( Document doc ) { Debug.Assert( doc.IsFamilyDocument, "this method will only work in a family document" ); Application app = doc.Application; Autodesk.Revit.Creation.Application creApp = app.Create; Autodesk.Revit.Creation.FamilyItemFactory factory = doc.FamilyCreate; double startAngle = 0; double midAngle = Math.PI; double endAngle = 2 * Math.PI; XYZ xAxis = XYZ.BasisX; XYZ yAxis = XYZ.BasisY; XYZ center = XYZ.Zero; XYZ normal = -XYZ.BasisZ; double radius = 0.7579; //Arc arc1 = creApp.NewArc( center, radius, startAngle, midAngle, xAxis, yAxis ); // 2013 //Arc arc2 = creApp.NewArc( center, radius, midAngle, endAngle, xAxis, yAxis ); // 2013 Arc arc1 = Arc.Create( center, radius, startAngle, midAngle, xAxis, yAxis ); // 2014 Arc arc2 = Arc.Create( center, radius, midAngle, endAngle, xAxis, yAxis ); // 2014 CurveArray baseProfile = new CurveArray(); baseProfile.Append( arc1 ); baseProfile.Append( arc2 ); // create top profile: CurveArray topProfile = new CurveArray(); bool circular_top = false; if( circular_top ) { // create a circular top profile: XYZ center2 = new XYZ( 0, 0, 1.27 ); //Arc arc3 = creApp.NewArc( center2, radius, startAngle, midAngle, xAxis, yAxis ); // 2013 //Arc arc4 = creApp.NewArc( center2, radius, midAngle, endAngle, xAxis, yAxis ); // 2013 Arc arc3 = Arc.Create( center2, radius, startAngle, midAngle, xAxis, yAxis ); // 2014 Arc arc4 = Arc.Create( center2, radius, midAngle, endAngle, xAxis, yAxis ); // 2014 topProfile.Append( arc3 ); topProfile.Append( arc4 ); } else { // create a skewed rectangle top profile: XYZ[] pts = new XYZ[] { new XYZ(0,0,3), new XYZ(2,0,3), new XYZ(3,2,3), new XYZ(0,4,3) }; for( int i = 0; i < 4; ++i ) { //topProfile.Append( creApp.NewLineBound( // 2013 topProfile.Append( Line.CreateBound( // 2014 pts[0 == i ? 3 : i - 1], pts[i] ) ); } } Plane basePlane = creApp.NewPlane( normal, center ); //SketchPlane sketch = factory.NewSketchPlane( basePlane ); // 2013 SketchPlane sketch = SketchPlane.Create( doc, basePlane ); // 2014 Blend blend = factory.NewBlend( true, topProfile, baseProfile, sketch ); return blend; }
Result Execute2( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; using( Transaction tx = new Transaction( doc ) ) { tx.Start( "Create a Floor" ); int n = 4; XYZ[] points = new XYZ[n]; points[0] = XYZ.Zero; points[1] = new XYZ( 10.0, 0.0, 0.0 ); points[2] = new XYZ( 10.0, 10.0, 0.0 ); points[3] = new XYZ( 0.0, 10.0, 0.0 ); CurveArray curve = new CurveArray(); for( int i = 0; i < n; i++ ) { Line line = Line.CreateBound( points[i], points[( i < n - 1 ) ? i + 1 : 0] ); curve.Append( line ); } doc.Create.NewFloor( curve, true ); tx.Commit(); } return Result.Succeeded; }
/// <summary> /// get necessary data when create AreaReinforcement on a straight wall /// </summary> /// <param name="wall">wall on which to create AreaReinforcemen</param> /// <param name="refer">reference of the vertical straight face on the wall</param> /// <param name="curves">curves compose the vertical face of the wall</param> /// <returns>is successful</returns> public bool GetWallGeom(Wall wall, ref Reference refer, ref CurveArray curves) { FaceArray faces = GeomUtil.GetFaces(wall); LocationCurve locCurve = wall.Location as LocationCurve; //unless API has bug, locCurve can't be null if (null == locCurve) { return false; } //check the location is line Line locLine = locCurve.Curve as Line; if (null == locLine) { return false; } //get the face reference foreach (Face face in faces) { if (GeomUtil.IsParallel(face, locLine)) { refer = face.Reference; break; } } //can't find proper reference if (null == refer) { return false; } //check the analytical model profile is rectangular AnalyticalModel model = wall.GetAnalyticalModel() ; if (null == model) { return false; } IList<Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves); curves = m_currentDoc.Application.Create.NewCurveArray(); foreach (Curve curve in curveList) { curves.Append(curve); } if (!GeomUtil.IsRectangular(curves)) { return false; } return true; }
private Value AddCurves(FamilyInstance fi, GeometryElement geomElem, int count, ref CurveArray curves) { foreach (GeometryObject geomObj in geomElem) { Curve curve = geomObj as Curve; if (null != curve) { curves.Append(curve); continue; } //If this GeometryObject is Instance, call AddCurve GeometryInstance geomInst = geomObj as GeometryInstance; if (null != geomInst) { //curve live in family symbol in this case, need to apply the correct transform to get them in to //the project coordinate system lining up with the instance // http://wikihelp.autodesk.com/Revit/enu/2012/Help/API_Dev_Guide/0074-Revit_Ge74/0108-Geometry108/0110-Geometry110/GeometryInstances //Autodesk.Revit.DB.GeometryElement transformedGeomElem // curves transformed into project coords // = geomInst.GetInstanceGeometry(geomInst.Transform); //AddCurves(fi, transformedGeomElem, count, ref curves); GeometryElement transformedGeomElem // curves transformed into project coords = geomInst.GetInstanceGeometry(); AddCurves(fi, transformedGeomElem, count, ref curves); //Autodesk.Revit.DB.GeometryElement symbolTransformedGeomElem // curves in symbol coords // = geomInst.GetSymbolGeometry(geomInst.Transform); //AddCurves(fi, symbolTransformedGeomElem, count, ref curves); } } return Value.NewContainer(curves); }
/// <summary> /// Creates a new Sketch Plane from a Curve /// </summary> /// <param name="document">Active Document</param> /// <param name="curve">Curve to get plane from</param> /// <returns>Plane of the curve</returns> public static SketchPlane NewSketchPlaneFromCurve(Document document, Autodesk.Revit.DB.Curve curve) { XYZ startPoint = curve.GetEndPoint(0); XYZ endPoint = curve.GetEndPoint(1); // If Start end Endpoint are the same check further points. int i = 2; while (startPoint == endPoint && endPoint != null) { endPoint = curve.GetEndPoint(i); i++; } // Plane to return Plane plane; // If Z Values are equal the Plane is XY if (startPoint.Z == endPoint.Z) { plane = document.Application.Create.NewPlane(XYZ.BasisZ, startPoint); } // If X Values are equal the Plane is YZ else if (startPoint.X == endPoint.X) { plane = document.Application.Create.NewPlane(XYZ.BasisX, startPoint); } // If Y Values are equal the Plane is XZ else if (startPoint.Y == endPoint.Y) { plane = document.Application.Create.NewPlane(XYZ.BasisY, startPoint); } // Otherwise the Planes Normal Vector is not X,Y or Z. // We draw lines from the Origin to each Point and use the Plane this one spans up. else { CurveArray curves = new CurveArray(); curves.Append(curve); curves.Append(Autodesk.Revit.DB.Line.CreateBound(new XYZ(0, 0, 0), startPoint)); curves.Append(Autodesk.Revit.DB.Line.CreateBound(endPoint, new XYZ(0, 0, 0))); plane = document.Application.Create.NewPlane(curves); } // return new Sketchplane return SketchPlane.Create(document, plane); }
/// <summary> /// Create a Revit Floor given it's curve outline and Level /// </summary> /// <param name="outline"></param> /// <param name="floorType"></param> /// <param name="level"></param> /// <returns>The floor</returns> public static Floor ByOutlineTypeAndLevel(PolyCurve outline, FloorType floorType, Level level) { if (outline == null) { throw new ArgumentNullException("outline"); } if (floorType == null) { throw new ArgumentNullException("floorType"); } if ( level == null ) { throw new ArgumentNullException("level"); } if (!outline.IsClosed) { throw new ArgumentException("The input PolyCurve is not closed"); } var ca = new CurveArray(); outline.Curves().ForEach(x => ca.Append(x.ToRevitType())); return new Floor(ca, floorType.InternalFloorType, level.InternalLevel ); }