Example #1
0
        internal static void UpdateTag(ElementId modifiedElmId, Autodesk.Revit.DB.Document doc)
        {
            StringBuilder strBld      = new StringBuilder();
            int           rows        = 0;
            int           shelfLength = 0;
            Element       modifiedElm = doc.GetElement(modifiedElmId);

            switch (modifiedElm.Category.Name)
            {
            case "Walls":
                Wall              wl        = modifiedElm as Wall;
                WallType          wlType    = wl.WallType;
                CompoundStructure cmpStr_wl = wlType.GetCompoundStructure();
                strBld = LayersAsString(cmpStr_wl, doc, out shelfLength);
                rows   = wlType.GetCompoundStructure().LayerCount;
                break;

            case "Floors":
                Floor             fl        = modifiedElm as Floor;
                FloorType         flType    = fl.FloorType;
                CompoundStructure cmpStr_fl = flType.GetCompoundStructure();
                strBld = LayersAsString(cmpStr_fl, doc, out shelfLength);
                rows   = flType.GetCompoundStructure().LayerCount;
                break;

            case "Ceilings":
                Ceiling           cl        = modifiedElm as Ceiling;
                CeilingType       clType    = doc.GetElement(cl.GetTypeId()) as CeilingType;
                CompoundStructure cmpStr_cl = clType.GetCompoundStructure();
                strBld = LayersAsString(cmpStr_cl, doc, out shelfLength);
                rows   = clType.GetCompoundStructure().LayerCount;
                break;

            case "Roofs":
                RoofBase          rf        = modifiedElm as RoofBase;
                RoofType          rfType    = rf.RoofType;
                CompoundStructure cmpStr_rf = rfType.GetCompoundStructure();
                strBld = LayersAsString(cmpStr_rf, doc, out shelfLength);
                rows   = rfType.GetCompoundStructure().LayerCount;
                break;
            }

            FamilyInstance tag = doc.GetElement(new ElementId(modifiedElm.LookupParameter("LinkedTag").AsInteger())) as FamilyInstance;

            try
            {
                tag.LookupParameter("multilineText").Set(strBld.ToString());
                tag.LookupParameter("# of Rows").Set(rows);
                tag.LookupParameter("Shelf Length").Set(ToFt(shelfLength));
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
            }
        }
Example #2
0
        public void AdjustWallTypeProperties(WallType wallType)
        {
            string actualTypeName = wallType.Name;

            string targetMatSign = actualTypeName.Between("-", "-");
            string targetWallMat = RvtMaterial.GetMatName(targetMatSign);

            double targetThickness = Convert.ToDouble(actualTypeName.After("EP"));

            double wallThickness;
            string wallMat;
            bool   isStructural;

            GetWallTypeProperties(wallType, out isStructural, out wallMat, out wallThickness);

            if (isStructural)
            {
                if (!wallMat.Equals(targetWallMat))
                {
                    Material targetMaterial = GetMaterialByName(_doc, targetWallMat);

                    Transaction t = new Transaction(_doc);
                    t.Start("Change the material of the structural layer of the wall type");
                    foreach (CompoundStructureLayer layer in wallType.GetCompoundStructure().GetLayers())
                    {
                        if (layer.Function == MaterialFunctionAssignment.Structure)
                        {
                            layer.MaterialId = targetMaterial.Id;
                        }
                    }
                    t.Commit();
                }

                if (wallThickness != targetThickness)
                {
                    TaskDialog.Show("Revit", $"{isStructural}, {targetThickness}, {wallThickness}");
                    Transaction t = new Transaction(_doc);
                    t.Start("Change the structural layer thickness of the wall type property");
                    foreach (CompoundStructureLayer layer in wallType.GetCompoundStructure().GetLayers())
                    {
                        if (layer.Function == MaterialFunctionAssignment.Structure)
                        {
                            layer.Width = UnitUtils.Convert(targetThickness, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);
                        }
                    }
                    t.Commit();
                }
            }
        }
Example #3
0
        public WallType CreateNewWallType(Document doc, Wall wall)
        {
            WallType wallType    = wall.WallType;
            WallType NewWallType = null;

            Transaction t = new Transaction(doc, "Duplicate wall");

            t.Start();
            try
            {
                NewWallType = wallType.Duplicate("SW48") as WallType;
                CompoundStructure compoundStructure = NewWallType.GetCompoundStructure();
                int layerIndex = compoundStructure.GetFirstCoreLayerIndex();
                IList <CompoundStructureLayer> csLayers = compoundStructure.GetLayers();
                foreach (CompoundStructureLayer csl in csLayers)
                {
                    if (csl.Function.ToString() == "Structure")
                    {
                        compoundStructure.SetLayerWidth(layerIndex, 48 / 12);
                    }
                    layerIndex++;
                }
                NewWallType.SetCompoundStructure(compoundStructure);
            }
            catch {}
            t.Commit();
            return(NewWallType);
        }
