//////////////////////////////////////////////////////////////////////// // Eplan-OpenProjectFolder //////////////////////////////////////////////////////////////////////// // Erstellt am: 2023/Mar/16 // Erstellt von: Michael Ott // Geändert am: 2023/Mar/16 // Geändert von: Michael Ott //////////////////////////////////////////////////////////////////////// // Fügt die Funktion "Favoriten" - "Projekt" - "Projektordner" hinzu. // Diese Funktion erlaubt es, den Projektordner aus EPLAN // heraus zu öffnen. Wird diese Funktion bei einem Projekt das erste // Mal ausgeführt, so muss man den Projektordner auswählen. Anschließend // kann der Ordner im Explorer geöffnet werden. // Beim nächsten Ausführen wird der gespeicherte Ordnerpfad im Explorer // geöffnet. Wird der Pfad nicht gefunden, kann erneut ein Ordner // gewählt werden. // Die Funktion beschleunigt das Öffnen des Projektordners. //////////////////////////////////////////////////////////////////////// // Bekannte Probleme: // // //////////////////////////////////////////////////////////////////////// using System.Collections.Generic; using System.IO; using System.Text; using System.Xml; using System.Diagnostics; // using System.Linq; // using Eplan.EplApi.ApplicationFramework; // using Eplan.EplApi.Base; // using Eplan.EplApi.Scripting; public class OpenProjectFolder { // !!! hier musst Du m_TabName und m_commandGroupName anpassen, damit es zu Deinem Menüband passt string m_TabName = "Favoriten"; string m_commandGroupName = "Projekt"; string m_commandName = "Projektordner"; #region register menu item on load [DeclareRegister] public void registerRibbonItems() { var newTab = new Eplan.EplApi.Gui.RibbonBar().GetTab(m_TabName); var commandGroup = newTab.CommandGroups.FirstOrDefault(item => item.Name == m_commandGroupName); if (commandGroup == null) //CommandGroup noch nicht vorhanden, dann neu erzeugen { commandGroup = newTab.AddCommandGroup(m_commandGroupName); } commandGroup.AddCommand(m_commandName, "openProjFolder", m_commandName, "Öffnet den Projektordner auf dem Server"); } #endregion register menu item on load #region unregister menu item on unload [DeclareUnregister] public void unRegisterRibbonItems() { //Command entfernen var vTab = new Eplan.EplApi.Gui.RibbonBar().Tabs.FirstOrDefault(item => item.Name == m_TabName); if (vTab != null) { var commandGroup = vTab.CommandGroups.FirstOrDefault(item => item.Name == m_commandGroupName); if (commandGroup != null) { var command = commandGroup.Commands.Values.FirstOrDefault(item => item.Text == m_commandName); if (command != null) { command.Remove(); } //Wenn CommandGroup leer ist diese auch entfernen if (commandGroup.Commands.Count == 0) { commandGroup.Remove(); } } } } #endregion unregister menu item on unload private FolderBrowserDialog folderBrowserDialog1; [DeclareAction("openProjFolder")] //[Start] public void openProjectFolder() { string path = ""; try { path = (DatenLesen("10901","993").Substring(6)).Replace(";",""); } catch { path = ""; } if((path == "") || (!Directory.Exists(path))) { var setNewFolder = MessageBox.Show("Es wurde kein Projektordner angelegt oder der Projektordner existiert nicht. Möchten Sie einen neuen Projektordner festlegen?","Ordnerpfad ungültig",MessageBoxButtons.YesNo); if (setNewFolder != DialogResult.Yes) { return; } folderBrowserDialog1 = new FolderBrowserDialog(); // folderBrowserDialog1.SelectedPath = (@"\\sample\sample\sample\sample"); !!! hier kannst Du einen Pfad zur Ordnerauswahl vorbelegen und dann die Auskommentierung entfernen folderBrowserDialog1.ShowNewFolderButton = false; if (folderBrowserDialog1.ShowDialog() != DialogResult.OK) { return; } path = folderBrowserDialog1.SelectedPath; DatenSchreiben("10901","993",path); var openNewFolder = MessageBox.Show("Der Projektordner wurde festgelegt. Möchten Sie den Ordner jetzt öffnen?","Projektordner festgelegt",MessageBoxButtons.YesNo); if (openNewFolder != DialogResult.Yes) { return; } } Process.Start("explorer.exe",path); } public string DatenLesen(string id, string index) { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); string value = null; acc.AddParameter("PropertyId", id); acc.AddParameter("PropertyIndex", index); oCLI.Execute("XEsGetProjectPropertyAction", acc); acc.GetParameter("PropertyValue", ref value); return value; } public void DatenSchreiben(string id, string index, string propValue) { CommandLineInterpreter oCLI = new CommandLineInterpreter(); ActionCallingContext acc = new ActionCallingContext(); acc.AddParameter("PropertyId", id); acc.AddParameter("PropertyIndex", index); acc.AddParameter("PropertyValue", propValue); oCLI.Execute("XEsSetProjectPropertyAction", acc); } }