Halasox
Civil/Environmental
- Jun 5, 2016
- 16
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:
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!
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