//Nesting the various profiles into a polycurve segments private List <ICurve> GetProfiles(DB.CeilingAndFloor floor) { var profiles = new List <ICurve>(); var faces = HostObjectUtils.GetTopFaces(floor); Face face = floor.GetGeometryObjectFromReference(faces[0]) as Face; var crvLoops = face.GetEdgesAsCurveLoops(); foreach (var crvloop in crvLoops) { var poly = new Polycurve(ModelUnits); foreach (var curve in crvloop) { var c = curve; if (c == null) { continue; } poly.segments.Add(CurveToSpeckle(c)); } profiles.Add(poly); } return(profiles); }
public ETABSTendon ETABSTendonToSpeckle(string name) { var speckleETABSTendon = new ETABSTendon(); int numberPoints = 0; double[] X = null; double[] Y = null; double[] Z = null; Model.TendonObj.GetTendonGeometry(name, ref numberPoints, ref X, ref Y, ref Z); if (numberPoints != 0) { var polyLine = new Polycurve(); for (int i = 0; i < numberPoints - 1; i++) { var pt1 = new Point(X[i], Y[i], Z[i]); var pt2 = new Point(X[i + 1], Y[i + 1], Z[i + 1]); var line = new Line(pt1, pt2); polyLine.segments.Add(line); } speckleETABSTendon.polycurve = polyLine; } string tendonProp = null; Model.TendonObj.GetProperty(name, ref tendonProp); speckleETABSTendon.ETABSTendonProperty = TendonPropToSpeckle(tendonProp); SpeckleModel.elements.Add(speckleETABSTendon); return(speckleETABSTendon); }
public RevitRailing(string type, Polycurve baseCurve, Level level, bool flipped = false) { this.type = type; this.path = baseCurve; this.level = level; this.flipped = flipped; }
/// <summary> /// DS Polycurve to SpecklePolyline if all curves are linear /// SpecklePolycurve otherwise /// </summary> /// <param name="polycurve"></param> /// <returns name="speckleObject"></returns> public Base PolycurveToSpeckle(PolyCurve polycurve, string units = null) { var u = units ?? ModelUnits; if (polycurve.IsPolyline()) { var points = polycurve.Curves().SelectMany(c => PointToArray(c.StartPoint)).ToList(); points.AddRange(PointToArray(polycurve.Curves().Last().EndPoint)); var poly = new Polyline(points, u); CopyProperties(poly, polycurve); poly.length = polycurve.Length; poly.bbox = BoxToSpeckle(polycurve.BoundingBox.ToCuboid(), u); return(poly); } else { Polycurve spkPolycurve = new Polycurve(u); CopyProperties(spkPolycurve, polycurve); spkPolycurve.segments = polycurve.Curves().Select(c => (ICurve)CurveToSpeckle(c, u)).ToList(); spkPolycurve.length = polycurve.Length; spkPolycurve.bbox = BoxToSpeckle(polycurve.BoundingBox.ToCuboid(), u); return(spkPolycurve); } }
//Nesting the various profiles into a polycurve segments private List <ICurve> GetProfiles(DB.RoofBase roof) { // TODO handle case if not one of our supported roofs var profiles = new List <ICurve>(); switch (roof) { case FootPrintRoof footprint: { ModelCurveArrArray crvLoops = footprint.GetProfiles(); for (var i = 0; i < crvLoops.Size; i++) { var crvLoop = crvLoops.get_Item(i); var poly = new Polycurve(ModelUnits); foreach (DB.ModelCurve curve in crvLoop) { if (curve == null) { continue; } var segment = CurveToSpeckle(curve.GeometryCurve) as Base; //it's a safe casting segment["slopeAngle"] = GetParamValue <double>(curve, BuiltInParameter.ROOF_SLOPE); segment["isSloped"] = GetParamValue <bool>(curve, BuiltInParameter.ROOF_CURVE_IS_SLOPE_DEFINING); segment["offset"] = GetParamValue <double>(curve, BuiltInParameter.ROOF_CURVE_HEIGHT_OFFSET); poly.segments.Add(segment as ICurve); //roud profiles are returned duplicated! if (curve is ModelArc arc && RevitVersionHelper.IsCurveClosed(arc.GeometryCurve)) { break; } } profiles.Add(poly); } break; } case ExtrusionRoof extrusion: { var crvloop = extrusion.GetProfile(); var poly = new Polycurve(ModelUnits); foreach (DB.ModelCurve curve in crvloop) { if (curve == null) { continue; } poly.segments.Add(CurveToSpeckle(curve.GeometryCurve)); } profiles.Add(poly); break; } } return(profiles); }
public static dynamic GetTSObject(Polycurve dynObject) { if (dynObject is null) { return(null); } return(dynObject.teklaObject); }
public Polycurve CurveListToSpeckle(IList <DB.Curve> loop, string units = null) { var polycurve = new Polycurve(); polycurve.units = units ?? ModelUnits; polycurve.closed = loop.First().GetEndPoint(0).DistanceTo(loop.Last().GetEndPoint(1)) < 0.0164042; //5mm polycurve.length = ScaleToSpeckle(loop.Sum(x => x.Length)); polycurve.segments.AddRange(loop.Select(x => CurveToSpeckle(x))); return(polycurve); }
public Polycurve CurveLoopToSpeckle(CurveLoop loop) { var polycurve = new Polycurve(); polycurve.units = ModelUnits; polycurve.closed = !loop.IsOpen(); polycurve.length = ScaleToSpeckle(loop.GetExactLength()); polycurve.segments.AddRange(loop.Select(x => CurveToSpeckle(x))); return(polycurve); }
public Polycurve CurveLoopToSpeckle(CurveLoop loop, string units = null) { var polycurve = new Polycurve(); polycurve.units = units ?? ModelUnits; polycurve.closed = !loop.IsOpen(); polycurve.length = units == Units.None ? loop.GetExactLength() : ScaleToSpeckle(loop.GetExactLength()); polycurve.segments.AddRange(loop.Select(x => CurveToSpeckle(x))); return(polycurve); }
public PolyCurve PolycurveToNative(Polycurve polycurve) { DS.Curve[] curves = new DS.Curve[polycurve.segments.Count]; for (var i = 0; i < polycurve.segments.Count; i++) { switch (polycurve.segments[i]) { case Line curve: curves[i] = LineToNative(curve); break; case Arc curve: curves[i] = ArcToNative(curve); break; case Circle curve: curves[i] = CircleToNative(curve); break; case Ellipse curve: curves[i] = EllipseToNative(curve); break; case Spiral curve: curves[i] = PolylineToNative(curve.displayValue); break; case Polycurve curve: curves[i] = PolycurveToNative(curve); break; case Polyline curve: curves[i] = PolylineToNative(curve); break; case Curve curve: curves[i] = CurveToNative(curve); break; } } PolyCurve polyCrv = null; if (curves.Any()) { polyCrv = PolyCurve.ByJoinedCurves(curves); polyCrv = polyCrv.SetDynamoProperties <PolyCurve>(GetDynamicMembersFromBase(polycurve)); } return(polyCrv); }
/// <summary> /// Constructs a transition section geometry /// </summary> /// <param name="rectangularHeight">Height of the rectangular base</param> /// <param name="rectangularWidth">Width of the rectangular base</param> /// <param name="transitionLength">Length of the transition section</param> /// <param name="circularSectionRadius">Radius of the cylindrical section</param> /// <param name="baseCentroid">Centroid of the rectangular base</param> /// <param name="normalDirection">Normal of the plane where the rectangular section is located</param> public TransitionSectionGeometry(double rectangularHeight, double rectangularWidth, double transitionLength, double circularSectionRadius, Point baseCentroid, Vector normalDirection) { this.RectangularHeight = rectangularHeight; this.RectangularWidth = rectangularWidth; this.TransitionLength = transitionLength; this.CircularRadius = circularSectionRadius; this.BaseCentroid = baseCentroid; this.Normal = normalDirection; this.RectangularSection = this.GetRectangularSection(); this.CircularSection = this.GetCircularSection(); }
/// <summary> /// Draws the preview of a polycurve. /// </summary> /// <param name="polycurve">Curve to draw.</param> private void DrawPolycurve(Polycurve polycurve) { foreach (var curve in polycurve) { if (curve is LineSegment segment) { this.Graphics.DrawLine(segment.StartPoint, segment.EndPoint); } else if (curve is Arc arc) { this.Graphics.DrawArc(arc); } } }
// Polycurve // Rh Capture/Gh Capture public Polycurve PolycurveToSpeckle(PolyCurve p) { var myPoly = new Polycurve(); myPoly.closed = p.IsClosed; myPoly.domain = IntervalToSpeckle(p.Domain); var segments = new List <RH.Curve>(); CurveSegments(segments, p, true); //let the converter pick the best type of curve myPoly.segments = segments.Select(s => (ICurve)ConvertToSpeckle(s)).ToList(); return(myPoly); }
// Polycurve // Rh Capture/Gh Capture public Polycurve PolycurveToSpeckle(PolyCurve p, string units = null) { var u = units ?? ModelUnits; var myPoly = new Polycurve(); myPoly.closed = p.IsClosed; myPoly.domain = IntervalToSpeckle(p.Domain); myPoly.length = p.GetLength(); myPoly.bbox = BoxToSpeckle(new RH.Box(p.GetBoundingBox(true)), u); var segments = new List <RH.Curve>(); CurveSegments(segments, p, true); //let the converter pick the best type of curve myPoly.segments = segments.Select(s => CurveToSpeckle(s, u)).ToList(); myPoly.units = u; return(myPoly); }
/// <summary> /// DS Polycurve to SpecklePolyline if all curves are linear /// SpecklePolycurve otherwise /// </summary> /// <param name="polycurve"></param> /// <returns name="speckleObject"></returns> public Base PolycurveToSpeckle(PolyCurve polycurve) { if (polycurve.IsPolyline()) { var points = polycurve.Curves().SelectMany(c => PointToArray(c.StartPoint)).ToList(); points.AddRange(PointToArray(polycurve.Curves().Last().EndPoint)); var poly = new Polyline(points, ModelUnits); CopyProperties(poly, polycurve); return(poly); } else { Polycurve spkPolycurve = new Polycurve(); CopyProperties(spkPolycurve, polycurve); spkPolycurve.segments = polycurve.Curves().Select(c => (ICurve)CurveToSpeckle(c)).ToList(); return(spkPolycurve); } }
/// <summary> /// Transforms a given polycurve in the local coordsys to global. /// </summary> /// <param name="curveInLocal">Curve in local coordinates.</param> /// <returns>The transformed polycurve in global coordinates.</returns> private Polycurve TransformToGlobal(Polycurve curveInLocal) { var coordSys = GetBaseCoordsys(this.BaseCentroid, this.Normal); var toGlobal = MatrixFactory.FromCoordinateSystem(coordSys); var transformedCurves = curveInLocal.Select(c => TransformGeometryByMatrix(c, toGlobal)); var builder = new PolycurveGeometryBuilder(); foreach (var curve in transformedCurves) { if (curve is Arc arc) { builder.Append(arc); } else if (curve is LineSegment segment) { builder.Append(segment); } } return(builder.GetPolycurve()); }
public PolyCurve PolycurveToNative(Polycurve p) { PolyCurve myPolyc = new PolyCurve(); foreach (var segment in p.segments) { try { //let the converter pick the best type of curve myPolyc.AppendSegment((RH.Curve)ConvertToNative((Base)segment)); } catch { } } if (p.domain != null) { myPolyc.Domain = IntervalToNative(p.domain); } return(myPolyc); }
public static List <ICurve> FromArray(List <double> list) { var curves = new List <ICurve>(); if (list.Count == 0) { return(curves); } var done = false; var currentIndex = 0; while (!done) { var itemLength = (int)list[currentIndex]; var item = list.GetRange(currentIndex, itemLength + 1); switch (item[1]) { case CurveTypeEncoding.Arc: curves.Add(Arc.FromList(item)); break; case CurveTypeEncoding.Circle: curves.Add(Circle.FromList(item)); break; case CurveTypeEncoding.Curve: curves.Add(Curve.FromList(item)); break; case CurveTypeEncoding.Ellipse: curves.Add(Ellipse.FromList(item)); break; case CurveTypeEncoding.Line: curves.Add(Line.FromList(item)); break; case CurveTypeEncoding.Polyline: curves.Add(Polyline.FromList(item)); break; case CurveTypeEncoding.PolyCurve: curves.Add(Polycurve.FromList(item)); break; } currentIndex += itemLength + 1; done = currentIndex >= list.Count; } return(curves); }
private List <ICurve> GetProfiles(DB.Room room) { var profiles = new List <ICurve>(); var boundaries = room.GetBoundarySegments(new SpatialElementBoundaryOptions()); foreach (var loop in boundaries) { var poly = new Polycurve(ModelUnits); foreach (var segment in loop) { var c = segment.GetCurve(); if (c == null) { continue; } poly.segments.Add(CurveToSpeckle(c)); } profiles.Add(poly); } return(profiles); }
public Objects.Geometry.Polycurve PolycurveFromTopology(List <Node> nodes) { Polycurve polycurve = new Polycurve(); foreach (int index in Enumerable.Range(0, nodes.Count)) { if (index == nodes.Count - 1) { var point1 = nodes[index].basePoint; var point2 = nodes[0].basePoint; Geometry.Line segment = new Geometry.Line(point1, point2, point1.units); polycurve.segments.Add(segment); } else { var point1 = nodes[index].basePoint; var point2 = nodes[index + 1].basePoint; Geometry.Line segment = new Geometry.Line(point1, point2, point1.units); polycurve.segments.Add(segment); } } return(polycurve); }
public BuiltElements.Opening OpeningToSpeckle(DB.Opening revitOpening) { if (!ShouldConvertHostedElement(revitOpening, revitOpening.Host)) { return(null); } RevitOpening speckleOpening; if (revitOpening.IsRectBoundary) { speckleOpening = new RevitWallOpening(); var poly = new Polyline(); poly.value = new List <double>(); //2 points: bottom left and top right var btmLeft = PointToSpeckle(revitOpening.BoundaryRect[0]); var topRight = PointToSpeckle(revitOpening.BoundaryRect[1]); poly.value.AddRange(btmLeft.value); poly.value.AddRange(new Point(btmLeft.value[0], btmLeft.value[1], topRight.value[2], ModelUnits).value); poly.value.AddRange(topRight.value); poly.value.AddRange(new Point(topRight.value[0], topRight.value[1], btmLeft.value[2], ModelUnits).value); poly.value.AddRange(btmLeft.value); poly.units = ModelUnits; speckleOpening.outline = poly; } else { if (revitOpening.Host != null) { //we can ignore vertical openings because they will be created when we try re-create voids in the roof / ceiling / floor outline return(null); //speckleOpening = new RevitVerticalOpening(); } else { speckleOpening = new RevitShaft(); if (revitOpening.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE) != null) { ((RevitShaft)speckleOpening).topLevel = ConvertAndCacheLevel(revitOpening, BuiltInParameter.WALL_HEIGHT_TYPE); ((RevitShaft)speckleOpening).bottomLevel = ConvertAndCacheLevel(revitOpening, BuiltInParameter.WALL_BASE_CONSTRAINT); ((RevitShaft)speckleOpening).height = GetParamValue <double>(revitOpening, BuiltInParameter.WALL_USER_HEIGHT_PARAM); } } var poly = new Polycurve(ModelUnits); poly.segments = new List <ICurve>(); foreach (DB.Curve curve in revitOpening.BoundaryCurves) { if (curve != null) { poly.segments.Add(CurveToSpeckle(curve)); } } speckleOpening.outline = poly; } //speckleOpening.type = revitOpening.Name; GetAllRevitParamsAndIds(speckleOpening, revitOpening, new List <string> { "WALL_BASE_CONSTRAINT", "WALL_HEIGHT_TYPE", "WALL_USER_HEIGHT_PARAM" }); return(speckleOpening); }
private Element2D AnalyticalSurfaceToSpeckle(AnalyticalModelSurface revitSurface) { if (!revitSurface.IsEnabled()) { return(new Element2D()); } var speckleElement2D = new Element2D(); var structuralElement = Doc.GetElement(revitSurface.GetElementId()); var mark = GetParamValue <string>(structuralElement, BuiltInParameter.ALL_MODEL_MARK); speckleElement2D.name = mark; var edgeNodes = new List <Node> { }; var loops = revitSurface.GetLoops(AnalyticalLoopType.External); var displayLine = new Polycurve(); foreach (var loop in loops) { var coor = new List <double>(); foreach (var curve in loop) { var points = curve.Tessellate(); foreach (var p in points.Skip(1)) { var vertex = PointToSpeckle(p); var edgeNode = new Node(vertex, null, null, null); edgeNodes.Add(edgeNode); } displayLine.segments.Add(CurveToSpeckle(curve)); } } speckleElement2D.topology = edgeNodes; speckleElement2D["displayValue"] = displayLine; var voidNodes = new List <List <Node> > { }; var voidLoops = revitSurface.GetLoops(AnalyticalLoopType.Void); foreach (var loop in voidLoops) { var loopNodes = new List <Node>(); foreach (var curve in loop) { var points = curve.Tessellate(); foreach (var p in points.Skip(1)) { var vertex = PointToSpeckle(p); var voidNode = new Node(vertex, null, null, null); loopNodes.Add(voidNode); } } voidNodes.Add(loopNodes); } //speckleElement2D.voids = voidNodes; //var mesh = new Geometry.Mesh(); //var solidGeom = GetElementSolids(structuralElement); //(mesh.faces, mesh.vertices) = GetFaceVertexArrFromSolids(solidGeom); //speckleElement2D.baseMesh = mesh; var prop = new Property2D(); // Material DB.Material structMaterial = null; double thickness = 0; var memberType = MemberType2D.Generic2D; if (structuralElement is DB.Floor) { var floor = structuralElement as DB.Floor; structMaterial = Doc.GetElement(floor.FloorType.StructuralMaterialId) as DB.Material; thickness = GetParamValue <double>(structuralElement, BuiltInParameter.STRUCTURAL_FLOOR_CORE_THICKNESS); memberType = MemberType2D.Slab; } else if (structuralElement is DB.Wall) { var wall = structuralElement as DB.Wall; structMaterial = Doc.GetElement(wall.WallType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()) as DB.Material; thickness = ScaleToSpeckle(wall.WallType.Width); memberType = MemberType2D.Wall; } var materialAsset = ((PropertySetElement)Doc.GetElement(structMaterial.StructuralAssetId)).GetStructuralAsset(); var materialType = structMaterial.MaterialClass; Structural.Materials.Material speckleMaterial = null; switch (materialType) { case "Concrete": var concreteMaterial = new Concrete { name = Doc.GetElement(structMaterial.StructuralAssetId).Name, //type = Structural.MaterialType.Concrete, grade = null, designCode = null, codeYear = null, elasticModulus = materialAsset.YoungModulus.X, compressiveStrength = materialAsset.ConcreteCompression, tensileStrength = 0, flexuralStrength = 0, maxCompressiveStrain = 0, maxTensileStrain = 0, maxAggregateSize = 0, lightweight = materialAsset.Lightweight, poissonsRatio = materialAsset.PoissonRatio.X, shearModulus = materialAsset.ShearModulus.X, density = materialAsset.Density, thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, dampingRatio = 0 }; speckleMaterial = concreteMaterial; break; case "Steel": var steelMaterial = new Steel { name = Doc.GetElement(structMaterial.StructuralAssetId).Name, //type = Structural.MaterialType.Steel, grade = materialAsset.Name, designCode = null, codeYear = null, elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter yieldStrength = materialAsset.MinimumYieldStress, // Newtons per foot meter ultimateStrength = materialAsset.MinimumTensileStrength, // Newtons per foot meter maxStrain = 0, poissonsRatio = materialAsset.PoissonRatio.X, shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter density = materialAsset.Density, // kilograms per cubed feet thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin dampingRatio = 0 }; speckleMaterial = steelMaterial; break; case "Wood": var timberMaterial = new Timber { name = Doc.GetElement(structMaterial.StructuralAssetId).Name, //type = Structural.MaterialType.Timber, grade = materialAsset.WoodGrade, designCode = null, codeYear = null, elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter poissonsRatio = materialAsset.PoissonRatio.X, shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter density = materialAsset.Density, // kilograms per cubed feet thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin species = materialAsset.WoodSpecies, dampingRatio = 0 }; timberMaterial["bendingStrength"] = materialAsset.WoodBendingStrength; timberMaterial["parallelCompressionStrength"] = materialAsset.WoodParallelCompressionStrength; timberMaterial["parallelShearStrength"] = materialAsset.WoodParallelShearStrength; timberMaterial["perpendicularCompressionStrength"] = materialAsset.WoodPerpendicularCompressionStrength; timberMaterial["perpendicularShearStrength"] = materialAsset.WoodPerpendicularShearStrength; speckleMaterial = timberMaterial; break; default: var defaultMaterial = new Structural.Materials.Material { name = Doc.GetElement(structMaterial.StructuralAssetId).Name }; speckleMaterial = defaultMaterial; break; } prop.material = speckleMaterial; prop.name = Doc.GetElement(revitSurface.GetElementId()).Name; //prop.type = memberType; //prop.analysisType = Structural.AnalysisType2D.Shell; prop.thickness = thickness; speckleElement2D.property = prop; GetAllRevitParamsAndIds(speckleElement2D, revitSurface); //speckleElement2D.displayMesh = GetElementDisplayMesh(Doc.GetElement(revitSurface.GetElementId()), // new Options() { DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false }); return(speckleElement2D); }