Exemplo n.º 1
0
        public BuiltElements.Duct DuctToSpeckle(DB.Duct revitDuct)
        {
            var baseGeometry = LocationToSpeckle(revitDuct);
            var baseLine     = baseGeometry as Line;

            if (baseLine == null)
            {
                throw new Exception("Only line base Ducts are currently supported.");
            }

            // SPECKLE DUCT
            var speckleDuct = new RevitDuct();

            speckleDuct.family   = revitDuct.DuctType.FamilyName;
            speckleDuct.type     = revitDuct.DuctType.Name;
            speckleDuct.baseLine = baseLine;

            speckleDuct.diameter = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_CURVE_DIAMETER_PARAM);
            speckleDuct.height   = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
            speckleDuct.width    = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_CURVE_WIDTH_PARAM);
            speckleDuct.length   = GetParamValue <double>(revitDuct, BuiltInParameter.CURVE_ELEM_LENGTH);
            speckleDuct.velocity = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_VELOCITY);
            speckleDuct.level    = ConvertAndCacheLevel(revitDuct, BuiltInParameter.RBS_START_LEVEL_PARAM);

            var typeElem = Doc.GetElement(revitDuct.MEPSystem.GetTypeId());

            speckleDuct.systemName = typeElem.Name;

            GetAllRevitParamsAndIds(speckleDuct, revitDuct,
                                    new List <string> {
                "RBS_CURVE_HEIGHT_PARAM", "RBS_CURVE_WIDTH_PARAM", "RBS_CURVE_DIAMETER_PARAM", "CURVE_ELEM_LENGTH", "RBS_START_LEVEL_PARAM", "RBS_VELOCITY"
            });

            return(speckleDuct);
        }
Exemplo n.º 2
0
        public List <ApplicationPlaceholderObject> DuctToNative(BuiltElements.Duct speckleDuct)
        {
            var baseLine   = LineToNative(speckleDuct.baseLine);
            XYZ startPoint = baseLine.GetEndPoint(0);
            XYZ endPoint   = baseLine.GetEndPoint(1);

            Autodesk.Revit.DB.Level level;

            var speckleRevitDuct = speckleDuct as RevitDuct;

            level = LevelToNative(speckleRevitDuct != null ? speckleRevitDuct.level : LevelFromCurve(baseLine));

            var ductType     = GetElementType <DB.DuctType>(speckleDuct);
            var systemFamily = (speckleDuct is RevitDuct rd) ? rd.systemName : "";

            List <ElementType> types = new FilteredElementCollector(Doc).WhereElementIsElementType()
                                       .OfClass(typeof(MechanicalSystemType)).ToElements().Cast <ElementType>().ToList();
            var system = types.FirstOrDefault(x => x.Name == systemFamily);

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

            var docObj = GetExistingElementByApplicationId(((Base)speckleDuct).applicationId);


            // deleting instead of updating for now!
            if (docObj != null)
            {
                Doc.Delete(docObj.Id);
            }

            DB.Duct duct = DB.Duct.Create(Doc, system.Id, ductType.Id, level.Id, startPoint, endPoint);

            if (speckleRevitDuct != null)
            {
                TrySetParam(duct, BuiltInParameter.RBS_CURVE_HEIGHT_PARAM, speckleRevitDuct.height, speckleRevitDuct.units);
                TrySetParam(duct, BuiltInParameter.RBS_CURVE_WIDTH_PARAM, speckleRevitDuct.width, speckleRevitDuct.units);
                TrySetParam(duct, BuiltInParameter.RBS_CURVE_DIAMETER_PARAM, speckleRevitDuct.diameter, speckleRevitDuct.units);
                TrySetParam(duct, BuiltInParameter.CURVE_ELEM_LENGTH, speckleRevitDuct.length, speckleRevitDuct.units);
                TrySetParam(duct, BuiltInParameter.RBS_VELOCITY, speckleRevitDuct.velocity, speckleRevitDuct.units);
                //Report.Log($"Created Duct {duct.Id}");
                SetInstanceParameters(duct, speckleRevitDuct);
            }

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

            return(placeholders);
        }