Example #4
0
        internal static Material GetMaterial(Document doc, Wall wall)
        {
            WallType aWallType = wall.WallType;

            if (WallKind.Basic == aWallType.Kind)
            {
                CompoundStructure comStruct     = aWallType.GetCompoundStructure();
                Categories        allCategories = doc.Settings.Categories;
                // Get the category OST_Walls default Material;
                // use if that layer's default Material is <By Category>
                Category wallCategory = allCategories.get_Item(BuiltInCategory.OST_Walls);
                Material wallMaterial = wallCategory.Material;
                foreach (CompoundStructureLayer structLayer in comStruct.GetLayers())
                {
                    var layerMaterial = ElementFilterUtils.GetElement(doc, structLayer.MaterialId) as Material;
                    if (layerMaterial == null)
                    {
                        switch (structLayer.Function)
                        {
                        case MaterialFunctionAssignment.Structure:
                            layerMaterial = allCategories.get_Item(BuiltInCategory.OST_WallsStructure).Material;
                            break;
                        }
                    }
                    if (layerMaterial != null)
                    {
                        wallMaterial = layerMaterial;
                        break;
                    }
                }
                return(wallMaterial);
            }

            return(null);
        }
        public WallType CreateWallType(Document document, WallType _wallType, double wallTypeThickness)
        {
            WallType wallType = null;

            try
            {
                wallType = _wallType.Duplicate($"Wall {Convert.ToInt32((wallTypeThickness )).ToString() }mm") as WallType;

                CompoundStructure compoundStructure = wallType.GetCompoundStructure();

                int layerIndex = compoundStructure.GetFirstCoreLayerIndex();


                IList <CompoundStructureLayer> clayers = compoundStructure.GetLayers();

                foreach (CompoundStructureLayer csl in clayers)
                {
                    if (csl.Function.ToString() == "Structure")
                    {
                        compoundStructure.SetLayerWidth(layerIndex, wallTypeThickness * _mm_to_feet);
                    }

                    layerIndex++;
                }

                wallType.SetCompoundStructure(compoundStructure);
            }
            catch { }


            return(wallType);
        }
Example #6
0
        public void GetWallTypeProperties(WallType wallType, out bool isStructural, out string wallMat, out double wallThickness)
        {
            CompoundStructureLayer strLayer =
                (from CompoundStructureLayer layer in wallType.GetCompoundStructure().GetLayers()
                 where layer.Function == MaterialFunctionAssignment.Structure
                 select layer)
                .FirstOrDefault();

            if (strLayer != null)
            {
                isStructural = true;

                if (strLayer.MaterialId != ElementId.InvalidElementId)
                {
                    wallMat = _doc.GetElement(strLayer.MaterialId).Name;
                }
                else
                {
                    wallMat = String.Empty;
                }

                wallThickness = UnitUtils.Convert(
                    strLayer.Width,
                    DisplayUnitType.DUT_DECIMAL_FEET,
                    DisplayUnitType.DUT_CENTIMETERS);
            }
            else
            {
                isStructural  = false;
                wallMat       = String.Empty;
                wallThickness = 0;
            }
        }
Example #7
0
        public void CreateWalls
            (Document doc, HouseObject house,
            List <WallType> autoTypes, Level baseLevel)
        {
            foreach (A_Floor floor in house.Floors)
            {
                ///Create the walls.
                foreach (A_Wall wa in floor.Walls)
                {
                    WallType currentWt = null;
                    XYZ      p1        = new XYZ(wa.P1.X, wa.P1.Y, 0);
                    XYZ      p2        = new XYZ(wa.P2.X, wa.P2.Y, 0);
                    Curve    c         = Line.CreateBound(p1, p2);

                    ///Find the right wall type.
                    ///If the type doesnt exist,create a new one.
                    try
                    {
                        currentWt = autoTypes
                                    .First(at => at.Width - wa.Thickness < 0.0001);
                    }
                    catch
                    {
                        ///Duplicate a new walltype;
                        float wallWidthMm = Helper.Feet2Mm(wa.Thickness);
                        currentWt = AutoWallTypes[0].Duplicate
                                        ("AutoWall-" + wallWidthMm) as WallType;
                        ///Set the width of the new type;
                        CompoundStructure cStru = CompoundStructure
                                                  .CreateSingleLayerCompoundStructure
                                                      (MaterialFunctionAssignment.Structure,
                                                      wa.Thickness, currentWt.GetCompoundStructure().GetMaterialId(0));
                        currentWt.SetCompoundStructure(cStru);
                        ///Add it to collection.
                        AutoWallTypes.Add(currentWt);
                    }

                    ///Create the individual wall
                    wa.Wall = Wall.Create(doc, c, currentWt.Id, baseLevel.Id,
                                          floor.Height, 0, false, true);

                    ActiveForm.UpdateProgress(wallWorkLoad);
                }

                ///Create the floor.
                CurveArray floorCrv = new CurveArray();
                foreach (A_Room outer in floor.Outers)
                {
                    foreach (A_Contour con in outer.Meta.Contours)
                    {
                        floorCrv.Append(Line.CreateBound
                                            (new XYZ(con.P1.X, con.P1.Y, baseLevel.Elevation),
                                            new XYZ(con.P2.X, con.P2.Y, baseLevel.Elevation)));
                    }
                    doc.Create.NewFloor(floorCrv, false);
                }
            }
        }
        public static void CatpureWalls(this Document doc)
        {
            List <Element> WallCollector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).ToList();
            string         filename      = directory + "\\FOUNDLABELS_StudLayer.csv";
            List <string>  lines         = new List <string>();

            foreach (Element e in WallCollector)
            {
                Wall w = e as Wall;
                if (w != null)
                {
                    TaskDialog.Show("Test", "Wall Found");
                    WallType wt = w.WallType;
                    if (wt.Kind == WallKind.Basic)
                    {
                        TaskDialog.Show("Test", "Wall Kind is Basic");
                        var layers = wt.GetCompoundStructure().GetLayers();

                        string s = "";
                        foreach (var layer in layers)
                        {
                            var materialId = layer.MaterialId;
                            if (materialId != ElementId.InvalidElementId)
                            {
                                Material mat = doc.GetElement(layer.MaterialId) as Material;
                                s += mat.Name + ',';
                            }
                            else
                            {
                                s += "NullMaterial,";
                            }
                        }
                        lines.Add(s);
                    }
                }
            }

            File.WriteAllLines(filename, lines);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

