//method to get thinnest tray element private CableTray ThinnestTray() { try { CableTray thinTray = null; foreach (Element e in trayDuctlist) { if (e is CableTray) { thinTray = e as CableTray; break; } } foreach (Element e in trayDuctlist) { if (e is CableTray) { if (((CableTray)e).Width < thinTray.Width) { thinTray = e as CableTray; } } } return(thinTray); } catch { throw new Exception(); } }
//method to get thinnest tray element private static CableTray MaxWidthTray(List <Element> eleList) { try { CableTray maxTray = null; foreach (Element e in eleList) { if (e is CableTray) { maxTray = e as CableTray; break; } } foreach (Element e in eleList) { if (e is CableTray) { if (((CableTray)e).Width > maxTray.Width) { maxTray = e as CableTray; } } } return(maxTray); } catch { throw new Exception(); } }
public static MaterialComposition MaterialComposition(this CableTray cableTray) { if (cableTray == null) { BH.Engine.Reflection.Compute.RecordError("Cannot query the material composition of a null cable tray."); return(null); } if (cableTray.SectionProperty == null) { Engine.Reflection.Compute.RecordError("The Duct MaterialComposition could not be calculated as no SectionProperty has been assigned."); return(null); } List <Material> materials = null; List <double> ratios = null; materials = new List <Material>() { cableTray.SectionProperty.Material }; ratios = new List <double>() { cableTray.SectionProperty.ElementSolidArea }; return(Matter.Create.MaterialComposition(materials, ratios)); }
public static MEPCurve BreakCurve(this MEPCurve mep, XYZ point) { var locationline = mep.LocationLine(); var start = locationline.StartPoint(); var end = locationline.EndPoint(); var executeflag = point.IsOnLine(locationline) && point.DistanceTo(start) > 1d.MetricToFeet() && point.DistanceTo(end) > 1d.MetricToFeet(); if (!executeflag) { throw new Exception("点不在线上"); } var doc = mep.Document; #if Revit2016 return(null); #endif #if Revit2019 ElementId result = null; if (mep is Duct) { result = MechanicalUtils.BreakCurve(doc, mep.Id, point); } else if (mep is Pipe) { result = PlumbingUtils.BreakCurve(doc, mep.Id, point); } else if (mep is CableTray) { var newline1 = Line.CreateBound(start, point); var newline2 = Line.CreateBound(point, end); (mep.Location as LocationCurve).Curve = newline1; var newcabletray = CableTray.Create(doc, mep.GetTypeId(), point, end, mep.ReferenceLevel.Id); var para_w = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM); var para_H = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM); para_w.Set(mep.Width); para_H.Set(mep.Height); result = newcabletray.Id; } return(result.GetElement(doc) as MEPCurve); #endif }
//method to find maximum width of the tray/duct from list public static Element MaxWidthElement(List <Element> eleList) { try { Element maxWidthEle = null; CableTray maxTray = MaxWidthTray(eleList); Duct maxDuct = MaxWidthDuct(eleList); if (maxDuct != null && maxTray != null) { if (maxDuct.Width >= maxTray.Width) { maxWidthEle = maxDuct as Element; } else { maxWidthEle = maxTray as Element; } return(maxWidthEle); } else if (maxDuct == null && maxTray != null) { maxWidthEle = maxTray as Element; return(maxWidthEle); } else if (maxDuct != null && maxTray == null) { maxWidthEle = maxDuct as Element; return(maxWidthEle); } return(maxWidthEle); } catch { throw new Exception(); } }
public static CableTrayModel Create(CableTray oCableTray) { var curveStartEndPoint = oCableTray.GetStartAndEndPoint(); var connectors = oCableTray.GetConnectors(); if (curveStartEndPoint.Count < 2 || connectors.Count < 2) { return(null); } var pipeModel = new CableTrayModel { Model = oCableTray, Curve = oCableTray.GetCurve(), StarPoint = curveStartEndPoint[0], EndPoint = curveStartEndPoint[1], ConnectorFirst = connectors[0], ConnectorSecond = connectors[1] }; return(pipeModel); }
//method to find the tray or duct with least width public Element LeastWidth() { try { Element thinnest = null; CableTray thinnestTray = ThinnestTray(); Duct thinnestDuct = ThinnestDuct(); if (thinnestDuct != null && thinnestTray != null) { if (thinnestDuct.Width <= thinnestTray.Width) { thinnest = thinnestDuct as Element; } else { thinnest = thinnestTray as Element; } return(thinnest); } else if (thinnestDuct == null && thinnestTray != null) { thinnest = thinnestTray as Element; return(thinnest); } else if (thinnestDuct != null && thinnestTray == null) { thinnest = thinnestDuct as Element; return(thinnest); } return(thinnest); } catch { throw new Exception(); } }
public static double SolidVolume(this CableTray cableTray) { double length = cableTray.Length(); double elementSolidArea = cableTray.SectionProperty.ElementSolidArea; if (length <= 0) { Engine.Reflection.Compute.RecordError("Cannot query SolidVolume from zero length members."); return(double.NaN); } if (cableTray.SectionProperty.SectionProfile.ElementProfile == null) { Engine.Reflection.Compute.RecordWarning("No ElementProfile detected for object " + cableTray.BHoM_Guid); } if (elementSolidArea <= 0) { Engine.Reflection.Compute.RecordNote("ElementSolidArea is 0. Returning 0 for ElementSolidVolume."); } return(length * elementSolidArea); }
public static CableTray Transform(this CableTray cableTray, TransformMatrix transform, double tolerance = Tolerance.Distance) { if (!transform.IsRigidTransformation(tolerance)) { BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported."); return(null); } CableTray result = cableTray.ShallowClone(); result.StartPoint = result.StartPoint.Transform(transform); result.EndPoint = result.EndPoint.Transform(transform); Vector normalBefore = new Line { Start = cableTray.StartPoint, End = cableTray.EndPoint }.ElementNormal(cableTray.OrientationAngle); Vector normalAfter = normalBefore.Transform(transform); result.OrientationAngle = normalAfter.OrientationAngleLinear(new Line { Start = result.StartPoint, End = result.EndPoint }); return(result); }
public static void EletricalQElementMySQLPara(Document doc, FilteredElementCollector cableCollector, System.Data.DataTable dt) { foreach (Element ele in cableCollector) { CableTray cable = ele as CableTray; Level level = level = doc.GetElement(cable.LevelId) as Level; if (cable != null) { string Olev = null; string shuidui = null; string chuizhidui = null; double offset = 0.0; string width = null; string height = null; string hendang = null; string familyname = null; foreach (Parameter param in cable.Parameters) { InternalDefinition definition = null; definition = param.Definition as InternalDefinition; if (null == definition) { continue; } if (BuiltInParameter.RBS_START_LEVEL_PARAM == definition.BuiltInParameter) { Olev = param.AsValueString(); } if (BuiltInParameter.RBS_CURVE_HOR_OFFSET_PARAM == definition.BuiltInParameter) { shuidui = param.AsValueString(); } if (BuiltInParameter.RBS_CURVE_VERT_OFFSET_PARAM == definition.BuiltInParameter) { chuizhidui = param.AsValueString(); } if (BuiltInParameter.RBS_OFFSET_PARAM == definition.BuiltInParameter) { offset = FeetTomm(param.AsDouble()); } if (BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM == definition.BuiltInParameter) { width = param.AsValueString(); } if (BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM == definition.BuiltInParameter) { height = param.AsValueString(); } if (BuiltInParameter.RBS_CABLETRAY_RUNGSPACE == definition.BuiltInParameter) { hendang = param.AsValueString(); } if (BuiltInParameter.ELEM_FAMILY_PARAM == definition.BuiltInParameter) { familyname = param.AsValueString(); } } CreateEletricalQMySQLRow(dt, cable.Category.Name, Olev, shuidui, chuizhidui, offset, width, height, hendang, familyname ); } } }
public static List <BH.oM.MEP.System.CableTray> CableTrayFromRevit(this Autodesk.Revit.DB.Electrical.CableTray revitCableTray, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); // Reuse a BHoM cable tray from refObjects if it has been converted before List <BH.oM.MEP.System.CableTray> bhomCableTrays = refObjects.GetValues <BH.oM.MEP.System.CableTray>(revitCableTray.Id); if (bhomCableTrays != null) { return(bhomCableTrays); } else { bhomCableTrays = new List <BH.oM.MEP.System.CableTray>(); } // Section properties BH.oM.MEP.System.SectionProperties.CableTraySectionProperty sectionProperty = BH.Revit.Engine.Core.Query.CableTraySectionProperty(revitCableTray, settings); // Orientation angle double orientationAngle = revitCableTray.OrientationAngle(settings); bool isStartConnected = false; bool isEndConnected = false; List <BH.oM.Geometry.Line> queried = Query.LocationCurveMEP(revitCableTray, out isStartConnected, out isEndConnected, settings); Vector revitCableTrayVector = BH.Engine.Geometry.Modify.RoundCoordinates(VectorFromRevit((revitCableTray.Location as LocationCurve).Curve.GetEndPoint(0) - (revitCableTray.Location as LocationCurve).Curve.GetEndPoint(1)), 4).Normalise(); for (int i = 0; i < queried.Count; i++) { BH.oM.Geometry.Line segment = queried[i]; BH.oM.MEP.System.CableTray thisSegment = new CableTray { StartPoint = segment.StartPoint(), EndPoint = segment.EndPoint(), SectionProperty = sectionProperty, ConnectionProperty = new CableTrayConnectionProperty(), OrientationAngle = orientationAngle }; Vector bhomCableTrayVector = BH.Engine.Geometry.Modify.RoundCoordinates((thisSegment.StartPoint - thisSegment.EndPoint), 4).Normalise(); if (queried.Count > 1) { if (i == 0) //meaning it's the start segment of the revit cable tray that was split { if (BH.Engine.Geometry.Query.IsEqual(revitCableTrayVector, bhomCableTrayVector)) { thisSegment.ConnectionProperty.IsStartConnected = isStartConnected; thisSegment.ConnectionProperty.IsEndConnected = true; } else { thisSegment.ConnectionProperty.IsStartConnected = true; thisSegment.ConnectionProperty.IsEndConnected = isStartConnected; } } else if (i == queried.Count - 1) //meaning it's the end segment of the revit cable tray that was split { if (BH.Engine.Geometry.Query.IsEqual(revitCableTrayVector, bhomCableTrayVector)) { thisSegment.ConnectionProperty.IsStartConnected = true; thisSegment.ConnectionProperty.IsEndConnected = isEndConnected; } else { thisSegment.ConnectionProperty.IsStartConnected = isEndConnected; thisSegment.ConnectionProperty.IsEndConnected = true; } } else //meaning it's all mid segments of the revit cable tray that was split { thisSegment.ConnectionProperty.IsStartConnected = true; thisSegment.ConnectionProperty.IsEndConnected = true; } } else { if (BH.Engine.Geometry.Query.IsEqual(revitCableTrayVector, bhomCableTrayVector)) { thisSegment.ConnectionProperty.IsStartConnected = isStartConnected; thisSegment.ConnectionProperty.IsEndConnected = isEndConnected; } else { thisSegment.ConnectionProperty.IsStartConnected = isEndConnected; thisSegment.ConnectionProperty.IsEndConnected = isStartConnected; } } //Set identifiers, parameters & custom data thisSegment.SetIdentifiers(revitCableTray); thisSegment.CopyParameters(revitCableTray, settings.ParameterSettings); thisSegment.SetProperties(revitCableTray, settings.ParameterSettings); bhomCableTrays.Add(thisSegment); } refObjects.AddOrReplace(revitCableTray.Id, bhomCableTrays); return(bhomCableTrays); }