nx_blech_projects_visualstudio/NX_Blech/Program.cs

119 lines
4.0 KiB
C#

using System;
using NXOpen;
using NXOpen.UF;
using NX_Blech;
public class Program
{
// 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()
{
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.");
}
}
}