' Michael Knaupp Fa. Kramksi ' Programm ' Datum: ' Änderung:---- ' Option Strict Off Imports System Imports System.Collections Imports System.IO Imports System.Environment Imports System.Windows.Forms Imports NXOpen Imports NXOpen.UF Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Assemblies Module Kramski_Programm Sub Main Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Dim wP As Part = s.Parts.Work Dim dp As Part = s.Parts.Display ' Ein Teil geladen? if s.Parts.Work is Nothing Then Windows.Forms.MessageBox.Show("Kein Teil geladen! - No Part Loaded!") Exit Sub End If 'NX Manager Aktiv? Dim managerActive As Boolean ufs.UF.IsUgmanagerActive(managerActive) If managerActive = False Then Windows.Forms.MessageBox.Show("Diese Programm arbeitet nur unter Teamcenter / This programm is just for Teamcent Env") Exit Sub End If 'modulabfrage Dim module_id As Integer = 0 ufs.UF.AskApplicationModule(module_id) If module_id = UFConstants.UF_APP_DRAFTING Then Windows.Forms.MessageBox.Show("Bitte ins Modeling wechseln / Please change to modeling") Exit Sub End If if wP Is dp then lw.open() lw.WriteLine("Ueberpruefe ob Arbeitsteil gleich dargestelltes Teil ist - OK / Check Work Part is displayed Part - OK") else lw.open() lw.WriteLine("Arbeitsteil ist nicht Dargestelltes Teil! / Work Part is not displayed Part!") lw.WriteLine("Bitte aendern Sie dies / Please Change that") Exit Sub End if Dim partstring as String = "" Try Dim partnumber as String = wp.GetStringAttribute("DB_PART_NO") Dim partrev as String = wp.GetStringAttribute("DB_PART_REV") Dim partname as String = wp.GetStringAttribute("DB_PART_NAME") partstring = (partnumber + "/" + partrev + " Part Info: " + partname) Catch ex As Exception End Try ' Undo Mark setzten s.SetUndoMark( Session.MarkVisibility.Visible, "Kein Normteil") lw.open() lw.WriteLine("Start Programm " + CType(TimeOfDay(), String)) lw.WriteLine("") Dim databaseAttributeManager1 As PDM.DatabaseAttributeManager databaseAttributeManager1 = wP.PDMPart.NewDatabaseAttributeManager() Dim o as integer = 0 Dim obj as object Dim projattr(11) As String projattr(0) = "KR_PM_WERKSTOFF" projattr(1) = "KR_PM_NORMTEILNUMMER" projattr(2) = "KR_PM_ABMASSE" projattr(3) = "KR_PM_BESTELLNUMMER" projattr(4) = "KR_PM_LIEFERANT" projattr(5) = "KR_PM_ERSATZTEILKENNER" projattr(6) = "KR_PM_KENNER" projattr(7) = "KR_PM_SAP_NT_EK_NUMMER" projattr(8) = "KR_PM_SAP_NT_EK_NACHARBEIT" projattr(9) = "KR_PM_SAP_ROHMASS" projattr(10) = "KR_PM_FEDERVORSPANNUNG" projattr(11) = "KR_PM_FEDERENDSPANNUNG" Dim projattr_nx(10) As String projattr_nx(0) = "KR_PM_ROHMASS" projattr_nx(1) = "UM_STD_DIM" projattr_nx(2) = "UM_STD_OPT_DIM" projattr_nx(3) = "UM_STD_OPT_LAB" projattr_nx(4) = "UM_STD_SCALE_DIM" projattr_nx(5) = "UM_STD_SCALE_LAB" projattr_nx(6) = "UM_STD_OPT_EXTRA_DIM" projattr_nx(7) = "UM_STD_OPT_EXTRA_LAB" projattr_nx(8) = "UM_STD_SCALE_EXTRA_DIM" projattr_nx(9) = "UM_STD_SCALE_EXTRA_LAB" projattr_nx(10) = "UM_STANDARD_PART_ROOT" Dim wert as string ' Siko von Attributen erstellen wp.SetAttribute("KEIN_NORMTEIL","1") For o = 0 To (projattr.GetLength(0) - 1) Try wert = wp.GetStringAttribute(projattr(o)) wP.SetAttribute(("S_TC_" + projattr(o)), wert) Catch ex As Exception 'lw.WriteLine(projattr(o) + " / nicht gesetzt") End Try Next o For o = 0 To (projattr_nx.GetLength(0) - 1) Try wert = wp.GetStringAttribute(projattr_nx(o)) wP.SetAttribute(("S_NX_" + projattr_nx(o)), wert) Catch ex As Exception 'lw.WriteLine(projattr_nx(o) + " / nicht gesetzt") End Try Next o For o = 0 To (projattr.GetLength(0) - 1) Try ' Datenbankattribute Dim dbAttribManager(o+2) As PDM.DatabaseAttributeManager dbAttribManager(o+2) = wP.PDMPart.NewDatabaseAttributeManager() wert = wp.GetStringAttribute(projattr(o)) 'wP.SetAttribute(projattr(o), "") dbAttribManager(o+2).SetAttribute(projattr(o), " ") lw.WriteLine("Attribute : " + projattr(o) + " war: -->" + wert + "<-- wird geloescht") dbAttribManager(o+2).StoreAttributes() dbAttribManager(o+2).Dispose() Catch ex As Exception lw.WriteLine(projattr(o) + " / nicht gesetzt") End Try Next o 'dbAttribManager.StoreAttributes() 'dbAttribManager.Dispose() databaseAttributeManager1.Dispose() For o = 0 To (projattr_nx.GetLength(0) - 1) Try wert = wp.GetStringAttribute(projattr_nx(o)) wP.SetAttribute(projattr_nx(o), "") lw.WriteLine("Attribute : " + projattr_nx(o) + " war: -->" + wert + "<-- wird geloescht") Catch ex As Exception lw.WriteLine(projattr_nx(o) + " / nicht gesetzt") End Try Next o lw.WriteLine("") Try Dim partSaveStatus1 As PartSaveStatus partSaveStatus1 = wP.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False) partSaveStatus1.Dispose() lw.WriteLine("Speichere Arbeitsteil / Save work part: " + partstring) Catch ex As Exception lw.WriteLine("Kann Arbeitsteil nicht speichern / Can not save work Part: " + partstring) End Try lw.WriteLine("") lw.WriteLine("Ende Programm " + CType(TimeOfDay(), String)) End Sub ' Unload options Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately '----Other unload options------- 'Unloads the image when the NX session terminates 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination 'Unloads the image explicitly, via an unload dialog 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly '------------------------------- End Function End Module