Beispiel #1
0
        public static BH.oM.MEP.System.WireSegment WireFromRevit(this Autodesk.Revit.DB.Electrical.Wire revitWire, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            // Reuse a BHoM duct from refObjects it it has been converted before
            BH.oM.MEP.System.WireSegment bhomWire = refObjects.GetValue <BH.oM.MEP.System.WireSegment>(revitWire.Id);
            if (bhomWire != null)
            {
                return(bhomWire);
            }

            LocationCurve locationCurve = revitWire.Location as LocationCurve;
            Curve         curve         = locationCurve.Curve;

            BH.oM.Geometry.Point startPoint = curve.GetEndPoint(0).PointFromRevit();
            BH.oM.Geometry.Point endPoint   = curve.GetEndPoint(1).PointFromRevit();
            BH.oM.Geometry.Line  line       = BH.Engine.Geometry.Create.Line(startPoint, endPoint); // BHoM line

            // Wire
            bhomWire = BH.Engine.MEP.Create.WireSegment(line);

            //Set identifiers, parameters & custom data
            bhomWire.SetIdentifiers(revitWire);
            bhomWire.CopyParameters(revitWire, settings.ParameterSettings);
            bhomWire.SetProperties(revitWire, settings.ParameterSettings);

            refObjects.AddOrReplace(revitWire.Id, bhomWire);

            return(bhomWire);
        }
        public BuiltElements.Wire WireToSpeckle(DB.Electrical.Wire revitWire)
        {
            var speckleWire = new RevitWire
            {
                family     = revitWire.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString(),
                type       = revitWire.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString(),
                wiringType = revitWire.get_Parameter(BuiltInParameter.RBS_ELEC_WIRE_TYPE).AsValueString(),
                level      = ConvertAndCacheLevel(revitWire.ReferenceLevel.Id)
            };

            // construction geometry for creating the wire on receive (doesn't match geometry points 🙃)
            var points = new List <double>();

            for (var i = 0; i < revitWire.NumberOfVertices; i++)
            {
                points.AddRange(PointToSpeckle(revitWire.GetVertex(i)).ToList());
            }
            speckleWire.constructionPoints = points;

            // geometry
            var start = ((LocationCurve)revitWire.Location).Curve.GetEndPoint(0);

            speckleWire.segments = new List <ICurve>();
            var view        = (View)Doc.GetElement(revitWire.OwnerViewId);
            var segmentList = revitWire.get_Geometry(new Options {
                View = view
            }).ToList();

            foreach (var segment in segmentList)
            {
                // transform and convert the geometry segments
                switch (segment)
                {
                case DB.PolyLine polyLine:
                    var revitLine = polyLine.GetTransformed(Transform.CreateTranslation(new XYZ(0, 0, start.Z)));
                    var line      = PolylineToSpeckle(revitLine);
                    speckleWire.segments.Add(line);
                    break;

                case DB.NurbSpline nurbSpline:
                    var revitCurve = nurbSpline.CreateTransformed(
                        Transform.CreateTranslation(new XYZ(0, 0, start.Z)));
                    // add display value
                    var curve      = (Curve)CurveToSpeckle(revitCurve);
                    var polyCoords = revitCurve.Tessellate().SelectMany(pt => PointToSpeckle(pt).ToList()).ToList();
                    curve.displayValue = new Polyline(polyCoords, ModelUnits);
                    speckleWire.segments.Add(curve);
                    break;
                }
            }

            GetAllRevitParamsAndIds(speckleWire, revitWire, new List <string>());
            //Report.Log($"Converted Wire {revitWire.Id}");
            return(speckleWire);
        }
Beispiel #3
0
        public static IProfile Profile(this Autodesk.Revit.DB.Electrical.Wire wire, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            List <ICurve> edges = new List <ICurve>();

            double diameter = wire.Diameter.ToSI(UnitType.UT_WireSize);

            double thickness = 0;

            return(BH.Engine.Spatial.Create.TubeProfile(diameter, thickness));
        }
