Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

NxOpen Batch error "The filename, directory name, or volume label syntax is incorrect." 1

Status
Not open for further replies.

Halasox

Civil/Environmental
Jun 5, 2016
16
0
0
US
Hi,

I am looking to import a part into my default template (not the blank) and then rotate it. The code works but when I run in batch it gives some error:
Code:
 [COLOR=#EF2929]The filename, directory name, or volume label syntax is incorrect.[/color]

The code creates the output and rotates the bodies as wanted, but I am not able to execute it on multiple files, like my other batch scripts. I am not sure why and hope for some help!

Code:
@echo off

C:\PROGRA~1\Siemens\NX2212\NXBIN\run_journal.exe <pathtoscript> -args %1

pause

Code:
 Option Strict Off
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Math 
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities

Module NXJournal

Public  theSession As NXOpen.Session = NXOpen.Session.GetSession()
Public  theUFSession As UFSession = UFSession.GetUFSession
Public  workPart As NXOpen.Part = theSession.Parts.Work
Public  displayPart As NXOpen.Part = theSession.Parts.Display
Public  LW As ListingWindow = theSession.ListingWindow
Public  templatePath As String = "mytemplatePath" 'Template path location

	
Sub Main(ByVal args() As String)

LW.Open()

Dim filePath As String = args(0)
'CreatePartFile(filePath)
'Dim strPath As String = theSession.Parts.Work.FullPath
'Dim fileName As String = IO.Path.GetFileName(filePath)
Dim fileNameNoExt As String = IO.Path.GetFileNameWithoutExtension(filePath)
Dim parentFolder As String = IO.Path.GetDirectoryName(filePath)
'fileName = fileName.Replace(".prt", "")
'lw.WriteLine(strPath)
'lw.WriteLine(fileNameNoExt)
'lw.WriteLine(fileName)
'lw.WriteLine(parentFolder)

' ----------------------------------------------
'   Create Part File
' ----------------------------------------------
Dim fileNew1 As NXOpen.FileNew = Nothing
fileNew1 = theSession.Parts.FileNew()
fileNew1.TemplateFileName = templatePath
fileNew1.UseBlankTemplate = False
fileNew1.ApplicationName = "ModelTemplate"
fileNew1.Units = NXOpen.Part.Units.Inches
fileNew1.RelationType = "master"
fileNew1.UsesMasterModel = "No"
fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
fileNew1.TemplatePresentationName = "Part"
fileNew1.ItemType = ""
fileNew1.Specialization = ""
fileNew1.SetCanCreateAltrep(False)
fileNew1.MasterFileName = ""
fileNew1.MakeDisplayedPart = True
fileNew1.DisplayPartOption = NXOpen.DisplayPartOption.AllowAdditional

Dim strFileName As String = parentFolder & "\" & fileNameNoExt & ".prt"
'lw.WriteLine(strFileName)
fileNew1.NewFileName = strFileName

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = fileNew1.Commit()

fileNew1.Destroy()

theSession.ApplicationSwitchImmediate("UG_APP_MODELING")
' ----------------------------------------------
'   Import Part File
' ----------------------------------------------
workPart = theSession.Parts.Work

Dim partImporter1 As PartImporter
partImporter1 = workPart.ImportManager.CreatePartImporter()

'change the following line to point to the part you want to import
partImporter1.FileName = args(0)
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = False
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work

Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)

partImporter1.DestinationCoordinateSystem = nXMatrix1

'set destination point to WCS origin
Dim destinationPoint1 As Point3d = workPart.WCS.Origin
partImporter1.DestinationPoint = destinationPoint1

'Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()

partImporter1.Destroy()

' ----------------------------------------------
'   Rotate Bodies 90d X-axis
' ----------------------------------------------
Dim bodies As BodyCollection = workpart.Bodies
Dim origin(2) As Double
origin(0) = 0.0
origin(1) = 0.0
origin(2) = 0.0

Dim direction(2) As Double
direction(0) = 1.0
direction(1) = 0.0
direction(2) = 0.0

Dim degreesRotation As Double = 90.0

Dim matrix(11) As Double
Dim status As Integer

