Example #1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            // get selected element
            var elementRef = uidoc.Selection.PickObject(ObjectType.Element);
            var element    = doc.GetElement(elementRef.ElementId);

            // convert element to CrossPlatform one
            var wall = new CrossPlatform.BIM.Wall();

            wall = WallInterop.FromRevit(element as Wall);

            // write to json on desktop
            var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "exportedWall.json");
            var exported = Library.IO.Json.ToJsonFile(wall, filepath);

            // inform user
            if (exported)
            {
                TaskDialog.Show("Success", "Saved the JSON file here :" + Environment.NewLine + filepath);
            }
            else
            {
                TaskDialog.Show("Failed", "Failed to export the JSON file.");
            }

            return(exported ? Result.Succeeded : Result.Failed);
        }
Example #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: start here modifying the behaviour of your command.
            RhinoApp.WriteLine("The {0} command will make a wall from a CrossPlatform.BIM.Wall object.");
            try
            {
                // load the json file from disk
                OpenFileDialog theDialog = new OpenFileDialog();
                theDialog.Title = "Please select the CrossPlatform.BIM.Wall json file.";
                DialogResult result = theDialog.ShowDialog();
                if (result != DialogResult.OK) // Test result.
                {
                    RhinoApp.WriteLine("Could not load file.");
                    return(Result.Cancel);
                }

                // import the CrossPlatform Wall
                RhinoApp.WriteLine("Importing wall from file : " + theDialog.FileName);
                var wall = CrossPlatform.Library.IO.Json.FromJsonFile <CrossPlatform.BIM.Wall>(theDialog.FileName);

                // make a new Rhino box from wall dimensions
                var brep = WallInterop.ToRhino(wall);

                RhinoApp.WriteLine(CrossPlatform.Library.IO.Json.ToJson(wall));
                if (doc.Objects.AddBrep(brep) == System.Guid.Empty)
                {
                    throw new Exception("Could not add box to document");
                }
                RhinoApp.WriteLine("The {0} command added one wall to the document.");
            }
            catch (Exception e)
            {
                RhinoApp.WriteLine("Something failed miserably : " + e.Message);
                throw;
            }

            doc.Views.Redraw();
            return(Result.Success);
        }