Пример #1
0
        /// <summary>
        /// Add selected shared parameters to cart DataTable.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (gridParams.SelectedItems.Count > 0)
            {
                foreach (DataRowView dr in gridParams.SelectedItems)
                {
                    //DataRow selectedParam = (System.Data.DataRow)gridParams.SelectedItems[i];
                    if (dr != null)
                    {
                        ImportProcess.dtCart.Rows.Add(dr.Row.ItemArray);
                    }

                    // Update status text
                    if (gridParams.SelectedItems.Count == 1)
                    {
                        UpdateStatusText("Added (1) parameter to list of parameters to be added.");
                    }
                    if (gridParams.SelectedItems.Count > 1)
                    {
                        UpdateStatusText("Added (" + gridParams.SelectedItems.Count.ToString() + ") parameters to list of parameters to be added.");
                    }
                }
            }

            // Remove duplicate entries
            ImportProcess.dtCart = ImportProcess.RemoveDuplicateRows(ImportProcess.dtCart, "name");

            // Refresh DataGrid
            gridCart.Items.Refresh();
        }
        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;

            // Create local directory
            LocalFiles.CreateLocalDir();

            // Check OpenRFA.org for latest update to online db
            LocalFiles.GetLastUpdateJsonOnline();

            MainWindow appDialog = new MainWindow();

            appDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            // Check if current document is a Revit family
            if (doc.IsFamilyDocument)
            {
                // Only open window if continueCommand is set true
                if (ImportProcess.continueCommand == true)
                {
                    appDialog.ShowDialog();
                }

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

                    // Complete import process
                    ImportProcess.ProcessImport(doc, app, confDialog.DialogResult.HasValue, confDialog.DialogResult.Value);

                    // Clear all data in case addin is run again in the same session
                    // TODO: Call this method with every method that uses the datatables?
                    ImportProcess.ClearAllData();
                }

                return(Result.Succeeded);
            }
            else
            {
                MessageBox.Show("The current document must be a Revit family to use this tool.");
                return(Result.Failed);
            }
        }
Пример #3
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);
        }
Пример #4
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.");
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Refreshes all data including DataTables, DataViews, DataContext, etc.
        /// </summary>
        public void RefreshData()
        {
            // Convert Json to list
            LocalFiles.JsonToList();

            // Convert list to DataTable
            ImportProcess.dtParams = SharedParameter.ToDataTable(LocalFiles.sharedParams);

            // Creates new view object of DataTable for customizing columns
            DataView view = new DataView(ImportProcess.dtParams);

            // Bind all parameter properties to the DataGrid
            gridParams.DataContext = ImportProcess.dtParams.DefaultView;

            // Create DataTable for cart to add parameters to and display in grid
            ImportProcess.dtCart = SharedParameter.ToDataTable(LocalFiles.sharedParams);
            // Clear the cart DataTable - we only add DataContext to create identical columns. Is there a better way?
            ImportProcess.dtCart.Clear();
            gridCart.DataContext = ImportProcess.dtCart.DefaultView;

            ImportProcess.blv = ImportProcess.dtParams.DefaultView;

            // Set the BindingListView to show approved parameters by default
            ImportProcess.blv.Filter = "state = 'Approved'";

            // Populate combobox with DataType options for filtering
            // Create a view of distinct datatypes
            DataTable dtParamsDistinct = view.ToTable(true, "datatype");

            dtParamsDistinct.DefaultView.Sort = "datatype asc";
            comboDataType.ItemsSource         = dtParamsDistinct.DefaultView;

            // Populate Group combobox with parameter groups
            DataTable dtParamGroups = view.ToTable(true, "group");

            dtParamGroups.DefaultView.Sort = "group asc";
            comboParamGroup.ItemsSource    = dtParamGroups.DefaultView;

            // Populate combobox with parameter sets
            List <string> _newSets    = new List <string>();
            DataTable     dtParamSets = view.ToTable(true, "parameter_sets");

            // Split comma separated values for parameters with multiple tags
            foreach (DataRow _dr in dtParamSets.Rows)
            {
                if (_dr[0].ToString().Contains(", "))
                {
                    // Split multiple values
                    foreach (string s in _dr[0].ToString().Split(','))
                    {
                        _newSets.Add(s);
                    }
                }
            }

            // Remove rows that have multiple values
            for (int i = dtParamSets.Rows.Count - 1; i >= 0; i--)
            {
                DataRow dr = dtParamSets.Rows[i];
                if (dr[0].ToString().Contains(", "))
                {
                    dr.Delete();
                }
            }
            dtParamSets.AcceptChanges();

            for (int i = 0; i < _newSets.Count(); i++)
            {
                // Remove extra space from split
                if (_newSets[i].StartsWith(" "))
                {
                    _newSets[i] = _newSets[i].Substring(1);
                }

                // Add parameter sets from list as data rows
                DataRow _newRow = dtParamSets.NewRow();
                _newRow[0] = _newSets[i];
                dtParamSets.Rows.Add(_newRow);
            }

            // Remove duplicates
            ImportProcess.RemoveDuplicateRows(dtParamSets, 0);
            dtParamSets.DefaultView.Sort  = "parameter_sets asc";
            comboParameterSet.ItemsSource = dtParamSets.DefaultView;
        }
Пример #6
0
 /// <summary>
 /// Cancels the dialog.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonCancel_Click(object sender, RoutedEventArgs e)
 {
     ImportProcess.ClearAllData();
 }