Step File Export Automation
Step File Export Automation
(OP)
I am trying to use journaling to automate the export of a step file from a part. Our company produces one-off products that are exported to a step file with objects on specific layers broken down like this:
Layer 1 - Solids
Layer 4 - Solids
Layer 5 - Solids
Layer 41 - Lines
Layer 44 - Points
Layer 63 - Solids
The objects on layers 5, 41, 44, and 63 all come from imported part files. These imported files also have components on other layer (21, 42, etc.)
Utilizing cowski's excellent nxjournaling.com resource I was able to write a journal that will prompt the user to select the objects with the necessary layers visible, and export a stp file. The problem I am having is that the stp file I create contains the objects on layers 21, 42, etc... even though they weren't selected. I assume this is because they are associated with the other components from the imported part files.
I thought I had solved this by exporting copies of the objects on layers 5, 41, 44, and 63 instead of the objects themselves. Unfortunately, I cannot make a copy of the points. When executing a journal that makes a copy of the points to layer 44, it returns an error "Smart Objects cannot be copied by layer copy".
So I'm a bit stuck and was hoping someone could help. I've included a sample of the code I am using
Again, thanks to cowski for the SelectObjects function info on nxjournaling.com
Layer 1 - Solids
Layer 4 - Solids
Layer 5 - Solids
Layer 41 - Lines
Layer 44 - Points
Layer 63 - Solids
The objects on layers 5, 41, 44, and 63 all come from imported part files. These imported files also have components on other layer (21, 42, etc.)
Utilizing cowski's excellent nxjournaling.com resource I was able to write a journal that will prompt the user to select the objects with the necessary layers visible, and export a stp file. The problem I am having is that the stp file I create contains the objects on layers 21, 42, etc... even though they weren't selected. I assume this is because they are associated with the other components from the imported part files.
I thought I had solved this by exporting copies of the objects on layers 5, 41, 44, and 63 instead of the objects themselves. Unfortunately, I cannot make a copy of the points. When executing a journal that makes a copy of the points to layer 44, it returns an error "Smart Objects cannot be copied by layer copy".
So I'm a bit stuck and was hoping someone could help. I've included a sample of the code I am using
CODE
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Sub Main
Dim mySelectedObjects as NXObject()
If SelectObjects("Hey, select multiple somethings", mySelectedObjects) = Selection.Response.Ok Then
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim step214Creator1 As Step214Creator
step214Creator1 = theSession.DexManager.CreateStep214Creator()
Dim added1 As Boolean
added1 = step214Creator1.ExportSelectionBlock.SelectionComp.Add(mySelectedObjects)
step214Creator1.OutputFile = "Random Directory Here"
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export to STEP214 Options")
step214Creator1.FileSaveFlag = False
step214Creator1.LayerMask = "*"
Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)
theSession.SetUndoMarkName(markId1, "Export to STEP214 Options")
step214Creator1.Destroy()
End if
End Sub
Function SelectObjects(prompt As String, _
ByRef selObj as NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Select Objects for STEP Export", _
Selection.SelectionScope.WorkPart, _
False, typeArray, selobj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
return Selection.Response.Cancel
End If
End Function
Imports System
Imports System.IO
Imports NXOpen
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Sub Main
Dim mySelectedObjects as NXObject()
If SelectObjects("Hey, select multiple somethings", mySelectedObjects) = Selection.Response.Ok Then
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim step214Creator1 As Step214Creator
step214Creator1 = theSession.DexManager.CreateStep214Creator()
Dim added1 As Boolean
added1 = step214Creator1.ExportSelectionBlock.SelectionComp.Add(mySelectedObjects)
step214Creator1.OutputFile = "Random Directory Here"
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Export to STEP214 Options")
step214Creator1.FileSaveFlag = False
step214Creator1.LayerMask = "*"
Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)
theSession.SetUndoMarkName(markId1, "Export to STEP214 Options")
step214Creator1.Destroy()
End if
End Sub
Function SelectObjects(prompt As String, _
ByRef selObj as NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Select Objects for STEP Export", _
Selection.SelectionScope.WorkPart, _
False, typeArray, selobj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
return Selection.Response.Cancel
End If
End Function
Again, thanks to cowski for the SelectObjects function info on nxjournaling.com





RE: Step File Export Automation
I'm not entirely clear if you are working in a single monolithic part file or an assembly file. You mention "imported parts", which makes me think of File -> Import Part... (single part file), but later mention components (assembly file).
If you are working in an assembly file, do you want to export just those objects from the assembly file or from each component file? For example, do you want to export all the solid bodies from layer 1 from just the assembly file or do you want to export all the solid bodies on layer 1 from the assembly file and each of the component files? Depending on how the component was added to the assembly, these options may have different results.
www.nxjournaling.com
RE: Step File Export Automation
Sorry for the confusion. We work with single part files and use the File -> Import Part function. There will never be any assembly file or components.
Again, sorry for the confusion.
RE: Step File Export Automation
Here is a journal that selects the objects according to your list. The SelectObjects function isn't used in this version, but I left it in the file in case you want to add some functionality to allow the user to pick additional objects. You'll probably want to change the output location. It currently outputs the STEP file based on the name and location of the work part.
CODE
'Layer 1 - Solids
'Layer 4 - Solids
'Layer 5 - Solids
'Layer 41 - Lines
'Layer 44 - Points
'Layer 63 - Solids
'eng-tips thread561-321704
'May 11, 2012
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Module Module1
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim mySelectedObjects As New List(Of NXObject)
Dim tempSelectedObjects() As NXObject
Dim step214File As String
Dim outputPath As String = IO.Path.GetDirectoryName(workPart.FullPath)
Dim outputFile As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)
outputFile = IO.Path.Combine(outputPath, outputFile & ".stp")
Dim STEP214UG_DIR As String = theSession.GetEnvironmentVariableValue("STEP214UG_DIR")
step214File = IO.Path.Combine(STEP214UG_DIR, "ugstep214.def")
If Not IO.File.Exists(step214File) Then
MsgBox("The step214 settings file (ugstep214.def) was not found." & vbCrLf & _
"This journal will now exit.", vbOKOnly + vbCritical)
Exit Sub
Else
'lw.WriteLine("STEP214 definition file found at: " & step214File)
End If
AddSolidsFromLayer(1, mySelectedObjects)
AddSolidsFromLayer(4, mySelectedObjects)
AddSolidsFromLayer(5, mySelectedObjects)
AddSolidsFromLayer(63, mySelectedObjects)
'add lines from layer 41
tempSelectedObjects = workPart.Layers.GetAllObjectsOnLayer(41)
For Each obj As NXObject In tempSelectedObjects
If TypeOf obj Is Line Then
mySelectedObjects.Add(obj)
End If
Next
'add points from layer 44
tempSelectedObjects = workPart.Layers.GetAllObjectsOnLayer(44)
For Each obj As NXObject In tempSelectedObjects
If TypeOf obj Is Point Then
mySelectedObjects.Add(obj)
End If
Next
'export to STEP214 file
Dim step214Creator1 As Step214Creator
step214Creator1 = theSession.DexManager.CreateStep214Creator()
step214Creator1.SettingsFile = step214File
step214Creator1.ObjectTypes.Solids = True
step214Creator1.LayerMask = "1-256"
step214Creator1.InputFile = workPart.FullPath
step214Creator1.OutputFile = outputFile
step214Creator1.FileSaveFlag = False
step214Creator1.ExportSelectionBlock.SelectionScope = ObjectSelector.Scope.SelectedObjects
Dim added1 As Boolean
added1 = step214Creator1.ExportSelectionBlock.SelectionComp.Add(mySelectedObjects.ToArray)
Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()
step214Creator1.Destroy()
lw.Close()
End Sub
Sub AddSolidsFromLayer(ByVal layer As Integer, ByRef objList As List(Of NXObject))
Dim tempselectedobjects() As NXObject
Dim tempSolidObj As Body
tempselectedobjects = workPart.Layers.GetAllObjectsOnLayer(layer)
'filter out the solid bodies on the layer and add them to the export list
For Each obj As NXObject In tempselectedobjects
If TypeOf obj Is Body Then
tempSolidObj = CType(obj, Body)
If tempSolidObj.IsSolidBody Then
objList.Add(tempSolidObj)
End If
End If
Next
End Sub
Function SelectObjects(ByVal prompt As String, _
ByRef selObj As NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Select Objects for STEP Export", _
Selection.SelectionScope.WorkPart, _
False, typeArray, selObj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.Ok Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
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
www.nxjournaling.com
RE: Step File Export Automation
I am still confused why the objects on layers 21 and 42 were being exported in my original code. It seems that the SelectObjects function works differently from the AddSolidsFromLayer function. Do you have any idea why?
Again, thank you so much. Your site is excellent. Perhaps if I get enough experience with this journaling I can one day submit something to it.
RE: Step File Export Automation
CODE -->
Thanks for the kind words, I'm glad you have found the website useful. I'm looking forward to getting some submitted journals to share!
www.nxjournaling.com