Пример #1
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.WinConfigureImport = ((OpenRFA_WPF_CS.ConfigureImport)(target));
                return;

            case 2:
                this.gridParamCon = ((System.Windows.Controls.DataGrid)(target));

            #line 19 "..\..\ConfigureImport.xaml"
                this.gridParamCon.CurrentCellChanged += new System.EventHandler <System.EventArgs>(this.gridParamCon_CurrentCellChanged);

            #line default
            #line hidden

            #line 19 "..\..\ConfigureImport.xaml"
                this.gridParamCon.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.gridParamCon_SelectionChanged);

            #line default
            #line hidden
                return;

            case 3:
                this.AssignGroup = ((System.Windows.Controls.DataGridComboBoxColumn)(target));
                return;

            case 4:
                this.InstanceOrType = ((System.Windows.Controls.DataGridComboBoxColumn)(target));
                return;

            case 5:
                this.ButtonImport = ((System.Windows.Controls.Button)(target));

            #line 32 "..\..\ConfigureImport.xaml"
                this.ButtonImport.Click += new System.Windows.RoutedEventHandler(this.ButtonImport_Click);

            #line default
            #line hidden
                return;

            case 6:
                this.ButtonCancel = ((System.Windows.Controls.Button)(target));

            #line 33 "..\..\ConfigureImport.xaml"
                this.ButtonCancel.Click += new System.Windows.RoutedEventHandler(this.ButtonCancel_Click);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
        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);
        }