nx_blech_relief_projects_vi.../blech.vb

193 lines
15 KiB
VB.net
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

' NX 12.0.2.9
' Journal created by 001142709 on Thu Apr 4 16:25:16 2019 Mitteleuropäische Sommerzeit
'
Imports System
Imports NXOpen
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
theSession.Preferences.Modeling.UpdatePending = False
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
theSession.SetUndoMarkName(markId1, "Expressions Dialog")
Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Edit Expression")
'---------- Anfang --- created by Eugen Hoeglinger 2019-04-10 ---
'Überprüfen ob die notwendigen Variablen existieren, wenn nicht, dann eine Fehlermeldung ausgeben
Dim ValueExist As Boolean
ValueExist = false
For Each name as Expression In workPart.Expressions
If name.Name = "Sheet_Metal_Material_Thickness" Then
ValueExist = true
End If
Next
If ValueExist = true Then
'--- Aktualisieren ---
'Dateiname der Blech-Expression-Tabelle
Dim SheetMetalExpressionsValue As String
SheetMetalExpressionsValue = theSession.GetEnvironmentVariableValue("NX_SERVER_DIR") + "\global\06_ENGEL_NX_CUSTOMIZING\Blech\blech.exp"
'Alle Expressions die den Wert 't' enthalten den Wert 't' gegen 'Sheet_Metal_Relief_Depth' tauschen
For Each expr10 As Expression In workPart.Expressions
If expr10.RightHandSide = "t" Then
Dim expression10 As NXOpen.Expression = CType(workPart.Expressions.FindObject(expr10.Name), NXOpen.Expression)
Dim unit10 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim value10 As String = "Sheet_Metal_Relief_Depth"
workPart.Expressions.EditWithUnits(expression10, unit10, value10)
End If
Next
'---Anfang--- Korrektur wenn das Blech vor NX12 konstruiert wurden
For Each name As Expression In workPart.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" Then
'Den Wert Sheet_Metal_Relief_Depth auf 0 setzen
Dim expression1 As NXOpen.Expression = CType(workPart.Expressions.FindObject("Sheet_Metal_Relief_Depth"), NXOpen.Expression)
Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
workPart.Expressions.EditWithUnits(expression1, unit1, "0")
Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Delete Expression")
Dim expression2 As NXOpen.Expression = CType(workPart.Expressions.FindObject("t"), NXOpen.Expression)
workPart.Expressions.Delete(expression2)
End If
Next
For Each name As Expression In workPart.Expressions
'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" Then
'Den Wert Sheet_Metal_Relief_Width setzen
Dim expression3 As NXOpen.Expression = CType(workPart.Expressions.FindObject("Sheet_Metal_Relief_Width"), NXOpen.Expression)
Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim value As String
Dim expression4 As NXOpen.Expression = CType(workPart.Expressions.FindObject("Sheet_Metal_Material_Thickness"), NXOpen.Expression)
If expression4.Value >= 6 Then
value = "2"
Else
value = "1"
End If
workPart.Expressions.EditWithUnits(expression3, unit1, value)
'Alle Expressions die den Wert 'b' enthalten den Wert 'b' gegen 'Sheet_Metal_Relief_Width' tauschen
For Each expr11 As Expression In workPart.Expressions
If expr11.RightHandSide = "b" Then
Dim expression11 As NXOpen.Expression = CType(workPart.Expressions.FindObject(expr11.Name), NXOpen.Expression)
Dim unit11 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim value11 As String = "Sheet_Metal_Relief_Width"
workPart.Expressions.EditWithUnits(expression11, unit11, value11)
End If
Next
Dim expression5 As NXOpen.Expression = CType(workPart.Expressions.FindObject("b"), NXOpen.Expression)
workPart.Expressions.Delete(expression5)
End If
Next
'---Ende---
'Werte setzen/aktualisieren
Dim expModified1 As Boolean
Dim errorMessages1() As String
workPart.Expressions.ImportFromFile(SheetMetalExpressionsValue, ExpressionCollection.ImportMode.Replace, expModified1, errorMessages1)
'Den Wert Sheet_Metal_Relief_Width setzen
Dim expression6 As NXOpen.Expression = CType(workPart.Expressions.FindObject("Sheet_Metal_Relief_Width"), NXOpen.Expression)
Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim relief_width As String
Dim expression7 As NXOpen.Expression = CType(workPart.Expressions.FindObject("Sheet_Metal_Material_Thickness"), NXOpen.Expression)
If expression7.Value >= 6 Then
relief_width = "2"
Else
relief_width = "1"
End If
workPart.Expressions.EditWithUnits(expression6, unit2, relief_width)
'Den Wert Sheet_Metal_Relief_Depth setzen
Dim expression8 As NXOpen.Expression = CType(workPart.Expressions.FindObject("Sheet_Metal_Relief_Depth"), NXOpen.Expression)
Dim unit3 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim relief_depth As String
relief_depth = "0"
workPart.Expressions.EditWithUnits(expression8, unit3, relief_depth)
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 ---
If theSession.GetEnvironmentVariableValue("UGII_LANG") = "german" Then
NXOpen.UI.GetUI().NXMessageBox.Show("Warnung!", NXMessageBox.DialogType.Warning, "Bitte zuerst die Funktion ""Material Blechbearbeitung""" + vbNewLine + "und dann noch einmal ""ENGEL_Blechparameter"" ausführen!")
Else
NXOpen.UI.GetUI().NXMessageBox.Show("Warning!", NXMessageBox.DialogType.Warning, "Please execute the function ""Material Blechbearbeitung""" + vbNewLine + "first and then ""ENGEL_Blechparameter"" again!")
End If
End If
'---------- Ende ---
Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "NX update")
Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId4)
theSession.DeleteUndoMark(markId4, "NX update")
Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Expressions")
theSession.DeleteUndoMark(markId5, Nothing)
Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Expressions")
Dim markId7 As NXOpen.Session.UndoMarkId = Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Make Up to Date")
Dim markId8 As NXOpen.Session.UndoMarkId = Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "NX update")
Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.DoUpdate(markId8)
theSession.DeleteUndoMark(markId8, "NX update")
theSession.DeleteUndoMark(markId7, Nothing)
theSession.DeleteUndoMark(markId6, Nothing)
theSession.SetUndoMarkName(markId1, "Expressions")
End Sub
End Module