Exemplo n.º 3
0
        private void AssertDuctEqual(DB.Duct sourceElem, DB.Duct destElem)
        {
            Assert.NotNull(destElem);
            Assert.Equal(sourceElem.Name, destElem.Name);

            AssertEqualParam(sourceElem, destElem, BuiltInParameter.CURVE_ELEM_LENGTH);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.RBS_START_LEVEL_PARAM);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.RBS_CURVE_WIDTH_PARAM);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.RBS_CURVE_DIAMETER_PARAM);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.RBS_VELOCITY);
        }
Exemplo n.º 4
0
        public BuiltElements.Duct DuctToSpeckle(DB.Duct revitDuct)
        {
            var baseGeometry = LocationToSpeckle(revitDuct);

            if (!(baseGeometry is Line baseLine))
            {
                throw new Speckle.Core.Logging.SpeckleException("Only line based Ducts are currently supported.");
            }

            // SPECKLE DUCT
            var speckleDuct = new RevitDuct
            {
                family      = revitDuct.DuctType.FamilyName,
                type        = revitDuct.DuctType.Name,
                baseLine    = baseLine,
                diameter    = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_CURVE_DIAMETER_PARAM),
                height      = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_CURVE_HEIGHT_PARAM),
                width       = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_CURVE_WIDTH_PARAM),
                length      = GetParamValue <double>(revitDuct, BuiltInParameter.CURVE_ELEM_LENGTH),
                velocity    = GetParamValue <double>(revitDuct, BuiltInParameter.RBS_VELOCITY),
                level       = ConvertAndCacheLevel(revitDuct, BuiltInParameter.RBS_START_LEVEL_PARAM),
                displayMesh = GetElementMesh(revitDuct)
            };


            var typeElem = Doc.GetElement(revitDuct.MEPSystem.GetTypeId());

            speckleDuct.systemName = typeElem.Name;

            GetAllRevitParamsAndIds(speckleDuct, revitDuct,
                                    new List <string>
            {
                "RBS_CURVE_HEIGHT_PARAM", "RBS_CURVE_WIDTH_PARAM", "RBS_CURVE_DIAMETER_PARAM", "CURVE_ELEM_LENGTH",
                "RBS_START_LEVEL_PARAM", "RBS_VELOCITY"
            });
            //Report.Log($"Converted Duct {revitDuct.Id}");
            return(speckleDuct);
        }
