From d819702522bbdbddf98f74b4b5e1d946c5b6caf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugen=20H=C3=B6glinger?= Date: Thu, 27 Feb 2020 15:07:57 +0100 Subject: [PATCH] Projekt neu angelegt. --- .gitignore | 32 ++++++ NX_Blech.sln | 23 ++++ NX_Blech/EditExpressions.cs | 209 ++++++++++++++++++++++++++++++++++++ NX_Blech/NX_Blech.csproj | 72 +++++++++++++ NX_Blech/Program.cs | 118 ++++++++++++++++++++ NX_Blech/ReadMe.txt | 103 ++++++++++++++++++ 6 files changed, 557 insertions(+) create mode 100644 .gitignore create mode 100644 NX_Blech.sln create mode 100644 NX_Blech/EditExpressions.cs create mode 100644 NX_Blech/NX_Blech.csproj create mode 100644 NX_Blech/Program.cs create mode 100644 NX_Blech/ReadMe.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a5f80a --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ + +#Ignore thumbnails created by Windows +Thumbs.db +#Ignore files built by Visual Studio +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.lib +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ +[Tt]est[Rr]esult* +.vs/ +#Nuget packages folder +packages/ diff --git a/NX_Blech.sln b/NX_Blech.sln new file mode 100644 index 0000000..27e6258 --- /dev/null +++ b/NX_Blech.sln @@ -0,0 +1,23 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.572 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NX_Blech", "NX_Blech\NX_Blech.csproj", "{8A8F353E-1761-446E-B11A-BDABD9A7851C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8A8F353E-1761-446E-B11A-BDABD9A7851C}.Debug|Any CPU.ActiveCfg = Debug|x64 + {8A8F353E-1761-446E-B11A-BDABD9A7851C}.Release|Any CPU.ActiveCfg = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {67E631DC-0741-4DF7-9EE9-F64BB165ADFA} + EndGlobalSection +EndGlobal diff --git a/NX_Blech/EditExpressions.cs b/NX_Blech/EditExpressions.cs new file mode 100644 index 0000000..ac9328d --- /dev/null +++ b/NX_Blech/EditExpressions.cs @@ -0,0 +1,209 @@ +using System; +using NXOpen; +using NXOpen.UF; + +namespace NX_Blech +{ + class EditExpressions + { + Session theSession = NXOpen.Session.GetSession(); + + public EditExpressions() + { + Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit_Expressions"); + theSession.SetUndoMarkName(markId1, "Edit_Expression"); + + if (Edit()) + { + theSession.DeleteUndoMark(markId1, "Edit_Expressions"); + } + } + + #region OwnMethodes + private bool Edit() + { + if (ThicknessValueExist()) + { + //Aktualisieren + CorrectExpressions(); + + return false; //Kein Abbruch + } + else + { + //Wenn 'Sheet_Metal_Material_Thickness' nicht existiert, dann eine Meldung ausgeben, dass zuerst die Funktion + //'Material Blechbearbeitung' ausgeführt werden muss, damit die notwendigen Expression Werte angelegt werden + NoThicknessMessage(); + + return true; //Abbruch + } + } + + private bool ThicknessValueExist() + { + bool thicknessValueExist = false; + + foreach (Expression name in theSession.Parts.Work.Expressions) + { + if (name.Name == "Sheet_Metal_Material_Thickness") + { + thicknessValueExist = true; + } + } + + return thicknessValueExist; + } + + private void CorrectExpressions() + { + //Korrektur wenn das Blech vor NX12 konstruiert wurde + //TODO: Abfrage ob notwendig + PreNX12Created(); + + //Werte setzen/aktualisieren + UpdateExpressions(); + } + + private void PreNX12Created() + { + //Korrektur wenn das Blech vor NX12 konstruiert wurde + foreach (Expression name in theSession.Parts.Work.Expressions) + { + //Existiert der Wert 't', dann den Wert 'Sheet_Metal_Relief_Depth' auf '0' setzen und den Wert 't' löschen + if (name.Name == "t") + { + SetReliefDepth(); //Den Wert Sheet_Metal_Relief_Depth auf 0 setzen + ChangeValue("t", "Sheet_Metal_Relief_Depth"); //Alle Expressions die den Wert 't' enthalten gegen den Wert 'Sheet_Metal_Relief_Depth' tauschen + DeleteExpression("t"); //Expression 't' löschen + } + + //Existiert der Wert 'b', dann den Wert 'Sheet_Metal_Relief_Width' abhängig vom Wert 'Sheet_Metal_Material_Thickness' auf '1' oder '2' setzen und den Wert 'b' löschen + if (name.Name == "b") + { + SetReliefWidth(); //Den Wert 'Sheet_Metal_Relief_Width' abhängig von der Materialstärke auf '1' oder '2' setzen + ChangeValue("b", "Sheet_Metal_Relief_Width"); //Alle Expressions die den Wert 'b' enthalten gegen den Wert 'Sheet_Metal_Relief_Width' tauschen + DeleteExpression("b"); //Expression 'b' löschen + } + } + } + + private void UpdateExpressions() + { + //Expression Werte importieren + ImportExpressionValues(); + + //Den Wert Sheet_Metal_Relief_Width setzen + SetReliefWidth(); + + //Den Wert Sheet_Metal_Relief_Depth setzen + SetReliefDepth(); + + //k-Faktor bei 10mm Blech von 0.28 auf 0.42 ändern + CorrectKFactor(); + } + + private void ImportExpressionValues() + { + //Dateiname der Blech-Expression-Tabelle + string sheetMetalExpressionValues = String.Concat(theSession.GetEnvironmentVariableValue("NX_SERVER_DIR"), "\\global\\06_ENGEL_NX_CUSTOMIZING\\Blech\\blech.exp"); + + //Expression Werte importieren + bool expModified; + string[] errorMessages = new string[50]; + theSession.Parts.Work.Expressions.ImportFromFile(sheetMetalExpressionValues, ExpressionCollection.ImportMode.Replace, out expModified, out errorMessages); + } + + private void SetReliefDepth() + { + //Den Wert Sheet_Metal_Relief_Depth auf 0 setzen + Expression expression = theSession.Parts.Work.Expressions.FindObject("Sheet_Metal_Relief_Depth"); + Unit unit = theSession.Parts.Work.UnitCollection.FindObject("MilliMeter"); + + theSession.Parts.Work.Expressions.EditWithUnits(expression, unit, "0"); + } + + private void SetReliefWidth() + { + //Den Wert Sheet_Metal_Relief_Width abhängig von der Materialstärke auf 1 oder 2 setzen + Expression expression = theSession.Parts.Work.Expressions.FindObject("Sheet_Metal_Relief_Width"); + Unit unit = theSession.Parts.Work.UnitCollection.FindObject("MilliMeter"); + + theSession.Parts.Work.Expressions.EditWithUnits(expression, unit, ReliefWidth()); + } + + private string ReliefWidth() + { + Expression thickness = theSession.Parts.Work.Expressions.FindObject("Sheet_Metal_Material_Thickness"); + + //Der Wert 'reliefWidth' ist abhängig von der Materialstärke + if (thickness.Value >= 6) + { + return "2"; + } + else + { + return "1"; + } + } + + private void CorrectKFactor() + { + foreach (Expression name in theSession.Parts.Work.Expressions) + { + if (name.Name == "Sheet_Metal_Material_Thickness") + { + Expression thickness = theSession.Parts.Work.Expressions.FindObject("Sheet_Metal_Material_Thickness"); + + if (thickness.Value == 10) + { + //Wenn die Blechdicke 10mm ist, dann den Wert 'Sheet_Metal_Neutral_Factor' von '0.28' auf '0.42' setzen + Expression expression = theSession.Parts.Work.Expressions.FindObject("Sheet_Metal_Neutral_Factor"); + Unit unit = theSession.Parts.Work.UnitCollection.FindObject("MilliMeter"); + string kFactor = "0.42"; + + theSession.Parts.Work.Expressions.EditWithUnits(expression, unit, kFactor); + } + } + } + } + + private void ChangeValue(string value, string newValue) + { + //Alle Expressions die den Wert 'value' enthalten gegen den Wert 'newValue' tauschen + foreach (Expression name in theSession.Parts.Work.Expressions) + { + if (name.RightHandSide == value) + { + Expression expression = theSession.Parts.Work.Expressions.FindObject(name.Name); + Unit unit = theSession.Parts.Work.UnitCollection.FindObject("MilliMeter"); + + theSession.Parts.Work.Expressions.EditWithUnits(expression, unit, newValue); + + } + } + } + + private void DeleteExpression(string value) + { + //Expression löschen + Expression expression = theSession.Parts.Work.Expressions.FindObject(value); + + theSession.Parts.Work.Expressions.Delete(expression); + } + + private void NoThicknessMessage() + { + if (theSession.GetEnvironmentVariableValue("UGII_LANG") == "german") + { + //deutsch + NXOpen.UI.GetUI().NXMessageBox.Show("Warnung!", NXMessageBox.DialogType.Warning, "Bitte zuerst die Funktion \"Material Blechbearbeitung\"\nund dann noch einmal \"ENGEL_Blechparameter\" ausführen!"); + } + else + { + //englisch + NXOpen.UI.GetUI().NXMessageBox.Show("Warning!", NXMessageBox.DialogType.Warning, "Please execute the function \"Material Blechbearbeitung\"\nfirst and then \"ENGEL_Blechparameter\" again!"); + } + } + #endregion + } +} diff --git a/NX_Blech/NX_Blech.csproj b/NX_Blech/NX_Blech.csproj new file mode 100644 index 0000000..9c9f7ae --- /dev/null +++ b/NX_Blech/NX_Blech.csproj @@ -0,0 +1,72 @@ + + + + Debug + x64 + Library + Properties + NX_Blech + $(PROJECT_NAME) + v4.6 + {8A8F353E-1761-446E-B11A-BDABD9A7851C} + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + False + $(UGII_BASE_DIR)\nxbin\managed\NXOpen.dll + False + + + False + $(UGII_BASE_DIR)\nxbin\managed\NXOpen.UF.dll + False + + + False + $(UGII_BASE_DIR)\nxbin\managed\NXOpen.Utilities.dll + False + + + False + $(UGII_BASE_DIR)\nxbin\managed\NXOpenUI.dll + False + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NX_Blech/Program.cs b/NX_Blech/Program.cs new file mode 100644 index 0000000..d2d27e5 --- /dev/null +++ b/NX_Blech/Program.cs @@ -0,0 +1,118 @@ +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."); + } + } +} + diff --git a/NX_Blech/ReadMe.txt b/NX_Blech/ReadMe.txt new file mode 100644 index 0000000..4ea71e6 --- /dev/null +++ b/NX_Blech/ReadMe.txt @@ -0,0 +1,103 @@ +======================================================================== + NX_OPEN : NX_Blech Project Overview +======================================================================== + +NX12 Open C# Wizard has created this NX_Blech project for you as a starting point. + +This file contains a summary of what you will find in each of the files that make up your project. + +NX_Blech.vbproj + This is the main project file for projects generated using an Application Wizard. + It contains information about the version of the product that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + + Executing User Exit Functions + ----------------------------- + + For execution of each user exit, corresponding Environment Variable need to be set with the full path + of the dll. + + The following environment variables are used to point to user exit executables. + Alternatively a single Environment Variable USER_DEFAULT can be set for all the Entry point. + +User Exit Environment Variable Entry Point + +Open Part USER_RETRIEVE ufget + +New Part USER_CREATE ufcre + +Save Part USER_FILE ufput + +Save Part As USER_SAVEAS ufsvas + +Import Part USER_MERGE ufmrg + +Execute GRIP Program USER_GRIP ufgrp + +Add Existing Part USER_RCOMP ufrcp + +Export Part USER_FCOMP uffcp + +Component Where-used USER_WHERE_USED ufusd + +Plot File USER_PLOT ufplt + +2D Analysis Using +Curves USER_AREAPROPCRV uf2da + +User Defined Symbols USER_UDSYMBOL ufuds + +Open CLSF USER_CLS_OPEN ufclso + +Save CLSF USER_CLS_SAVE ufclss + +Rename CLSF USER_CLS_RENAME ufclsr + +Generate CLF USER_CL_GEN ufclg + +Postprocess CLSF USER_POST ufpost + +Create Component USER_CCOMP ufccp + +Change Displayed Part USER_CDISP ufcdp + +Change Work Part USER_CWORK ufcwp + +Remove Component USER_DCOMP ufdcp + +Reposition Component USER_MCOMP ufmcp + +Substitute Component +Out USER_SCOMP1 ufscpo + +Substitute Component In USER_SCOMP2 ufscpi + +Open Spreadsheet USER_SPRD_OPN ufspop + +Close Spreadsheet USER_SPRD_CLO ufspcl + +Update Spreadsheet USER_SPRD_UPD ufspup + +Finish Updating +Spreadsheet USER_SPRD_UPF ufspuf + +Replace Reference Set USER_RRSET ufrrs + +Rename Component USER_NCOMP ufncp + +NX Startup USER_STARTUP ufsta + +Access Genius Library +Management System USER_GENIUS ufgen + +Execute Debug GRIP USER_GRIPDEBUG ufgrpd + +Execute User Function USER_UFUN ufufun + +Initialize new operation +Re-initialize an +existing operation USER_CREATE_OPER ufnopr + +CAM Startup USER_CAM_STARTUP ufcams +