public Line LineToSpeckle(DB.Line line)
        {
            var l = new Line()
            {
                value = new List <double>(), units = ModelUnits
            };

            l.value.AddRange(PointToSpeckle(line.GetEndPoint(0)).value);
            l.value.AddRange(PointToSpeckle(line.GetEndPoint(1)).value);
            return(l);
        }
Esempio n. 2
0
        public Line LineToSpeckle(DB.Line line, string units = null)
        {
            var u = units ?? ModelUnits;
            var l = new Line {
                units = u
            };

            l.start = PointToSpeckle(line.GetEndPoint(0), u);
            l.end   = PointToSpeckle(line.GetEndPoint(1), u);

            l.length = line.Length;
            return(l);
        }
Esempio n. 3
0
        public Line LineToSpeckle(DB.Line line, string units = null)
        {
            var u = units ?? ModelUnits;
            var l = new Line {
                units = u
            };

            l.start  = PointToSpeckle(line.GetEndPoint(0), u);
            l.end    = PointToSpeckle(line.GetEndPoint(1), u);
            l.domain = new Interval(line.GetEndParameter(0), line.GetEndParameter(1));

            l.length = ScaleToSpeckle(line.Length);
            return(l);
        }
Esempio n. 4
0
        public List <ApplicationPlaceholderObject> PipeToNative(BuiltElements.Pipe specklePipe)
        {
            // check if this is a line based pipe, return null if not
            DB.Line baseLine = null;
            switch (specklePipe.baseCurve)
            {
            case Line line:
                baseLine = LineToNative(line);
                break;

            default:
                Report.LogConversionError(new Exception($"Pipe baseCurve is not a line"));
                return(null);
            }

            // geometry
            var speckleRevitPipe = specklePipe as RevitPipe;
            var level            = LevelToNative(speckleRevitPipe != null ? speckleRevitPipe.level : LevelFromCurve(baseLine));

            // get MEP pipe system by name or by type
            var pipeType = GetElementType <DB.Plumbing.PipeType>(specklePipe);
            var types    = new FilteredElementCollector(Doc).WhereElementIsElementType()
                           .OfClass(typeof(DB.Plumbing.PipingSystemType)).ToElements().Cast <ElementType>().ToList();
            var systemFamily = speckleRevitPipe?.systemType ?? "";
            var system       = types.FirstOrDefault(x => x.Name == speckleRevitPipe?.systemName) ??
                               types.FirstOrDefault(x => x.Name == systemFamily);

            if (system == null)
            {
                system = types.FirstOrDefault();
                Report.LogConversionError(new Exception($"Pipe type {systemFamily} not found; replaced with {system.Name}"));
            }

            // create or update the pipe
            DB.Plumbing.Pipe pipe;
            var isUpdate = false;
            var docObj   = GetExistingElementByApplicationId(specklePipe.applicationId);

            if (docObj == null)
            {
                pipe = DB.Plumbing.Pipe.Create(Doc, system.Id, pipeType.Id, level.Id,
                                               baseLine.GetEndPoint(0),
                                               baseLine.GetEndPoint(1));
            }
            else
            {
                pipe = (DB.Plumbing.Pipe)docObj;
                pipe.SetSystemType(system.Id);
                ((LocationCurve)pipe.Location).Curve = baseLine;
                isUpdate = true;
            }

            if (speckleRevitPipe != null)
            {
                TrySetParam(pipe, BuiltInParameter.RBS_START_LEVEL_PARAM, level);
                SetInstanceParameters(pipe, speckleRevitPipe);
            }
            TrySetParam(pipe, BuiltInParameter.RBS_PIPE_DIAMETER_PARAM, specklePipe.diameter, specklePipe.units);

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

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