public static SpecklePolycurve getFloorOutline(Autodesk.Revit.DB.Floor myFloor) { var geometry = myFloor.get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Medium }); var poly = new SpecklePolycurve(); poly.Segments = new List <SpeckleObject>(); foreach (Solid solid in geometry) // let's hope it's only one? { if (solid == null) { continue; } var f = GetLowestFace(solid); var crvLoops = f.GetEdgesAsCurveLoops(); foreach (var crvloop in crvLoops) { foreach (var curve in crvloop) { var c = curve as Autodesk.Revit.DB.Curve; if (c == null) { continue; } poly.Segments.Add(SpeckleCore.Converter.Serialise(c) as SpeckleObject); } } } return(poly); }
public static PolyCurve ToNative(this SpecklePolycurve p) { PolyCurve myPolyc = new PolyCurve(); foreach (var segment in p.Segments) { switch (segment) { case SpeckleCore.SpeckleCurve crv: myPolyc.Append(crv.ToNative()); break; case SpeckleCore.SpeckleLine crv: myPolyc.Append(crv.ToNative()); break; case SpeckleCore.SpeckleArc crv: myPolyc.Append(crv.ToNative()); break; case SpeckleCore.SpecklePolyline crv: myPolyc.Append(crv.ToNative()); break; } } myPolyc.UserDictionary.ReplaceContentsWith(p.Properties.ToNative()); if (p.Domain != null) { myPolyc.Domain = p.Domain.ToNative(); } return(myPolyc); }
public static PolyCurve ToNative(this SpecklePolycurve p) { PolyCurve myPolyc = new PolyCurve(); foreach (var segment in p.Segments) { if (segment.Type == "Curve") { myPolyc.Append((( SpeckleCurve )segment).ToNative()); } if (segment.Type == "Line") { myPolyc.Append((( SpeckleLine )segment).ToNative()); } if (segment.Type == "Arc") { myPolyc.Append((( SpeckleArc )segment).ToNative()); } if (segment.Type == "Polyline") { myPolyc.Append((( SpecklePolyline )segment).ToNative().ToNurbsCurve()); } } myPolyc.UserDictionary.ReplaceContentsWith(p.Properties.ToNative()); return(myPolyc); }
// Polycurve // Rh Capture/Gh Capture public static SpecklePolycurve ToSpeckle(this PolyCurve p) { SpecklePolycurve myPoly = new SpecklePolycurve(); p.RemoveNesting(); var segments = p.Explode(); myPoly.Segments = segments.Select(s => { return(s.ToSpeckle()); }).ToArray(); myPoly.Properties = p.UserDictionary.ToSpeckle(); myPoly.SetHashes(myPoly.Segments.Select(obj => obj.Hash).ToArray()); return(myPoly); }
public static Space ToSpeckle(this Autodesk.Revit.DB.Mechanical.Space mySpace) { var speckleSpace = new SpeckleElementsClasses.Space(); //Name & number speckleSpace.spaceName = mySpace.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOM_NAME).AsString(); speckleSpace.spaceNumber = mySpace.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOM_NUMBER).AsString(); //Location var locPt = ((Autodesk.Revit.DB.LocationPoint)mySpace.Location).Point; speckleSpace.spaceLocation = new SpecklePoint(locPt.X / Scale, locPt.Y / Scale, locPt.Z / Scale); //speckleSpace.levelElementId = mySpace.LevelId.IntegerValue.ToString(); //speckleSpace.phaseElementId = mySpace.GetParameters("Phase Id").FirstOrDefault().AsElementId().ToString(); //3d geometry (speckleSpace.Faces, speckleSpace.Vertices) = GetFaceVertexArrayFromElement(mySpace); //2d boundary curve var seg = mySpace.GetBoundarySegments(new Autodesk.Revit.DB.SpatialElementBoundaryOptions()); var myPolyCurve = new SpecklePolycurve() { Segments = new List <SpeckleCore.SpeckleObject>() }; foreach (BoundarySegment segment in seg[0]) { var crv = segment.GetCurve(); var converted = SpeckleCore.Converter.Serialise(crv); myPolyCurve.Segments.Add(converted as SpeckleObject); } speckleSpace.baseCurve = myPolyCurve; //parameters speckleSpace.parameters = GetElementParams(mySpace); //try get type parameters if (mySpace.IsValidType(mySpace.GetTypeId())) { speckleSpace.typeParameters = GetElementTypeParams(mySpace); } //global parameters speckleSpace.ApplicationId = mySpace.UniqueId; speckleSpace.elementId = mySpace.Id.ToString(); speckleSpace.GenerateHash(); return(speckleSpace); }
//public static EllipseArc ToNative(this SpeckleCurve arc) //{ // //TODO: Implement EllipseArc converter // throw new NotImplementedException("EllipsArc not implemented yet."); //} /// <summary> /// DS Polycurve to SpecklePolyline if all curves are linear /// SpecklePolycurve otherwise /// </summary> /// <param name="polycurve"></param> /// <returns name="speckleObject"></returns> public static SpeckleObject ToSpeckle(this PolyCurve polycurve) { if (polycurve.IsPolyline()) { var points = polycurve.Curves().SelectMany(c => c.StartPoint.ToArray()).ToList(); points.AddRange(polycurve.Curves().Last().EndPoint.ToArray()); return(new SpecklePolyline(points)); } else { SpecklePolycurve spkPolycurve = new SpecklePolycurve(); spkPolycurve.Segments = polycurve.Curves().Select(c => c.ToSpeckle()).ToList(); spkPolycurve.GenerateHash(); return(spkPolycurve); } }
// Polycurve // Rh Capture/Gh Capture public static SpecklePolycurve ToSpeckle(this PolyCurve p) { SpecklePolycurve myPoly = new SpecklePolycurve(); myPoly.Closed = p.IsClosed; myPoly.Domain = p.Domain.ToSpeckle(); var segments = new List <Curve>(); CurveSegments(segments, p, true); myPoly.Segments = segments.Select(s => { return(SpeckleCore.Converter.Serialise(s) as SpeckleObject); }).ToList(); myPoly.Properties = p.UserDictionary.ToSpeckle(root: p); myPoly.GenerateHash(); return(myPoly); }
public static PolyCurve ToNative(this SpecklePolycurve p) { PolyCurve myPolyc = new PolyCurve(); foreach (var segment in p.Segments) { try { myPolyc.AppendSegment(( Curve )Converter.Deserialise(segment)); } catch { } } myPolyc.UserDictionary.ReplaceContentsWith(p.Properties.ToNative()); if (p.Domain != null) { myPolyc.Domain = p.Domain.ToNative(); } return(myPolyc); }
public static Room ToSpeckle(this Autodesk.Revit.DB.Architecture.Room myRoom) { var speckleRoom = new Room(); speckleRoom.roomName = myRoom.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOM_NAME).AsString(); speckleRoom.roomNumber = myRoom.Number; var locPt = ((Autodesk.Revit.DB.LocationPoint)myRoom.Location).Point; speckleRoom.roomLocation = new SpecklePoint(locPt.X / Scale, locPt.Y / Scale, locPt.Z / Scale); (speckleRoom.Faces, speckleRoom.Vertices) = GetFaceVertexArrayFromElement(myRoom); // TODO: Get and set the boundary curve var seg = myRoom.GetBoundarySegments(new Autodesk.Revit.DB.SpatialElementBoundaryOptions()); var myPolyCurve = new SpecklePolycurve() { Segments = new List <SpeckleCore.SpeckleObject>() }; foreach (BoundarySegment segment in seg[0]) { var crv = segment.GetCurve(); var converted = SpeckleCore.Converter.Serialise(crv); myPolyCurve.Segments.Add(converted as SpeckleObject); } speckleRoom.baseCurve = myPolyCurve; speckleRoom.parameters = GetElementParams(myRoom); if (myRoom.IsValidType(myRoom.GetTypeId())) { speckleRoom.typeParameters = GetElementTypeParams(myRoom); } speckleRoom.ApplicationId = myRoom.UniqueId; speckleRoom.elementId = myRoom.Id.ToString(); speckleRoom.GenerateHash(); return(speckleRoom); }
public static PolyCurve ToNative(this SpecklePolycurve polycurve) { Curve[] curves = new Curve[polycurve.Segments.Count]; for (var i = 0; i < polycurve.Segments.Count; i++) { switch (polycurve.Segments[i]) { case SpeckleLine curve: curves[i] = curve.ToNative(); break; case SpeckleArc curve: curves[i] = curve.ToNative(); break; case SpeckleCircle curve: curves[i] = curve.ToNative(); break; case SpeckleEllipse curve: curves[i] = curve.ToNative(); break; case SpecklePolycurve curve: curves[i] = curve.ToNative(); break; case SpecklePolyline curve: curves[i] = curve.ToNative(); break; case SpeckleCurve curve: curves[i] = curve.ToNative(); break; } } var polyCrv = PolyCurve.ByJoinedCurves(curves); return(polyCrv.SetSpeckleProperties <PolyCurve>(polycurve.Properties)); }
// NOTE: if we will include more element based openings, we will need to figure out how to split this method, // or create a generic opening class // TODO: actually test this public static Shaft ToSpeckle(this Opening myShaft) { var spkShaft = new SpeckleElementsClasses.Shaft(); var poly = new SpecklePolycurve(); poly.Segments = new List <SpeckleObject>(); foreach (Autodesk.Revit.DB.Curve curve in myShaft.BoundaryCurves) { if (curve == null) { continue; } poly.Segments.Add(SpeckleCore.Converter.Serialise(curve) as SpeckleObject); } spkShaft.baseCurve = poly; spkShaft.ApplicationId = myShaft.UniqueId; spkShaft.elementId = myShaft.Id.ToString(); spkShaft.GenerateHash(); return(null); }
public static SpecklePolycurve ToSpecklePolycurve(this PolycurvePayload payload) { var polycurve = new SpecklePolycurve(); polycurve.Closed = payload.Closed; polycurve.Segments = new List <SpeckleObject>(); foreach (var segment in payload.Segments) { if (segment.SegmentType == SegmentType.Arc) { var arcPayload = JsonConvert.DeserializeObject <ArcPayload>(segment.Data); polycurve.Segments.Add(arcPayload.ToSpeckleArc()); } else if (segment.SegmentType == SegmentType.Line) { var linePayload = JsonConvert.DeserializeObject <LinePayload>(segment.Data); polycurve.Segments.Add(linePayload.ToSpeckleLine()); } } return(polycurve); }