using System; using System.IO; using NXOpen; using NXOpen.UF; using NX_Blech; public class Program { #region Version und Copyright // Version und Copyright string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); string copyright = "Copyright © 2018 by Eugen Höglinger"; //Assembly Datum und Zeit static DateTime value = AssemblyDateTime(); string date = value.ToShortDateString(); string time = value.ToLongTimeString(); private static DateTime AssemblyDateTime() { var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) return buildDateTime; } #endregion #region Programm-Info /// /// Contains the name of the program file /// public static string ProgramName { set; get; } /// /// Contains the version of the program file /// public static string ProgramVersion { set; get; } /// /// Contains the copyright notice /// public static string Copyright { set; get; } private void SetProgramInfo() { //Name, Version und Copyright setzen ProgramName = programName; ProgramVersion = programVersion; Copyright = copyright; } #endregion // class members private static Session theSession; private static UI theUI; private static UFSession theUfSession; public static Program theProgram; public static bool isDisposeCalled; //------------------------------------------------------------------------------ // Constructor //------------------------------------------------------------------------------ public Program() { SetProgramInfo(); //Stellt die Programm Info bereit try { theSession = Session.GetSession(); theUI = UI.GetUI(); theUfSession = UFSession.GetUFSession(); isDisposeCalled = false; } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- // UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message); } } public static bool FirstLoop { set; get; } //------------------------------------------------------------------------------ // Explicit Activation // This entry point is used to activate the application explicitly //------------------------------------------------------------------------------ public static int Main(string[] args) { FirstLoop = true; int retValue = 0; try { theProgram = new Program(); //TODO: Add your application code here var editExpression = new EditExpressions(); theProgram.Dispose(); } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- //Manche Parts erzeugen aus unerklärlichen Gründen beim ersten Durchlauf einen Fehler, in so einem Fall wird ein zweiter Durchlauf versucht. //Verursacht auch der zweite Durchlauf einen Fehler, dann ist die Aufgabe tatsächlich zu komplex und es wird eine Fehlermeldung ausgegeben. if (FirstLoop) { FirstLoop = false; //Wenn schon einmal durchgelaufen, dann setzen var editExpression = new EditExpressions(); } else { ShowComplexTaskMessage(); //Meldung ausgeben wenn die Aufgabe zu komplex ist. } } return retValue; } //------------------------------------------------------------------------------ // Following method disposes all the class members //------------------------------------------------------------------------------ public void Dispose() { try { if (isDisposeCalled == false) { //TODO: Add your application code here } isDisposeCalled = true; } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- } } public static int GetUnloadOption(string arg) { //Unloads the image explicitly, via an unload dialog //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly); //Unloads the image immediately after execution within NX // return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately); //Unloads the image when the NX session terminates return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination); } private static void ShowComplexTaskMessage() { if (theSession.GetEnvironmentVariableValue("UGII_LANG") == "german") { //deutsch NXOpen.UI.GetUI().NXMessageBox.Show("Warnung!", NXMessageBox.DialogType.Warning, "Die geforderte Aufgabe ist zu komplex.\nBitte lösen Sie die Aufgabe manuell.\nUnterstütztung erhalten Sie von ihrem Keyuser."); } else { //englisch NXOpen.UI.GetUI().NXMessageBox.Show("Warning!", NXMessageBox.DialogType.Warning, "The required task is too complex.\nPlease solve the task manually.\nYou will receive support from your keyuser."); } } }