Beispiel #4
0
        public static IBHoMObject FromRevit(this Autodesk.Revit.DB.Electrical.Wire wire, Discipline discipline, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            switch (discipline)
            {
            case Discipline.Architecture:
            case Discipline.Physical:
            case Discipline.Environmental:
                return(wire.WireFromRevit(settings, refObjects));

            default:
                return(null);
            }
        }
 public bool CanConvertToSpeckle(object @object)
 {
     return(@object
            switch
     {
         DB.DetailCurve _ => true,
         DB.DirectShape _ => true,
         DB.FamilyInstance _ => true,
         DB.Floor _ => true,
         DB.Level _ => true,
         DB.View _ => true,
         DB.ModelCurve _ => true,
         DB.Opening _ => true,
         DB.RoofBase _ => true,
         DB.Area _ => true,
         DB.Architecture.Room _ => true,
         DB.Architecture.TopographySurface _ => true,
         DB.Wall _ => true,
         DB.Mechanical.Duct _ => true,
         DB.Mechanical.Space _ => true,
         DB.Plumbing.Pipe _ => true,
         DB.Electrical.Wire _ => true,
         DB.CurtainGridLine _ => true, //these should be handled by curtain walls
         DB.Architecture.BuildingPad _ => true,
         DB.Architecture.Stairs _ => true,
         DB.Architecture.StairsRun _ => true,
         DB.Architecture.StairsLanding _ => true,
         DB.Architecture.Railing _ => true,
         DB.Architecture.TopRail _ => true,
         DB.Ceiling _ => true,
         DB.PointCloudInstance _ => true,
         DB.Group _ => true,
         DB.ProjectInfo _ => true,
         DB.ElementType _ => true,
         DB.Grid _ => true,
         DB.ReferencePoint _ => true,
         DB.Structure.AnalyticalModelStick _ => true,
         DB.Structure.AnalyticalModelSurface _ => true,
         DB.Structure.BoundaryConditions _ => true,
         _ => (@object as Element).IsElementSupported()
     });
Beispiel #6
0
        public static IBHoMObject FromRevit(this Autodesk.Revit.DB.Electrical.Wire wire, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            IElement1D result = null;

            switch (discipline)
            {
            case Discipline.Architecture:
            case Discipline.Physical:
            case Discipline.Environmental:
                result = wire.WireFromRevit(settings, refObjects);
                break;
            }

            if (result != null && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.ITransform(bHoMTransform);
            }

            return(result as IBHoMObject);
        }
        public List <ApplicationPlaceholderObject> WireToNative(BuiltElements.Wire speckleWire)
        {
            var speckleRevitWire = speckleWire as RevitWire;

            var wiringType = speckleRevitWire?.wiringType == "Chamfer"
        ? DB.Electrical.WiringType.Chamfer
        : DB.Electrical.WiringType.Arc;
            var wireType = GetElementType <DB.Electrical.WireType>(speckleWire);

            // get construction points (if wire is from Revit, these are not the same as the geometry points)
            var points = new List <XYZ>();

            if (speckleRevitWire != null)
            {
                points = PointListToNative(speckleRevitWire.constructionPoints, speckleRevitWire.units);
            }
            else
            {
                foreach (var segment in speckleWire.segments)
                {
                    switch (segment)
                    {
                    case Curve curve:
                        points.AddRange(PointListToNative(curve.points));
                        break;

                    case Polyline line:
                        points.AddRange(PointListToNative(line.value));
                        break;

                    default: // what other curves should be supported? currently just the ones you can create from revit
                        new SpeckleException($"Wire segment geometry of type {segment.GetType()} not currently supported");
                        break;
                    }
                }
            }

            DB.Electrical.Wire wire = null;
            var docObj = GetExistingElementByApplicationId(speckleWire.applicationId);

            if (docObj != null)
            {
                wire = (DB.Electrical.Wire)docObj;
                // if the number of vertices doesn't match, we need to create a new wire
                if (wire.NumberOfVertices != points.Count)
                {
                    wire = null;
                }
            }

            // update points if we can
            if (wire != null)
            {
                for (var i = 0; i < wire.NumberOfVertices; i++)
                {
                    if (points[i].IsAlmostEqualTo(wire.GetVertex(i)))
                    {
                        continue; // borks if we set the same point
                    }
                    wire.SetVertex(i, points[i]);
                }
            }
            var isUpdate = wire != null;

            // crete a new one if there isn't one to update
            wire ??= DB.Electrical.Wire.Create(Doc, wireType.Id, Doc.ActiveView.Id,
                                               wiringType,
                                               points, null, null);

            if (speckleRevitWire != null)
            {
                SetInstanceParameters(wire, speckleRevitWire);
            }

            var placeholders = new List <ApplicationPlaceholderObject>
            {
                new ApplicationPlaceholderObject
                {
                    applicationId = speckleWire.applicationId, ApplicationGeneratedId = wire.UniqueId, NativeObject = wire
                }
            };

            Report.Log($"{(isUpdate ? "Updated" : "Created")} Wire {wire.Id}");
            return(placeholders);
        }