Beispiel #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument   uidoc         = commandData.Application.ActiveUIDocument;
            string       baseLevel     = Properties.Settings.Default.BaseLevelName;
            string       topLevel      = Properties.Settings.Default.TopLevelName;
            float        scale         = Properties.Settings.Default.Scale;
            HouseBuilder elementPlacer = new HouseBuilder(uidoc.Document, baseLevel, topLevel, scale);

            try
            {
                using (Transaction transaction = new Transaction(uidoc.Document, "Classify Rooms"))
                {
                    transaction.Start();
                    elementPlacer.ClassifyRooms();
                    transaction.Commit();
                }
                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
        public void Execute(UIApplication app)
        {
            UIDocument uidoc = app.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            float  scale = 0;
            double overhang = 0;
            string levelName = "", topLevelName = "";

            try
            {
                scale        = Properties.Settings.Default.Scale;
                overhang     = UnitUtils.ConvertToInternalUnits(Properties.Settings.Default.Overhang, UnitTypeId.Meters);
                levelName    = Properties.Settings.Default.BaseLevelName;
                topLevelName = Properties.Settings.Default.TopLevelName;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                PlaceElementsForm.CloseForm();
            }

            string     path       = PlaceElementsForm.filePath;
            XYZ        roofVector = PlaceElementsForm.roofSelector.SlopeVector;
            RoofDesign roofDesign = PlaceElementsForm.roofSelector.RoofStyle;
            double     slope      = RoofSelector.GetSlopeByType(roofDesign);

            HouseBuilder builder = new HouseBuilder(doc, levelName, topLevelName, scale);

            string errorMessage = "";

            using (Transaction transaction = new Transaction(doc, "Contruir JSON"))
            {
                transaction.Start();
                try
                {
                    builder.BuildJSON(path);
                }
                catch (Exception e)
                {
                    errorMessage += $"\nErro ao construir elementos do JSON: \"{e.Message}\"";
                }
                try
                {
                    builder.CreateFloor(Properties.Settings.Default.FloorName);
                }
                catch (Exception e)
                {
                    errorMessage += $"\nErro ao construir piso: \"{e.Message}\"";
                }
                try
                {
                    builder.CreateCeiling(Properties.Settings.Default.CeilingName);
                }
                catch (Exception e)
                {
                    errorMessage += $"\nErro ao construir laje: \"{e.Message}\"";
                }
                try
                {
                    builder.ClassifyRooms();
                }
                catch (Exception e)
                {
                    errorMessage += $"\nErro ao classificar ambientes: \"{e.Message}\"";
                }
                transaction.Commit();
            }
            using (Transaction transaction = new Transaction(doc, "Contruir Telhado"))
            {
                transaction.Start();

                try
                {
                    builder.CreateRoof(overhang, slope, roofVector, roofDesign);
                }
                catch (Exception e)
                {
                    errorMessage += $"\nErro ao construir telhado: \"{e.Message}\"";
                }
                transaction.Commit();
            }

            if (errorMessage.Length > 1)
            {
                MessageBox.Show(errorMessage, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            PlaceElementsForm.CloseForm();
        }