Ejemplo n.º 1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app
                = uiapp.Application;
            Document doc = uidoc.Document;

            // Check that we are in a 3D view.

            View3D view = doc.ActiveView as View3D;

            if (null == view)
            {
                Util.ErrorMsg(
                    "You must be in a 3D view to export.");

                return(Result.Failed);
            }

            // Prompt for output filename selection.

            string filename = doc.PathName;

            if (0 == filename.Length)
            {
                filename = doc.Title;
            }

            if (null == _output_folder_path)
            {
                // Sometimes the command fails if the file is
                // detached from central and not saved locally

                try
                {
                    _output_folder_path = Path.GetDirectoryName(
                        filename);
                }
                catch
                {
                    TaskDialog.Show("Folder not found",
                                    "Please save the file and run the command again.");
                    return(Result.Failed);
                }
            }

            filename = Path.GetFileName(filename) + ".js";

            if (!SelectFile(ref _output_folder_path,
                            ref filename))
            {
                return(Result.Cancelled);
            }

            filename = Path.Combine(_output_folder_path,
                                    filename);

            // Ask user whether to interactively choose
            // which parameters to export or just export
            // them all.

            TaskDialog td = new TaskDialog("Ask user to filter parameters");

            td.Title             = "Filter parameters";
            td.CommonButtons     = TaskDialogCommonButtons.No | TaskDialogCommonButtons.Yes;
            td.MainInstruction   = "Do you want to filter the parameters of the objects to be exported?";
            td.MainContent       = "Click Yes and you will be able to select parameters for each category in the next window";
            td.AllowCancellation = true;
            td.VerificationText  = "Check this to include type properties";

            if (TaskDialogResult.Yes == td.Show())
            {
                filterElementParameters(doc, td.WasVerificationChecked());
                if (ParameterFilter.status == "cancelled")
                {
                    ParameterFilter.status = "";
                    return(Result.Cancelled);
                }
            }

            // Save file.

            ExportView3D(doc.ActiveView as View3D,
                         filename);

            return(Result.Succeeded);
        }