#if _2011
            //
            // code for the Revit 2011 API:
            //
            Debug.Assert(false,
                         "Currently, no new wall layer can be created, because"
                         + "there is no creation method available for it.");

            foreach (WallType wallType in doc.WallTypes)
            {
                if (0 < wallType.CompoundStructure.Layers.Size)
                {
                    CompoundStructureLayer oldLayer
                        = wallType.CompoundStructure.Layers.get_Item(0);

                    WallType newWallType
                        = wallType.Duplicate("NewWallType") as WallType;

                    CompoundStructure structure
                        = newWallType.CompoundStructure;

                    CompoundStructureLayerArray layers
                        = structure.Layers;


                    // from here on, nothing works, as expected:
                    // in the Revir 2010 API, we could call the constructor
                    // even though it is for internal use only.
                    // in 2011, it is not possible to call it either.

                    CompoundStructureLayer newLayer = null;
                    //  = new CompoundStructureLayer(); // for internal use only

                    newLayer.DeckProfile = oldLayer.DeckProfile;
                    //newLayer.DeckUsage = oldLayer.DeckUsage; // read-only
                    //newLayer.Function = oldLayer.Function; // read-only
                    newLayer.Material  = oldLayer.Material;
                    newLayer.Thickness = oldLayer.Thickness;
                    newLayer.Variable  = oldLayer.Variable;
                    layers.Append(newLayer);
                }
            }
#endif // _2011

            //WallTypeSet wallTypes = doc.WallTypes; // 2013

            FilteredElementCollector wallTypes
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(WallType)); // 2014

            foreach (WallType wallType in wallTypes)
            {
                if (0 < wallType.GetCompoundStructure().GetLayers().Count)
                {
                    CompoundStructureLayer oldLayer
                        = wallType.GetCompoundStructure().GetLayers()[0];

                    WallType newWallType
                        = wallType.Duplicate("NewWallType") as WallType;

                    CompoundStructure structure
                        = newWallType.GetCompoundStructure();

                    IList <CompoundStructureLayer> layers
                        = structure.GetLayers();

                    // in Revit 2012, we can create a new layer:

                    double width = 0.1;
                    MaterialFunctionAssignment function = oldLayer.Function;
                    ElementId materialId = oldLayer.MaterialId;

                    CompoundStructureLayer newLayer
                        = new CompoundStructureLayer(width, function, materialId);

                    layers.Add(newLayer);
                    structure.SetLayers(layers);
                    newWallType.SetCompoundStructure(structure);
                }
            }
            return(Result.Succeeded);
        }
        /// <summary>
        /// Cumulate the compound wall layer volumes for the given wall.
        /// </summary>
        void GetWallLayerVolumes(
            Wall wall,
            ref MapLayerToVolume totalVolumes)
        {
            WallType wt = wall.WallType;

            //CompoundStructure structure= wt.CompoundStructure; // 2011
            CompoundStructure structure = wt.GetCompoundStructure(); // 2012

            //CompoundStructureLayerArray layers = structure.Layers; // 2011
            IList <CompoundStructureLayer> layers = structure.GetLayers(); // 2012

            //int i, n = layers.Size; // 2011
            int i, n = layers.Count; // 2012

            double area      = GetWallParameter(wall, _bipArea);
            double volume    = GetWallParameter(wall, _bipVolume);
            double thickness = wt.Width;

            string desc = Util.ElementDescription(wall);

            Debug.Print(
                "{0} with thickness {1}"
                + " and volume {2}"
                + " has {3} layer{4}{5}",
                desc,
                Util.MmString(thickness),
                Util.RealString(volume),
                n, Util.PluralSuffix(n),
                Util.DotOrColon(n));

            // volume for entire wall:

            string key = wall.WallType.Name;

            totalVolumes.Cumulate(key, volume);

            // volume for compound wall layers:

            if (0 < n)
            {
                i = 0;
                double total = 0.0;
                double layerVolume;
                foreach (CompoundStructureLayer
                         layer in layers)
                {
                    key = wall.WallType.Name + " : "
                          + layer.Function;

                    //layerVolume = area * layer.Thickness; // 2011
                    layerVolume = area * layer.Width; // 2012

                    totalVolumes.Cumulate(key, layerVolume);
                    total += layerVolume;

                    Debug.Print(
                        "  Layer {0}: function {1}, "
                        + "thickness {2}, volume {3}",
                        ++i, layer.Function,
                        Util.MmString(layer.Width),
                        Util.RealString(layerVolume));
                }

                Debug.Print("Wall volume = {0},"
                            + " total layer volume = {1}",
                            Util.RealString(volume),
                            Util.RealString(total));

                if (!Util.IsEqual(volume, total))
                {
                    Debug.Print("Wall host volume parameter"
                                + " value differs from sum of all layer"
                                + " volumes: {0}",
                                volume - total);
                }
            }
        }