For Each theBody As Body In bodies
    Dim objects As Tag() = new Tag(0){theBody.Tag}
    theUFSession.Trns.CreateRotationMatrix(origin, direction, degreesRotation, matrix, status)
    theUFSession.Trns.TransformObjects(matrix, objects, 1, 1, 0, 2, Nothing, Nothing, status) 
Next

' ----------------------------------------------
'   Save
' ----------------------------------------------
Dim partSaveStatus1 As PartSaveStatus
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()

lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

    'Unloads the image immediately after execution within NX
    GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

 
Replies continue below

Recommended for you

The journal works and the batch too! It's not a problem with running it or the path length, as I already figured that out, it's that the batch is only running on just one file. They way I am running my batch scripts is to select multiple files -> RMB -> send to -> select my batch shortcut (it's placed in the "send to" folder). That way I can run scripts much easier and quicker. However, the current code is just executing on a single file and stops and I am not sure why!

Code:
Option Strict Off
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Math 
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities

Module NXJournal

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim LW As ListingWindow = theSession.ListingWindow
Dim templatePath As String = "<TempPath>" 'Template path location

	
Sub Main(ByVal args() As String)

lw.Open()

Try
    'OpenPart(args(0))
    
    Catch ex As Exception
End Try

'Dim filePath As String = args(0)
'Dim OpenPart As String = "test"
Dim OpenPart As String = args(0)
'CreatePartFile(filePath)
'Dim strPath As String = theSession.Parts.Work.FullPath
'Dim fileName As String = IO.Path.GetFileName(filePath)
Dim fileNameNoExt As String = IO.Path.GetFileNameWithoutExtension(OpenPart)
Dim parentFolder As String = IO.Path.GetDirectoryName(OpenPart)
'fileName = fileName.Replace(".prt", "")
'lw.WriteLine(strPath)
'lw.WriteLine(fileNameNoExt)
'lw.WriteLine(fileName)
'lw.WriteLine(parentFolder)

' ----------------------------------------------
'   Create Part File
' ----------------------------------------------
Dim fileNew1 As NXOpen.FileNew = Nothing
fileNew1 = theSession.Parts.FileNew()
fileNew1.TemplateFileName = templatePath
fileNew1.UseBlankTemplate = False
fileNew1.ApplicationName = "ModelTemplate"
fileNew1.Units = NXOpen.Part.Units.Inches
fileNew1.RelationType = "master"
fileNew1.UsesMasterModel = "No"
fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
fileNew1.TemplatePresentationName = "Part"
fileNew1.ItemType = ""
fileNew1.Specialization = ""
fileNew1.SetCanCreateAltrep(False)
fileNew1.MasterFileName = ""
fileNew1.MakeDisplayedPart = True
fileNew1.DisplayPartOption = NXOpen.DisplayPartOption.AllowAdditional

Dim strFileName As String = parentFolder & "\" & fileNameNoExt & ".prt"
'lw.WriteLine(strFileName)
fileNew1.NewFileName = strFileName

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = fileNew1.Commit()

fileNew1.Destroy()

theSession.ApplicationSwitchImmediate("UG_APP_MODELING")
' ----------------------------------------------
'   Import Part File
' ----------------------------------------------
workPart = theSession.Parts.Work

Dim partImporter1 As PartImporter
partImporter1 = workPart.ImportManager.CreatePartImporter()

'change the following line to point to the part you want to import
partImporter1.FileName = OpenPart
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = False
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work

Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)

partImporter1.DestinationCoordinateSystem = nXMatrix1

'set destination point to WCS origin
Dim destinationPoint1 As Point3d = workPart.WCS.Origin
partImporter1.DestinationPoint = destinationPoint1

'Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()

partImporter1.Destroy()

' ----------------------------------------------
'   Rotate Bodies 90d X-axis
' ----------------------------------------------
Dim bodies As BodyCollection = workpart.Bodies
Dim origin(2) As Double
origin(0) = 0.0
origin(1) = 0.0
origin(2) = 0.0

Dim direction(2) As Double
direction(0) = 1.0
direction(1) = 0.0
direction(2) = 0.0

Dim degreesRotation As Double = 90.0

Dim matrix(11) As Double
Dim status As Integer

