示例#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;

            // Launches the application window (WPF) for user input
            OpenRFA_WPF_CS.MainWindow appDialog = new MainWindow();
            appDialog.ShowDialog();


            {
                // Only executes if the user clicked "OK" button
                if (appDialog.DialogResult.HasValue && appDialog.DialogResult.Value)
                {
                    // Opens configuration window
                    OpenRFA_WPF_CS.ConfigureImport confDialog = new ConfigureImport();
                    confDialog.ShowDialog();

                    using (Transaction trans = new Transaction(doc, "AddParams"))
                    {
                        // Save list of parameters from MainWindow
                        ImportProcess.ParamCache = MainWindow.paramsOut;

                        // Check if configuration options have been saved
                        if (confDialog.DialogResult.HasValue && confDialog.DialogResult.Value)
                        {
                            // Test text for showing if datatable has been updated.
                            StringBuilder sb = new StringBuilder();
                            sb.Append("Updated datatable: \n");
                            foreach (DataRow dr in ConfigureImport.dtConfig.Rows)
                            {
                                sb.Append(dr[0] + ", " + dr[1] + "," + dr[2] + "\n");
                            }
                            MessageBox.Show(sb.ToString());

                            trans.Start();

                            // Set current shared parameters file
                            app.SharedParametersFilename = LocalFiles.tempDefinitionsFile;
                            defFile = app.OpenSharedParameterFile();

                            // Adds shared parameters to family
                            // TODO: Pass a list of BuiltInParameterGroup (currently only a placeholder) for overload
                            //SharedParameter.ImportParameterToFamily(doc, defFile, BuiltInParameterGroup.PG_MECHANICAL);

                            foreach (DataRow _row in ConfigureImport.dtConfig.Rows)
                            {
                                // Check if configuration is set to instance.
                                // TODO: Turn this into a method.
                                bool _instance = false;
                                if (_row[2].ToString() == "Instance")
                                {
                                    _instance = true;
                                }
                                else
                                {
                                    _instance = false;
                                }

                                // Get BuiltInParameterGroup by name
                                BuiltInParameterGroup _bipGroup = new BuiltInParameterGroup();
                                _bipGroup = SPBuiltInGroup.GetByName(_row[1].ToString());

                                // Get BIPG using the BuiltinParameterGroupLookup Class
                                var lookup = new BuiltInParameterGroupLookup();
                                BuiltInParameterGroup _selectedGroup = lookup[_row[1].ToString()];

                                // Write shared parameter to family
                                SharedParameter.ImportParameterToFamily(doc, defFile, _row, _selectedGroup, _instance);
                            }

                            trans.Commit();
                        }
                        else
                        {
                            MessageBox.Show("Operation canceled.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Operation canceled.");
                }
            }

            // Clear DataTables. TODO: Turn this into a method.
            ConfigureImport.dtConfig.Clear();
            ImportProcess.RemoveColumns(ConfigureImport.dtConfig);

            return(Result.Succeeded);
        }
示例#2
0
        /// <summary>
        /// Configures parameters to be imported to a family
        /// </summary>
        /// <param name="doc">The Revit document to process (must be a Revit family).</param>
        /// <param name="app">The current Revit application.</param>
        /// <param name="dialogHasValue">Does the MainWindow object have a value?</param>
        /// <param name="dialogValue">The result of the MainWindow object.</param>
        public static void ProcessImport(
            Document doc,
            Autodesk.Revit.ApplicationServices.Application app,
            bool dialogHasValue,
            bool dialogValue
            )
        {
            using (Transaction trans = new Transaction(doc, "AddParams"))
            {
                // Save list of parameters from MainWindow
                ImportProcess.ParamCache = ImportProcess.paramsOut;

                // Check if configuration options have been saved
                if (dialogHasValue && dialogValue)
                {
                    // Start transaction
                    trans.Start();

                    // Set current shared parameters file
                    app.SharedParametersFilename = LocalFiles.tempDefinitionsFile;
                    defFile = app.OpenSharedParameterFile();

                    foreach (DataRow _row in ConfigureImport.dtConfig.Rows)
                    {
                        // Check if configuration is set to instance.
                        // TODO: Turn this into a method.
                        bool _instance = false;
                        if (_row[2].ToString() == "Instance")
                        {
                            _instance = true;
                        }
                        else
                        {
                            _instance = false;
                        }

                        // Get BuiltInParameterGroup by name
                        BuiltInParameterGroup _bipGroup = new BuiltInParameterGroup();
                        _bipGroup = SPBuiltInGroup.GetByName(_row[1].ToString());

                        // Get BIPG using the BuiltinParameterGroupLookup Class
                        var lookup = new BuiltInParameterGroupLookup();
                        BuiltInParameterGroup _selectedGroup = lookup[_row[1].ToString()];
                        try {
                            // Write shared parameter to family
                            ImportProcess.ImportParameterToFamily(doc, defFile, _row, _selectedGroup, _instance);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Error");
                        }
                    }

                    trans.Commit();

                    // Show messages to user
                    if (ImportProcess.existingParams.Count > 0)
                    {
                        MessageBox.Show(ImportProcess.addedParams.Count + " parameters have been added to this family.\n" +
                                        ImportProcess.existingParams.Count.ToString() + " parameters already exist in the family.");

                        // Clear list of parameters every time the method is complete
                        addedParams.Clear();
                        existingParams.Clear();
                    }
                    else
                    {
                        MessageBox.Show(ImportProcess.addedParams.Count + " parameters have been added to this family.\n");

                        // Clear list of parameters every time the method is complete
                        addedParams.Clear();
                        existingParams.Clear();
                    }
                }
                else
                {
                    MessageBox.Show("No parameters have been loaded.");
                }
            }
        }