Example #11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            #region Get access to the current document and aplication.
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
            #endregion

            // Try to create a project parameter.
            try
            {
                Category    walls    = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Walls);
                Category    floors   = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Floors);
                Category    ceilings = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Ceilings);
                Category    roofs    = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Roofs);
                CategorySet catSet   = new CategorySet();
                catSet.Insert(walls); catSet.Insert(floors); catSet.Insert(ceilings); catSet.Insert(roofs);

                using (Transaction t = new Transaction(doc, "Add project parameter"))
                {
                    t.Start();
                    CreateProjectParam(app, "LinkedTag", ParameterType.Integer, false, catSet, BuiltInParameterGroup.INVALID, true);
                    if (t.Commit() == TransactionStatus.Committed)
                    {
                    }
                    else
                    {
                        t.RollBack();
                    }
                }
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
            }

            if (Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")) == null)
            {
                BuildNewSchema(doc);
            }

            // Retrieving a specific family from the database.
            try
            {
                // Create a new FilteredElementCollector
                FilteredElementCollector collector = new FilteredElementCollector(doc);

                // Define and apply one or more filters to it.
                ElementCategoryFilter  categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericAnnotation);
                ParameterValueProvider pvp_1          = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME));
                ParameterValueProvider pvp_2          = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME));
                FilterStringEquals     equals         = new FilterStringEquals();
                string             familyName         = "Z-M2-MultilayerMaterialTag-LOD1";
                string             typeName           = "2.5mm";
                FilterRule         fRule_1            = new FilterStringRule(pvp_1, equals, familyName, false);
                FilterRule         fRule_2            = new FilterStringRule(pvp_2, equals, typeName, false);
                IList <FilterRule> fRules             = new List <FilterRule> {
                    fRule_1, fRule_2
                };
                ElementParameterFilter filters = new ElementParameterFilter(fRules);

                // Collect the familySymbol's id
                ICollection <ElementId> id = collector.WherePasses(categoryFilter).WherePasses(filters).ToElementIds();

                if (id.Count == 0)
                {
                    message = "No FamilyType has been detected.";
                    return(Result.Failed);
                }

                AnnotationSymbolType materialTag = doc.GetElement(id.First()) as AnnotationSymbolType;

                if (CreateWorkPlane(doc) != true)
                {
                    return(Result.Failed);
                }

                // Prompt the user to select select the element to be tagged.
                Reference pickedRef = null;
                pickedRef = uidoc.Selection.PickObject(ObjectType.Element, new MultilayerStrFilter(), "Please select a multilayer element.");
                Element selectedElm = doc.GetElement(pickedRef.ElementId);

                XYZ point = uidoc.Selection.PickPoint("Please pick a point to place the family");

                StringBuilder strBld = new StringBuilder();
                int           rows;
                int           shelfLength;

                switch (selectedElm.Category.Name)
                {
                case "Walls":
                    Wall              wl        = selectedElm as Wall;
                    WallType          wlType    = wl.WallType;
                    CompoundStructure cmpStr_wl = wlType.GetCompoundStructure();
                    strBld = LayersAsString(cmpStr_wl, doc, out shelfLength);
                    rows   = wlType.GetCompoundStructure().LayerCount;
                    break;

                case "Floors":
                    Floor             fl        = selectedElm as Floor;
                    FloorType         flType    = fl.FloorType;
                    CompoundStructure cmpStr_fl = flType.GetCompoundStructure();
                    strBld = LayersAsString(cmpStr_fl, doc, out shelfLength);
                    rows   = flType.GetCompoundStructure().LayerCount;
                    break;

                case "Ceilings":
                    Ceiling           cl        = selectedElm as Ceiling;
                    CeilingType       clType    = doc.GetElement(cl.GetTypeId()) as CeilingType;
                    CompoundStructure cmpStr_cl = clType.GetCompoundStructure();
                    strBld = LayersAsString(cmpStr_cl, doc, out shelfLength);
                    rows   = clType.GetCompoundStructure().LayerCount;
                    break;

                case "Roofs":
                    RoofBase          rf        = selectedElm as RoofBase;
                    RoofType          rfType    = rf.RoofType;
                    CompoundStructure cmpStr_rf = rfType.GetCompoundStructure();
                    strBld = LayersAsString(cmpStr_rf, doc, out shelfLength);
                    rows   = rfType.GetCompoundStructure().LayerCount;
                    break;

                default:
                    TaskDialog.Show("Warning!", "This category is not supported.");
                    return(Result.Failed);
                }

                using (Transaction trn_1 = new Transaction(doc, "Materials Mark"))
                {
                    FamilyInstance createdElm = null;

                    if (trn_1.Start() == TransactionStatus.Started)
                    {
                        createdElm = doc.Create.NewFamilyInstance(point, materialTag, doc.ActiveView);
                        selectedElm.LookupParameter("LinkedTag").Set(createdElm.Id.IntegerValue);

                        if (trn_1.Commit() == TransactionStatus.Committed)
                        {
                            Transaction trn_2 = new Transaction(doc, "Set parameters");
                            try
                            {
                                trn_2.Start();
                                createdElm.LookupParameter("multilineText").Set(strBld.ToString());
                                createdElm.LookupParameter("# of Rows").Set(rows);
                                createdElm.LookupParameter("Shelf Length").Set(ToFt(shelfLength));
                                XYZ vec;
                                if (selectedElm.Category.Name != "Walls")
                                {
                                    vec = new XYZ(0, 0, createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale);
                                    createdElm.LookupParameter("Down Arrow Direction").Set(1);
                                }
                                else
                                {
                                    vec = new XYZ(-createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale, 0, 0);
                                    createdElm.LookupParameter("Down Arrow Direction").Set(0);
                                }

                                ElementTransformUtils.MoveElement(doc, createdElm.Id, vec);
                                trn_2.Commit();

                                AddElementToSchema(Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")), createdElm, selectedElm.Id);
                            }
                            finally
                            {
                                if (trn_2 != null)
                                {
                                    trn_2.Dispose();
                                }
                            }
                        }
                        else
                        {
                            trn_1.RollBack();
                            return(Result.Failed);
                        }
                    }
                    else
                    {
                        trn_1.RollBack();
                        return(Result.Failed);
                    }

                    return(Result.Succeeded);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Example #12
0
        public void createWall()
        {
            try
            {
                //Wall.Create(Document document, Curve curve, ElementId wallTypeId, ElementId levelId, double wallHeight, double wallOffset, bool flip, bool structural)
                WallType yeniWallType = null;
                bool     bulundu      = false;
                FilteredElementCollector wallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType));
                ElementId defaultElementTypeId     = doc.GetDefaultElementTypeId(ElementTypeGroup.WallType);
                #region Informatik isimli duvar tipini ara, yoksa yarat
                foreach (WallType wt in wallTypes)
                {
                    if (wt.Name == "Informatik")
                    {
                        informatikWallId = wt.Id;
                        bulundu          = true;
                        break;
                    }
                }
                if (bulundu == false)
                {
                    foreach (WallType wt in wallTypes)
                    {
                        if (wt.Id == defaultElementTypeId)
                        {
                            using (Transaction transaction = new Transaction(doc, "DuplicateWallType"))
                            {
                                transaction.Start();
                                yeniWallType = wt.Duplicate("Informatik") as WallType;
                                CompoundStructure cs                   = yeniWallType.GetCompoundStructure();
                                ElementId         materialId           = new ElementId(539);
                                IList <CompoundStructureLayer> cslList = new List <CompoundStructureLayer>();
                                CompoundStructureLayer         csl     = new CompoundStructureLayer(20 * mmToFeet, MaterialFunctionAssignment.Finish1, materialId);
                                cslList.Add(csl);
                                csl = new CompoundStructureLayer(160 * mmToFeet, MaterialFunctionAssignment.Structure, materialId);
                                cslList.Add(csl);
                                csl = new CompoundStructureLayer(20 * mmToFeet, MaterialFunctionAssignment.Finish2, materialId);
                                cslList.Add(csl);
                                CompoundStructure yeniStructure = CompoundStructure.CreateSimpleCompoundStructure(cslList);
                                yeniWallType.SetCompoundStructure(yeniStructure);
                                doc.SetDefaultElementTypeId(ElementTypeGroup.WallType, yeniWallType.Id);
                                transaction.Commit();
                                informatikWallId = yeniWallType.Id;
                            }
                            break;
                        }
                    }
                }
                #endregion
                #region levelId bul
                List <Level>             levels = new List <Level>();
                FilteredElementCollector filteredLevelCollector = new FilteredElementCollector(doc);
                filteredLevelCollector.OfClass(typeof(Level));
                levels = filteredLevelCollector.Cast <Level>().ToList();
                ElementId levelId = null;
                foreach (Level l in levels)
                {
                    if (l.Name == "Level 0")
                    {
                        levelId = l.Id;
                        break;
                    }
                }
                #endregion
                #region cizgileri seçtirt
                uiApp.ActiveUIDocument.Selection.GetElementIds().Clear();
                ISelectionFilter selFilter = new ModelLineSelectionFilter();
                this.Hide();
                IList <Reference> curves = uiApp.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, selFilter, "Select path Curve(s) for partition wall");
                this.Show();
                #endregion
                #region set computing options
                Options opt = new Options();
                opt.ComputeReferences        = true;
                opt.IncludeNonVisibleObjects = true;
                opt.View = doc.ActiveView;

                #endregion
                #region duvar yüksekliği ve offsetini belirle
                double wallHeight = 3000 * mmToFeet;
                double wallOffset = 0;
                #endregion
                List <Wall> yeniDuvarlar = new List <Wall>();
                if (curves.Count > 0)
                {
                    #region döngü
                    for (int i = 0; i < curves.Count; i++)
                    {
                        XYZ  globalPoint;
                        Wall yeniDuvar = null;
                        globalPoint = curves[i].GlobalPoint;
                        Element tempCurve = doc.GetElement(curves[i]) as Element;
                        Curve   curve     = null;
                        if (tempCurve != null)
                        {
                            #region element geometrisinden Curve bulunabiliyor mu
                            foreach (var geoObj in tempCurve.get_Geometry(opt))
                            {
                                Curve cv = geoObj as Curve;
                                if (cv != null)
                                {
                                    curve = cv;
                                    break;
                                }
                            }
                            #endregion
                            #region duvar üret
                            if (curve != null)
                            {
                                using (Transaction wallCreate = new Transaction(doc, "Duvar Yarat"))
                                {
                                    wallCreate.Start();
                                    yeniDuvar = Wall.Create(doc, curve, informatikWallId, levelId, wallHeight, wallOffset, false, false);
                                    if (yeniDuvar != null)
                                    {
                                        yeniDuvarlar.Add(yeniDuvar);
                                    }
                                    wallCreate.Commit();
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion
                    //BuiltInParameter myParameter = BuiltInParameter.DIVIDED_SURFACE_DISPLAY_ORIGINAL_SURFACE;
                    //Element myElement = yeniDuvar as Element;
                    //myElement.get_Parameter(myParameter).Set();
                    #region parametreleri kontrol et
                    if (yeniDuvarlar.Count > 0)
                    {
                        Wall yeniDuvar = yeniDuvarlar[0];

                        string s = string.Empty;
                        foreach (Parameter p in yeniDuvar.Parameters)
                        {
                            s += "Name=" + p.Definition.Name + " StorageType=" + p.StorageType.ToString() + "\r\n";
                        }
                        MessageBox.Show(s);
                    }
                    #endregion
                }
                if (curves.Count < 1)
                {
                    TaskDialog.Show("Seçilmedi", "En az bir çizgi seçmelisiniz");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #13
0
        public Result setup_wall_struct(Document doc)
        {
            WallType wallType = null;

            // FIXME : replace with the material approach?
            FilteredElementCollector wallTypes
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(WallType));

            foreach (WallType wt in wallTypes)
            {
                if (wt.Name.Equals("Generic - 8\""))
                {
                    wallType = wt;
                    break;
                }
            }

            Material concrete = new FilteredElementCollector(doc)
                                .OfClass(typeof(Material))
                                .Cast <Material>().FirstOrDefault(q
                                                                  => q.Name == "Concrete, Cast-in-Place gray");

            Material insulation = new FilteredElementCollector(doc)
                                  .OfClass(typeof(Material))
                                  .Cast <Material>().FirstOrDefault(q
                                                                    => q.Name == "EIFS, Exterior Insulation");

            Material lumber = new FilteredElementCollector(doc)
                              .OfClass(typeof(Material))
                              .Cast <Material>().FirstOrDefault(q
                                                                => q.Name == "Softwood, Lumber");

            Material gypsum = new FilteredElementCollector(doc)
                              .OfClass(typeof(Material))
                              .Cast <Material>().FirstOrDefault(q
                                                                => q.Name == "Gypsum Wall Board");

            WallType newWallType = null;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Basement exterior wall");

                newWallType = wallType.Duplicate("Basement") as WallType;
                // FIXME : this layer should have the "structural material" parameter set
                CompoundStructureLayer l1        = new CompoundStructureLayer(8.0 / 12, MaterialFunctionAssignment.Structure, concrete.Id);
                CompoundStructureLayer newLayer  = new CompoundStructureLayer(3.0 / 12, MaterialFunctionAssignment.Insulation, insulation.Id);
                CompoundStructureLayer newLayer2 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Finish1, lumber.Id);
                CompoundStructureLayer newLayer3 = new CompoundStructureLayer(.5 / 12, MaterialFunctionAssignment.Finish2, gypsum.Id);

                CompoundStructure structure = newWallType.GetCompoundStructure();

                IList <CompoundStructureLayer> layers = structure.GetLayers();

                layers.Add(l1);
                layers.Add(newLayer);
                layers.Add(newLayer2);
                layers.Add(newLayer3);
                structure.SetLayers(layers);

                structure.DeleteLayer(0);

                structure.SetNumberOfShellLayers(ShellLayerType.Interior, 3);

                newWallType.SetCompoundStructure(structure);

                tx.Commit();
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("2x4 + Gypsum wall");

                newWallType = wallType.Duplicate("2x4 + Gypsum") as WallType;
                CompoundStructureLayer l1 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Structure, lumber.Id);
                CompoundStructureLayer l2 = new CompoundStructureLayer(0.5 / 12, MaterialFunctionAssignment.Finish1, gypsum.Id);

                CompoundStructure structure = newWallType.GetCompoundStructure();

                IList <CompoundStructureLayer> layers = structure.GetLayers();

                layers.Add(l2);
                layers.Add(l1);
                layers.Add(l2);
                structure.SetLayers(layers);

                structure.DeleteLayer(0);
                structure.SetNumberOfShellLayers(ShellLayerType.Exterior, 1);
                structure.SetNumberOfShellLayers(ShellLayerType.Interior, 1);

                newWallType.SetCompoundStructure(structure);

                tx.Commit();
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("2x4 + Gypsum wall with Exterior");

                newWallType = wallType.Duplicate("2x4 + Gypsum wall with Exterior") as WallType;
                CompoundStructureLayer l1 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Structure, lumber.Id);
                CompoundStructureLayer l2 = new CompoundStructureLayer(0.5 / 12, MaterialFunctionAssignment.Finish1, gypsum.Id);

                CompoundStructure structure = newWallType.GetCompoundStructure();

                IList <CompoundStructureLayer> layers = structure.GetLayers();

                layers.Add(l2);
                layers.Add(l1);
                layers.Add(l2);
                structure.SetLayers(layers);

                structure.DeleteLayer(0);
                structure.SetNumberOfShellLayers(ShellLayerType.Exterior, 1);
                structure.SetNumberOfShellLayers(ShellLayerType.Interior, 1);


                ElementType wallSweepType = new FilteredElementCollector(doc)
                                            .OfCategory(BuiltInCategory.OST_Cornices)
                                            .WhereElementIsElementType()
                                            .Cast <ElementType>().FirstOrDefault();

                if (wallSweepType != null)
                {
                    var wallSweepInfo = new WallSweepInfo(WallSweepType.Sweep, false);
                    wallSweepInfo.Distance = 2;

                    List <WallSweepInfo> ModSW = new List <WallSweepInfo>();
                    // structure.AddWallSweep(wallSweepInfo);
                }


                newWallType.SetCompoundStructure(structure);

                tx.Commit();
            }

            return(Result.Succeeded);
        }
Example #14
0
        /// <summary>
        /// Create vertical CompoundStructure for wall: new layers, split new region, new sweep and new reveal.
        /// </summary>
        /// <param name="wall">The wall applying the new CompoundStructure.</param>
        public void CreateCSforWall(Wall wall)
        {
            // Get CompoundStructure


            WallType wallType = wall.WallType;
            //wallType.Name = wallType.Name + "_WithNewCompoundStructure";
            CompoundStructure wallCS = wallType.GetCompoundStructure();
            // Get material for CompoundStructureLayer

            Material masonry_Brick = CreateSampleBrickMaterial();
            Material concrete      = CreateSampleConcreteMaterial();

            // Create CompoundStructureLayers and add the materials created above to them.
            List <CompoundStructureLayer> csLayers       = new List <CompoundStructureLayer>();
            CompoundStructureLayer        finish1Layer   = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish1, masonry_Brick.Id);
            CompoundStructureLayer        substrateLayer = new CompoundStructureLayer(0.1, MaterialFunctionAssignment.Substrate, ElementId.InvalidElementId);
            CompoundStructureLayer        structureLayer = new CompoundStructureLayer(0.5, MaterialFunctionAssignment.Structure, concrete.Id);
            CompoundStructureLayer        membraneLayer  = new CompoundStructureLayer(0, MaterialFunctionAssignment.Membrane, ElementId.InvalidElementId);
            CompoundStructureLayer        finish2Layer   = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish2, concrete.Id);

            csLayers.Add(finish1Layer);
            csLayers.Add(substrateLayer);
            csLayers.Add(structureLayer);
            csLayers.Add(membraneLayer);
            csLayers.Add(finish2Layer);

            // Set the created layers to CompoundStructureLayer
            wallCS.SetLayers(csLayers);


            //Set which layer is used for structural analysis
            wallCS.StructuralMaterialIndex = 2;

            // Set shell layers and wrapping.
            wallCS.SetNumberOfShellLayers(ShellLayerType.Interior, 2);
            wallCS.SetNumberOfShellLayers(ShellLayerType.Exterior, 1);
            wallCS.SetParticipatesInWrapping(0, false);

            // Points for adding wall sweep and reveal.
            UV sweepPoint  = UV.Zero;
            UV revealPoint = UV.Zero;

            // split the region containing segment 0.
            int segId = wallCS.GetSegmentIds()[0];

            foreach (int regionId in wallCS.GetAdjacentRegions(segId))
            {
                // Get the end points of segment 0.
                UV endPoint1 = UV.Zero;
                UV endPoint2 = UV.Zero;
                wallCS.GetSegmentEndPoints(segId, regionId, out endPoint1, out endPoint2);

                // Split a new region in split point and orientation.
                RectangularGridSegmentOrientation splitOrientation = (RectangularGridSegmentOrientation)(((int)(wallCS.GetSegmentOrientation(segId)) + 1) % 2);
                UV   splitUV         = (endPoint1 + endPoint2) / 2.0;
                int  newRegionId     = wallCS.SplitRegion(splitUV, splitOrientation);
                bool isValidRegionId = wallCS.IsValidRegionId(newRegionId);

                // Find the enclosing region and the two segments intersected by a line through the split point
                int segId1;
                int segId2;
                int findRegionId = wallCS.FindEnclosingRegionAndSegments(splitUV, splitOrientation, out segId1, out segId2);

                // Get the end points of finding segment 1 and compute the wall sweep point.
                UV eP1 = UV.Zero;
                UV eP2 = UV.Zero;
                wallCS.GetSegmentEndPoints(segId1, findRegionId, out eP1, out eP2);
                sweepPoint = (eP1 + eP2) / 4.0;

                // Get the end points of finding segment 2 and compute the wall reveal point.
                UV ep3 = UV.Zero;
                UV ep4 = UV.Zero;
                wallCS.GetSegmentEndPoints(segId2, findRegionId, out ep3, out ep4);
                revealPoint = (ep3 + ep4) / 2.0;
            }

            // Create a WallSweepInfo for wall sweep
            WallSweepInfo sweepInfo = new WallSweepInfo(true, WallSweepType.Sweep);

            PrepareWallSweepInfo(sweepInfo, sweepPoint.V);
            // Set sweep profile: Sill-Precast : 8" Wide
            sweepInfo.ProfileId = GetProfile("8\" Wide").Id;
            sweepInfo.Id        = 101;
            wallCS.AddWallSweep(sweepInfo);

            // Create a WallSweepInfo for wall reveal
            WallSweepInfo revealInfo = new WallSweepInfo(true, WallSweepType.Reveal);

            PrepareWallSweepInfo(revealInfo, revealPoint.U);
            revealInfo.Id = 102;
            wallCS.AddWallSweep(revealInfo);

            // Set the new wall CompoundStructure to the type of wall.
            wallType.SetCompoundStructure(wallCS);
        }