For Each theBody As Body In bodies
    Dim objects As Tag() = new Tag(0){theBody.Tag}
    theUFSession.Trns.CreateRotationMatrix(origin, direction, degreesRotation, matrix, status)
    theUFSession.Trns.TransformObjects(matrix, objects, 1, 1, 0, 2, Nothing, Nothing, status) 
Next

' ----------------------------------------------
'   Save
' ----------------------------------------------
Dim partSaveStatus1 As PartSaveStatus
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()

lw.Close()

End Sub

Sub OpenPart(byval thePart as string)
	Dim basePart1 As BasePart
	Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
	basePart1 = theSession.Parts.OpenBaseDisplay(thePart, partLoadStatus1)
 
	displayPart = theSession.Parts.Display
	partLoadStatus1.Dispose()
	theSession.Parts.SetWork(displayPart)
	workPart = theSession.Parts.Work
End Sub


Public Function GetUnloadOption(ByVal dummy As String) As Integer

    'Unloads the image immediately after execution within NX
    GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module
 
I suspect that all the selected file names are being passed into the "args()" array. However, your journal only process the first file passed, "args(0)". You'll need to add a loop to process each item in the array.

www.nxjournaling.com
 
I have tried to read each "args()" in array or by changing to "args(1)", but there is only one in array and not showing others. I noticed that all of my batch scripts not working anymore and they worked with "args(0)" on multiple selection. It would open for each part file a new terminal and process it. However, now it's not doing it anymore only one terminal opens. I don't know if this problem is due to some windows updates or NX recent update!

Update:
Just tried using the existing "ug_convert_part.exe" to convert units. Same thing it only works on a single file!
 
Hello,

Try this string join and place all inside a try to get a error msg.

Code:
Try

Dim filename As String = Strings.Join(args, " ")

Catch ex As Exception
Console.OpenStandardOutput()
Console.WriteLine(ex.ToString)
Console.WriteLine()
End Try



Gelson Z. Nicoletto
V.18-NX1980
 
Hello,

Have tired it and getting always same error!

Code:
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
Press any key to continue . . .

The journal would finalize the task, but only on a single part.
 
Try with echo "%1" and -args "%1"

Code:
@echo off

echo "%1"
C:\PROGRA~1\Siemens\NX2212\NXBIN\run_journal.exe <pathtoscript> -args "%1"

pause

Gelson Z. Nicoletto
V.18-NX1980
 
It would show the path of the file and run the code. The problem is that it opens only one terminal and not multiple for each part. It worked in the past, but now if I select multiple parts and run the batch it runs/opens only on one file.
 
Halasox said:
Have tired it and getting always same error!

Code:
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
Press any key to continue . . .

The journal would finalize the task, but only on a single part.

In this case the error is repeated 13 times. Did you select 14 files and send to -> your script? Did the first file complete successfully and the other 13 error out?

I think what gelsonnicoletto is getting at is: do any of the files have spaces in the name/path? If so, the script is splitting the input at the first space and getting confused because the result isn't a valid path. The "%1" that he suggests will wrap the file path in double quotes, fixing this issue.

www.nxjournaling.com
 
If you select multiple files, RMB and "Send To" your batch file, then you will have these arguments, %1 %2 %3 ... %9
if you selected more than nine arguments, to process all of them, you need to use the command SHIFT

This is an example batch file

Code:
@echo off

:Loop
IF A%1A==AA GOTO Continue
C:\PROGRA~1\Siemens\NX2212\NXBIN\run_journal.exe <pathtoscript> -args %1
SHIFT
GOTO Loop

:Continue
pause

If you want to pass all the selected files as one argument to your journal, than you need to use %*, like this

Code:
@echo off

C:\PROGRA~1\Siemens\NX2212\NXBIN\run_journal.exe <pathtoscript> -args %*

pause

If the path of the selected files contains spaces, the arguments will include quotes, like "C:\Temp Folder\Your file.prt"
you need to test if your journal will handle the quotes correctly

I hope this will be help you
 
apekas,

The first code solved it [bow]! I tested to export 30+ parts to step without issues [thumbsup2]. Appreciate your help and thank you all.



 
Status
Not open for further replies.
Back
Top