' NX 12.0.2.9
' Journal created by MANok on Sat Jun 8 13:15:54 2019 Środkowoeuropejski czas letni
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Math
Imports NXOpen.Features
Imports System.Collections.Generic
'Imports System.Windows.Forms
'Imports System.Reflection
Module Saver_as
Public theSession As NXOpen.Session = NXOpen.Session.GetSession()
Public workPart As NXOpen.Part = theSession.Parts.Work
Public displayPart As NXOpen.Part = theSession.Parts.Display
Public currentFile, currentPath As String
Public Length As String
Public check_save As Boolean = True
Public name_length As Integer
Public IsTcEng As Boolean
Sub Main(ByVal args() As String)
theSession.EnableRedo(False)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Change length and save")
Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")
'Check TC or native
Dim theUFS As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()
IsTcEng = False
theUFS.UF.IsUgmanagerActive(IsTcEng)
Dim nazwa As String
If IsTcEng Then
nazwa = workPart.GetStringAttribute("DB_PART_NO")
Else
currentPath = Path.GetDirectoryName(workPart.FullPath)
currentFile = Path.GetFileNameWithoutExtension(workPart.FullPath)
nazwa = currentFile
End If
Dim EndName As String
Dim FullEndName as String
EndName = NXInputBox.GetInputString("Podaj nazwę pliku", "Save... the Queen...", nazwa)
If IsTcEng = false then
FullEndName = currentPath & "\" & EndName
End if
Try
If IsTcEng Then
If check_save = True Then
Dim partOperationCopyBuilder1 As NXOpen.PDM.PartOperationCopyBuilder = Nothing
partOperationCopyBuilder1 = theSession.PdmSession.CreateCopyOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.SaveAs)
partOperationCopyBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCopyBuilder.OperationSubType.Default)
partOperationCopyBuilder1.DependentFilesToCopyOption = NXOpen.PDM.PartOperationCopyBuilder.CopyDependentFiles.All
partOperationCopyBuilder1.ReplaceAllComponentsInSession = True
partOperationCopyBuilder1.SetDialogOperation(NXOpen.PDM.PartOperationBuilder.OperationType.SaveAs)
partOperationCopyBuilder1.DefaultDestinationFolder = partOperationCopyBuilder1.DefaultDestinationFolder = ":Normalia:Modyfikowane"
Dim selectedparts3(0) As NXOpen.BasePart
selectedparts3(0) = workPart
Dim failedparts3() As NXOpen.BasePart
partOperationCopyBuilder1.SetSelectedPartsToCopy(selectedparts3, failedparts3)
Dim logicalobjects3() As NXOpen.PDM.LogicalObject
partOperationCopyBuilder1.CreateLogicalObjects(logicalobjects3)
Dim sourceobjects8() As NXOpen.NXObject
sourceobjects8 = logicalobjects3(0).GetUserAttributeSourceObjects()
Dim objects2(-1) As NXOpen.NXObject
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder = Nothing
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects2, NXOpen.AttributePropertiesBuilder.OperationType.None)
Dim objects3(0) As NXOpen.NXObject
objects3(0) = sourceobjects8(0)
attributePropertiesBuilder1.SetAttributeObjects(objects3)
attributePropertiesBuilder1.Title = "DB_PART_NO"
attributePropertiesBuilder1.Category = "Item"
attributePropertiesBuilder1.StringValue = EndName
Dim changed1 As Boolean = Nothing
changed1 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Title = "DB_PART_NAME"
Dim changed2 As Boolean = Nothing
changed2 = attributePropertiesBuilder1.CreateAttribute()
partOperationCopyBuilder1.ValidateLogicalObjectsToCommit()
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = partOperationCopyBuilder1.Commit()
partOperationCopyBuilder1.Destroy()
attributePropertiesBuilder1.Destroy()
End If
Else
If check_save = True Then
Dim partSaveStatus1 As NXOpen.PartSaveStatus = Nothing
partSaveStatus1 = workPart.SaveAs(FullEndName & ".prt")
partSaveStatus1.Dispose()
End If
End If
Catch ex As NXException
MsgBox("Dany plik istnieje w określonej lokalizacji, nie mnóż bytów")
theSession.UndoToMark(markId2, "Change length And save")
Catch e As Exception
theSession.UndoToMark(markId2, "Change length And save")
MsgBox(e.Message)
MsgBox(e.HResult)
End Try
End1:
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module