Using Current Path in a Macro
Using Current Path in a Macro
(OP)
I'm trying to create a macro (in NX5) to export a step file from a part file. When I manually export the step file, the current path and filename is automatically put in the export dialogue, but when I run a recorded macro, it inserts the path and filename of the file I wrote the macro with. Does anyone know if there is a "current_path" and/or "current_filename" type tag that I can use replace the string that gets recorded in the macro. I tried the "User Input on Dialog Boxes" option, but for some reason, it doesn't work when I open the save dialogue box in the export window.
Thanks
Thanks





RE: Using Current Path in a Macro
CODE
Function GetFileName()
Dim strPath as String
Dim strPart as String
Dim pos as Integer
'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)
strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)
GetFileName = strPart
End Function
'***********************************************************************
Function GetFilePath()
Dim strPath as String
Dim strPart as String
Dim pos as Integer
'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)
strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)
GetFilePath = strPath
End Function
'***********************************************************************
CODE
Dim currentFile as string
'full path and file name of current file
'currentFile = GetFilePath() & GetFileName() & ".prt"
'path of current file
currentPath = GetFilePath()
'file name (without '.prt') of current file
currentFile = GetFileName()
RE: Using Current Path in a Macro
RE: Using Current Path in a Macro
Have you tried using journaling? I know it can be done in NX6, it is worth a shot in NX5.
RE: Using Current Path in a Macro
RE: Using Current Path in a Macro
RE: Using Current Path in a Macro
CODE
'
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
The above code was generated simply by starting to record a journal then stopping the record operation. You can see it automatically creates some useful objects for you to use.
RE: Using Current Path in a Macro
RE: Using Current Path in a Macro
RE: Using Current Path in a Macro
RE: Using Current Path in a Macro
RE: Using Current Path in a Macro
CODE
' Journal created by adminuser on Mon Jul 12 14:52:17 2010 Central Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Function GetFilePath()
Dim strPath as String
Dim strPart as String
Dim pos as Integer
'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)
strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)
GetFilePath = strPath
End Function
Function GetFileName()
Dim strPath as String
Dim strPart as String
Dim pos as Integer
'get the full file path
strPath = displayPart.fullpath
'get the part file name
pos = InStrRev(strPath, "\")
strPart = Mid(strPath, pos + 1)
strPath = Left(strPath, pos)
'strip off the ".prt" extension
strPart = Left(strPart, Len(strPart) - 4)
GetFileName = strPart
End Function
Sub Main
For Each fileName As String In My.Computer.FileSystem.GetFiles("C:\Documents and Settings\adminuser\Desktop\CATIA_translated files - Node 2\n2_eclss")
Dim theSession As Session = Session.GetSession()
' ----------------------------------------------
' Menu: File->Open...
' ----------------------------------------------
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
basePart1 = theSession.Parts.OpenBaseDisplay(fileName, partLoadStatus1)
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
partLoadStatus1.Dispose()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Enter Gateway")
' ----------------------------------------------
' Menu: File->Save As...
' ---------------------------------------------
Dim partSaveStatus1 As PartSaveStatus
Dim fileSavepath As String = "C:\Documents and Settings\adminuser\Desktop\Node 2 STP\"
Dim currentFile As String = GetFileName()
partSaveStatus1 = workPart.SaveAs(fileSavePath & currentFile & ".stp" )
partSaveStatus1.Dispose()
' ----------------------------------------------
' Menu: File->Close->All Parts
' ----------------------------------------------
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
workPart = Nothing
displayPart = Nothing
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
Next
End Sub
End Module
RE: Using Current Path in a Macro
CODE
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Sub Main...
Alternately, you could declare displayPart in each of the functions that use it. This would avoid the use of global variables and their potential problems.