Example #15
0
        private void compoundStructureLayeToJson(DesignAutomationData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            Application rvtApp = data.RevitApp;

            if (rvtApp == null)
            {
                throw new InvalidDataException(nameof(rvtApp));
            }

            string modelPath = data.FilePath;

            if (String.IsNullOrWhiteSpace(modelPath))
            {
                throw new InvalidDataException(nameof(modelPath));
            }

            Document doc = data.RevitDoc;

            if (doc == null)
            {
                throw new InvalidOperationException("Could not open document.");
            }

            JArray wallInfoResult = new JArray();

            FilteredElementCollector wallCollector = new FilteredElementCollector(doc).OfClass(typeof(Wall)).WhereElementIsNotElementType();

            foreach (Element e in wallCollector)
            {
                Wall     w     = e as Wall;
                WallType wtype = w.WallType;

                //CURTAIN WALL doesn't contain compound structure layers
                if (wtype != null && !wtype.Name.Contains("Curtain"))
                {
                    CompoundStructure compoundStruct = wtype.GetCompoundStructure();
                    IList <CompoundStructureLayer> compoundStructLayers = compoundStruct.GetLayers() as IList <CompoundStructureLayer>;
                    if (compoundStructLayers.Count == 0)
                    {
                        continue;
                    }

                    dynamic wallLayersInfo = new JObject();
                    wallLayersInfo.uniqueId = w.UniqueId;
                    wallLayersInfo.layers   = new JArray();

                    foreach (CompoundStructureLayer compoundStructLayer in compoundStructLayers)
                    {
                        dynamic layerInfo = new JObject();
                        layerInfo.function = compoundStructLayer.Function.ToString();
                        layerInfo.material = ((Material)doc.GetElement(compoundStructLayer.MaterialId)).Name;
                        layerInfo.width    = compoundStructLayer.Width;

                        wallLayersInfo.layers.Add(layerInfo);
                    }

                    wallInfoResult.Add(wallLayersInfo);
                }
            }

            // save all to a .json file
            using (StreamWriter file = File.CreateText("result.json"))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    wallInfoResult.WriteTo(writer);
                }
        }
