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);
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            //// Fields for checking for updates
            //DateTime dbLastUpdated = LocalFiles.UnixTimeStampToDateTime(LocalFiles.GetLastUpdatedDateTime());
            //DateTime localFileUpdated = File.GetLastWriteTimeUtc(LocalFiles.localJsonFile);

            InitializeComponent();

            // Prompt user to download definitions if local files are missing
            if (!File.Exists(LocalFiles.localJsonFile) || !File.Exists(LocalFiles.localSpFile))
            {
                LocalFiles.definitionsUpToDate = false;

                string           messageBoxText = "You must sync with the OpenRFA.org shared parameter defintions to use this add-in. Would you like to sync now?";
                MessageBoxResult result         = MessageBox.Show(messageBoxText, "OpenRFA Parameter Definitions Missing", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                switch (result)
                {
                case MessageBoxResult.Yes:
                    // Download JSON/TXT from OpenRFA.org
                    LocalFiles.DownloadLocalData();
                    RefreshData();

                    LocalFiles.definitionsUpToDate = true;
                    break;

                case MessageBoxResult.No:
                    LocalFiles.definitionsUpToDate = false;
                    //DialogResult = true;
                    break;
                }
            }
            else
            {
                // Store date/times locally to ensure methods are called from all scopes
                DateTime localFileUpdated = LocalFiles.GetLastUpdateJsonLocal();
                DateTime dbLastUpdated    = LocalFiles.GetLastUpdateJsonOnline();

                // Prompt user to updated definitions if local file is outdated
                if (localFileUpdated < dbLastUpdated)

                //&& LocalFiles.dbLastUpdated != LocalFiles.UnixTimeStampToDateTime(000))
                {
                    string messageBoxText = "OpenRFA.org was udpated: " + dbLastUpdated.ToLocalTime().ToString() +
                                            "\nYour last sync: " + localFileUpdated.ToString() +
                                            "\n\nWould you like to sync with OpenRFA.org?";

                    MessageBoxResult result = MessageBox.Show(messageBoxText, "OpenRFA Parameter Definitions Outdated", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                    switch (result)
                    {
                    case MessageBoxResult.Yes:
                        // Download JSON/TXT from OpenRFA.org
                        LocalFiles.DownloadLocalData();
                        RefreshData();

                        // Store new values for updated definitions
                        LocalFiles.definitionsUpToDate = true;
                        break;

                    case MessageBoxResult.No:
                        LocalFiles.definitionsUpToDate = false;
                        break;
                    }
                }
                if (dbLastUpdated == LocalFiles.UnixTimeStampToDateTime(000))
                {
                    MessageBox.Show("Can't connect to database. Please ensure you are online.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                // Notify the user that definitions are up to date
                if (localFileUpdated >= dbLastUpdated)
                {
                    LocalFiles.definitionsUpToDate = true;
                    //string messageBoxText = "Your parameter definitions are synced with OpenRFA.org.";
                    //MessageBoxResult result = MessageBox.Show(messageBoxText, "OpenRFA Parameter Definitions Up to Date", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                RefreshData();
            }

            // Notify users of status of parameter definitions
            if (LocalFiles.definitionsUpToDate == true)
            {
                UpdateStatusText("Your parameter definitions are up to date.");
            }
            else
            {
                UpdateStatusText("You parameter definitions are outdated.");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Downloads online JSON/TXT and refreshes data
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSync_Click(object sender, RoutedEventArgs e)
 {
     // Download JSON/TXT from OpenRFA.org
     LocalFiles.DownloadLocalData();
     RefreshData();
 }