public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_startTime = DateTime.Now; UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Metrics.StartCommand(doc, "Ribbon_Command", m_startTime); try { Ribbon_Form form = new Ribbon_Form(); //form.Document = doc; form.ShowDialog(); } catch (Exception ex) { Metrics.AppendLog("Exception: " + ex.Message); Metrics.AppendLog("Result: Failed"); return(Result.Failed); } Metrics.EndCommand(m_startTime); return(Result.Succeeded); }
// Get and save User Preferences public static MainUserPreferences GetUserPreferences() { MainUserPreferences userPreferences; try { Properties.Settings settings = Properties.Settings.Default; string json = settings.Settings_UserPreferences; if (json == "" || json == null) { userPreferences = new MainUserPreferences(); } else { userPreferences = new JavaScriptSerializer().Deserialize <MainUserPreferences>(json); } return(userPreferences); } catch (Exception ex) { Metrics.AppendLog("Exception in GetUserPreferences\r\n" + ex.Message); return(null); } }
private void UpgradeButton_Click(object sender, EventArgs e) { TaskDialogResult result = TaskDialog.Show("Update Moduleds", "Please confirm to update Arcadis Tools.", TaskDialogCommonButtons.Cancel & TaskDialogCommonButtons.Ok); if (result == TaskDialogResult.Ok) { foreach (ListViewItem module in ModulesListView.CheckedItems) { string repoFile = Path.Combine(m_repositoryPath, module.SubItems[0].Text + ".dll"); string revitFile = Path.Combine(m_revitAddinPath, module.SubItems[0].Text + ".dll"); File.Copy(repoFile, revitFile, true); repoFile = Path.Combine(m_repositoryPath, module.SubItems[0].Text + ".addin"); revitFile = Path.Combine(m_revitAddinPath, module.SubItems[0].Text + ".addin"); File.Copy(repoFile, revitFile, true); Metrics.AppendLog("Assembly:" + module.SubItems[0].Text + " updated"); } } else { Metrics.AppendLog("No updates selected."); } Close(); }
public Result OnShutdown(UIControlledApplication application) { DateTime endTime = DateTime.Now; Metrics.AppendLog("\r\n\r\nRevit Session End: " + endTime.ToString()); TimeSpan session = endTime - m_startTime; Metrics.AppendLog("Revit Session duration: " + session.ToString()); return(Result.Succeeded); }
public static void LoadAddin(string addinPath) { //string asspath = Path.GetDirectoryName(path); //string addinPath = Path.Combine(asspath, addin); try { g_controlledUIApp.LoadAddIn(addinPath); } catch (Exception ex) { Metrics.AppendLog("Error loading addin: " + addinPath + " could already be loaded."); } }
private void VersionsForm_Load(object sender, EventArgs e) { MessageTextBox.Text = "New versions or Arcadis Tools are available. Select modules to update."; string[] items = new string[3]; foreach (AssemblyVersion assembly in newAssemblies) { items[0] = Path.GetFileNameWithoutExtension(assembly.AssemblyName); items[1] = assembly.RepositoryVersion; items[2] = assembly.CurrentVersion; Metrics.AppendLog("Assembly:" + items[0] + " Repository Version: " + items[1] + " Current Version: " + items[2]); ListViewItem viewItem = new ListViewItem(items); viewItem.Checked = true; ModulesListView.Items.Add(viewItem); } }
public static BitmapImage ConvertBitmap(Bitmap bitmap) { try { MemoryStream ms = new MemoryStream(); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); BitmapImage image = new BitmapImage(); image.BeginInit(); ms.Seek(0, SeekOrigin.Begin); image.StreamSource = ms; image.EndInit(); return(image); } catch (Exception ex) { Metrics.AppendLog("Exception creating button image.\r\n" + ex.Message); return(null); } }
public static void CreateCommand(Autodesk.Revit.UI.RibbonPanel panel, ToolbarPanel toolPanel, string name, string title, string path, string com, Bitmap bitmap, string tooltip, Bitmap bitmapHelp, string longDesc, ContextualHelp contextHelp) { try { PushButton button = panel.AddItem(new PushButtonData(name, title, path, com)) as PushButton; button.LargeImage = ConvertBitmap(bitmap); button.ToolTip = tooltip; if (null != bitmapHelp) { button.ToolTipImage = ConvertBitmap(bitmapHelp); } button.LongDescription = longDesc; button.SetContextualHelp(contextHelp); toolPanel.Commands.Add(new ToolbarCommand(name, button, bitmap)); } catch (Exception ex) { Metrics.AppendLog("Exception creating button: " + name + "\r\n" + ex.Message); } }
public Result OnStartup(UIControlledApplication application) { try { m_startTime = DateTime.Now; Metrics.AppendLog("Launching Arcadis Main Application"); Metrics.AppendLog("Session Start: " + m_startTime.ToString()); //Language info //------------- CultureInfo ci = Thread.CurrentThread.CurrentCulture; var ri = new RegionInfo(ci.Name); Utils.k_systemCountry = ri.DisplayName; Utils.k_systemLanguage = ci.NativeName; Utils.k_revitLanguage = application.ControlledApplication.Language.ToString(); Metrics.AppendLog("System Language: " + Utils.k_systemLanguage); Metrics.AppendLog("System Country: " + Utils.k_systemCountry); Metrics.AppendLog("Revit language: " + Utils.k_revitLanguage); Metrics.AppendLog("\r\nChecking for new versions"); Utils.g_controlledUIApp = application; Assembly mainAssembly = Assembly.GetExecutingAssembly(); Utils.g_mainAssemblyPath = mainAssembly.Location; m_revitAddinPath = Path.GetDirectoryName(Utils.g_mainAssemblyPath); string locPath = Utils.g_mainAssemblyPath; string Revit = string.Empty; if (m_revitAddinPath.Contains("2018")) { Revit = "2018"; } else if (m_revitAddinPath.Contains("2019")) { Revit = "2019"; } else if (m_revitAddinPath.Contains("2020")) { Revit = "2020"; } else if (m_revitAddinPath.Contains("2021")) { Revit = "2021"; } Utils.k_revitVersion = Revit; Metrics.AppendLog("Revit Version: " + Utils.k_revitVersion); string arcadisRepository = Path.Combine(Utils.k_repository, Utils.k_revitVersion); Metrics.AppendLog("Repository : " + arcadisRepository); MainUserPreferences up = MainUserPreferences.GetUserPreferences(); IList <string> modules = up.ToolModules; foreach (string assemblyName in modules) { string repoPath = Path.Combine(arcadisRepository, assemblyName); string revitPath = Path.Combine(m_revitAddinPath, assemblyName); string revitVersion = string.Empty; string repoVersion = string.Empty; try { revitVersion = FileVersionInfo.GetVersionInfo(revitPath).ProductVersion; } catch { revitVersion = "Not Found"; } try { repoVersion = FileVersionInfo.GetVersionInfo(repoPath).ProductVersion; } catch { repoVersion = "Not Found"; } AssemblyVersion module = new AssemblyVersion(); module.AssemblyName = assemblyName; module.CurrentVersion = revitVersion; module.RepositoryVersion = repoVersion; Utils.s_assemblies.Add(module); if (repoVersion != revitVersion) { newAssemblies.Add(module); } } if (newAssemblies.Count > 0) { VersionsForm form = new VersionsForm(); form.NewAssemblies = newAssemblies; form.RevitAddInPath = m_revitAddinPath; form.RepositoryPath = arcadisRepository; form.ShowDialog(); } //Create Arcadis Tabs //------------------- application.CreateRibbonTab(Utils.k_arcadisMainTab); ToolbarTab mainTab = AddTabs(Utils.k_arcadisMainTab, true); application.CreateRibbonTab(Utils.k_arcadisToolsTab); ToolbarTab toolsTab = AddTabs(Utils.k_arcadisToolsTab, false); // About Arcadis Tools Panel //-------------------------- RibbonPanel panel = application.CreateRibbonPanel(Utils.k_arcadisMainTab, Utils.k_arcadisPanel); ToolbarPanel toolPanel = new ToolbarPanel(panel.Name, panel, "ArcadisMain.dll"); mainTab.Panels.Add(toolPanel); string strCommand = "ArcadisMain.About_Command"; Bitmap bitmap = Properties.Resources.Info; Bitmap bitmapHelp = Properties.Resources.AboutHelp; string helpURL = "https://www.arcadis.com/en/global/"; ContextualHelp contextHelp = new ContextualHelp(ContextualHelpType.Url, helpURL); string longDesc = "Long help description for command button. Can include a long descriptive text with and an optional image."; Utils.CreateCommand(panel, toolPanel, "About Tools", "About Tools", locPath, strCommand, bitmap, "Information about Arcadis automation tools", bitmapHelp, longDesc, contextHelp); strCommand = "ArcadisMain.Settings_Command"; bitmap = Properties.Resources.settings; bitmapHelp = Properties.Resources.SettingsHelp; helpURL = "https://help.autodesk.com/view/RVT/2020/ENU/?guid=GUID-35DE66AB-6EF5-48C0-B477-F3B1B120F18A"; contextHelp = new ContextualHelp(ContextualHelpType.Url, helpURL); Utils.CreateCommand(panel, toolPanel, Utils.k_settings, Utils.k_settings, locPath, strCommand, bitmap, "Arcadis Toolbar Settings", bitmapHelp, longDesc, contextHelp); strCommand = "ArcadisMain.Ribbon_Command"; bitmap = Properties.Resources.Ribbon; bitmapHelp = Properties.Resources.MetricsHelp; Utils.CreateCommand(panel, toolPanel, "Ribbon Settings", "Ribbon Settings", locPath, strCommand, bitmap, "Select Tools for Ribbon", bitmapHelp, longDesc, contextHelp); strCommand = "ArcadisMain.Metrics_Command"; bitmap = Properties.Resources.BarChart2; bitmapHelp = Properties.Resources.MetricsHelp; Utils.CreateCommand(panel, toolPanel, "Metrics Tracker", "Metrics Tracker", locPath, strCommand, bitmap, "Display session Metrics Tracker Log", bitmapHelp, longDesc, contextHelp); foreach (string module in up.ToolModules) { //string addinPath = Path.Combine(Utils.g_mainAssemblyPath, module); //addinPath = m_revitAddinPath; string addinFile = Path.GetFileNameWithoutExtension(module) + ".addin"; string addinPath = Path.Combine(m_revitAddinPath, addinFile); try { Utils.LoadAddin(addinPath); } catch (Exception ex) { TaskDialog.Show("Exception MainApp L202", ex.Message); } } } catch (Exception ex) { Metrics.AppendLog("\r\nException: " + ex.Message); TaskDialog.Show("Exception", ex.Message); return(Result.Failed); } return(Result.Succeeded); }