Example #16
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            //ElementSet a = uidoc.Selection.Elements; // 2014
            ICollection <ElementId> ids = uidoc.Selection.GetElementIds(); // 2015

            const string newWallTypeName = "NewWallType_with_Width_doubled";

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Duplicate Wall Type");

                foreach (ElementId id in ids)
                {
                    Wall wall = doc.GetElement(id) as Wall;

                    if (null != wall)
                    {
                        WallType wallType = wall.WallType;

                        WallType newWallType = wallType.Duplicate(
                            newWallTypeName) as WallType;

                        //CompoundStructureLayerArray layers = newWallType.CompoundStructure.Layers; // 2011
                        IList <CompoundStructureLayer> layers = newWallType.GetCompoundStructure().GetLayers(); // 2012

                        foreach (CompoundStructureLayer layer in layers)
                        {
                            // double each layer thickness:

                            //layer.Thickness *= 2.0; // 2011

                            layer.Width *= 2.0; // 2012
                        }
                        // assign the new wall type back to the wall:

                        wall.WallType = newWallType;

                        // only process the first wall, if one was selected:

                        break;
                    }
                }
                t.Commit();
            }
            return(Result.Succeeded);

            #region Assign colour
#if ASSIGN_COLOUR
            ElementSet elemset = doc.Selection.Elements;

            foreach (Element e in elemset)
            {
                FamilyInstance inst = e as FamilyInstance;

                // get the symbol and duplicate it:
                FamilySymbol dupSym = inst.Symbol.Duplicate(
                    "D1") as FamilySymbol;

                // access the material:
                ElementId matId = dupSym.get_Parameter(
                    "Material").AsElementId();

                Material mat = doc.GetElement(ref matId)
                               as Autodesk.Revit.Elements.Material;

                // change the color of this material:
                mat.Color = new Color(255, 0, 0);

                // assign the new symbol to the instance:
                inst.Symbol = dupSym;
#endif // ASSIGN_COLOUR
            #endregion // Assign colour
        }
    }