Exemplo n.º 5
0
            public void Duct_from_AutoCad()
            {
                UIDocument uidoc = this.ActiveUIDocument;
                Document   doc   = uidoc.Document;

                Autodesk.Revit.DB.View currentview = doc.ActiveView;
                if (currentview.ViewType != ViewType.FloorPlan)
                {
                    return;
                }                                                   //Only works in floorplans
                try
                {
                    puntoref_revit = uidoc.Selection.PickPoint("Pick origin point in REVIT");
                }
                catch { return; }
                OpenFileDialog archivofile = new OpenFileDialog();

                archivofile.Title           = "Open CAD data file";
                archivofile.CheckFileExists = true;
                archivofile.CheckPathExists = true;
                archivofile.Filter          = "Txt|*.txt";
                if (archivofile.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                string nombrefile = archivofile.FileName;

                string[] lineasarchivo = File.ReadAllLines(nombrefile);
                string   lineadata     = String.Empty;

                //get Rectangular Duct Type
                FilteredElementCollector collectorductos = new FilteredElementCollector(doc);

                collectorductos.OfClass(typeof(Autodesk.Revit.DB.Mechanical.DuctType)).ToElements();

                Autodesk.Revit.DB.Mechanical.DuctType ducttypefinal = null;
                foreach (Element elemw in collectorductos)
                {
                    Autodesk.Revit.DB.Mechanical.DuctType duct_type = elemw as Autodesk.Revit.DB.Mechanical.DuctType;
                    System.Diagnostics.Debug.Print(duct_type.Name);
                    Parameter ovaltoround     = duct_type.get_Parameter(BuiltInParameter.RBS_CURVETYPE_MULTISHAPE_TRANSITION_OVALROUND_PARAM);
                    Parameter recttooval      = duct_type.get_Parameter(BuiltInParameter.RBS_CURVETYPE_MULTISHAPE_TRANSITION_RECTOVAL_PARAM);
                    Parameter recttoround     = duct_type.get_Parameter(BuiltInParameter.RBS_CURVETYPE_MULTISHAPE_TRANSITION_PARAM);
                    int       val_ovaltoround = ovaltoround.AsElementId().IntegerValue;
                    int       val_recttooval  = recttooval.AsElementId().IntegerValue;
                    int       val_recttoround = recttoround.AsElementId().IntegerValue;
                    System.Diagnostics.Debug.Print("Oval to round:" + val_ovaltoround.ToString());
                    System.Diagnostics.Debug.Print("Rect to oval:" + val_recttooval.ToString());
                    System.Diagnostics.Debug.Print("Rect to round:" + val_recttoround.ToString());
                    //if val_recttoround is -1 the ducttype is OVAL
                    //if val_ovaltoround is -1 the ducttype is RECTANGULAR
                    // if val_recttooval is -1 the ducttyoe is ROUND
                    if (val_ovaltoround == -1)
                    {
                        ducttypefinal = duct_type; break;
                    }
                }
                //
                lineadata = lineasarchivo[0];
                string[] datos = lineadata.Split(';');
                double   x1    = Math.Round(Convert.ToDouble(datos[0]), 6) / 0.3048;
                double   y1    = Math.Round(Convert.ToDouble(datos[1]), 6) / 0.3048;
                double   z1    = Math.Round(Convert.ToDouble(datos[2]), 6) / 0.3048;

                puntoref_cad      = new XYZ(x1, y1, z1);
                vector_correccion = puntoref_revit - puntoref_cad;
                XYZ puntoCR    = new XYZ();
                int Countducts = 0;

                using (Transaction tr = new Transaction(doc, "DuctFromCAD"))
                {
                    tr.Start();
                    for (int ii = 1; ii < lineasarchivo.Length; ii++)
                    {
                        lineadata = lineasarchivo[ii];
                        datos     = lineadata.Split(';');
                        x1        = Math.Round(Convert.ToDouble(datos[0]), 6) / 0.3048;
                        y1        = Math.Round(Convert.ToDouble(datos[1]), 6) / 0.3048;
                        z1        = Math.Round(Convert.ToDouble(datos[2]), 6) / 0.3048;
                        double x2        = Math.Round(Convert.ToDouble(datos[3]), 6) / 0.3048;
                        double y2        = Math.Round(Convert.ToDouble(datos[4]), 6) / 0.3048;
                        double z2        = Math.Round(Convert.ToDouble(datos[5]), 6) / 0.3048;
                        double ancho     = Math.Round(Convert.ToDouble(datos[6]), 3);
                        string dim_ducto = datos[7];
                        if (dim_ducto != null && dim_ducto != "")
                        {
                            string[] blanksplit = dim_ducto.Split(' ');
                            string[] sizeplit   = blanksplit[0].Split('x');
                            double   widthduct  = Convert.ToDouble(sizeplit[0]) / 12; //from inches to feet
                            double   heightduct = Convert.ToDouble(sizeplit[1]) / 12; //from inches to feet
                            System.Diagnostics.Debug.Print(widthduct.ToString() + "x" + heightduct.ToString());
                            XYZ p1 = new XYZ(x1, y1, z1) + vector_correccion;
                            XYZ p2 = new XYZ(x2, y2, z2) + vector_correccion;
                            if (p1.DistanceTo(p2) < 1)
                            {
                                continue;
                            }                            //Not less than a feet
                            try
                            {
                                Autodesk.Revit.DB.Mechanical.Duct new_duct = doc.Create.NewDuct(p1, p2, ducttypefinal);
                                new_duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(widthduct);
                                new_duct.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).Set(heightduct);
                                doc.Create.NewTag(currentview, new_duct, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.TAG_HORIZONTAL, p1.Add(p2).Divide(2));
                                //doc.Create.NewTextNote(currentview, p1.Add(p2).Divide(2.001), XYZ.BasisX, XYZ.BasisZ, 1, TextAlignFlags.TEF_ALIGN_CENTER, sizeplit[0] + "x" + sizeplit[1]);
                                Countducts++;
                            }
                            catch { }
                        }
                    }
                    tr.Commit();
                }
                MessageBox.Show("Imported " + Countducts.ToString() + " Ducts");
            }