Example #17
0
        //----------------------------------------------------------
        public string Duplicate_Type(UIApplication uiapp, Document doc)
        {
            string result = "F";

            try
            {
                type_data     item_type     = (type_data)type.SelectedItem;
                material_data item_material = (material_data)material.SelectedItem;

                CultureInfo culture   = CultureInfo.CreateSpecificCulture("eu-ES");
                string      specifier = "G";

                if (item_type.type.Category.Name == myAll_Data.list_category_draw[3])
                {
                    WallType          wall_Type             = item_type.type.Duplicate("STB " + b.Text + " " + item_material.single_value) as WallType;
                    CompoundStructure compound_new          = wall_Type.GetCompoundStructure();
                    IList <CompoundStructureLayer> cslayers = compound_new.GetLayers();

                    for (int i = 0; i < cslayers.Count; i++)
                    {
                        compound_new.SetLayerWidth(cslayers[i].LayerId, Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                        compound_new.SetMaterialId(cslayers[i].LayerId, item_material.material.Id);
                    }
                    wall_Type.SetCompoundStructure(compound_new);

                    my_type_data.Add(new type_data()
                    {
                        type         = wall_Type,
                        single_value = wall_Type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == wall_Type.Name);

                    double width = Math.Round(wall_Type.Width * myAll_Data.list_unit_value_data[6], 3);
                    wall_Type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("h = " + width.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[4])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value);
                    new_type.LookupParameter(myAll_Data.list_parameter_column[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.LookupParameter(myAll_Data.list_parameter_column[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    double width  = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value);
                    new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    double width  = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3);
                    new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm");
                }
                else if (item_type.type.Category.Name == myAll_Data.list_category_draw[1] || item_type.type.Category.Name == myAll_Data.list_category_draw[2])
                {
                    ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text);
                    new_type.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]);
                    new_type.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    Update_UK_MA();
                }
                else
                {
                    ElementType new_type = item_type.type.Duplicate(item_type.type.Name + " " + b.Text);

                    my_type_data.Add(new type_data()
                    {
                        type         = new_type,
                        single_value = new_type.Name
                    });
                    type.Items.Refresh();
                    type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name);

                    Update_UK_MA();
                }

                result = "S";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }