Help Exporting with a journal

Hello,

I am looking to write a journal to take an assembly and export every selected solid to a parasolid and name the files the component name of the solid. Below is my ideal workflow for the journal
1) Ask user what solids to export (including window selection)
2) Retrieve component name of each solid
3) Put names in a list (if name is already found skip solid and move on)
4) Export solid in parasolid format
5) Name parasolid the component name found in step 2.

I am new to journaling and I have been trying to alter the examples on this site to do what I am looking for. However, I can not figure out how to retrieve the component name and if you select multiple bodies with a window selection how can I write some code to work on each solid selected not export all solids into one file.

If anyone has any tips or suggestions I would greatly appreciate the help.

Thank you

It could use some polishing, but the code below will export the bodies separately.


[code]
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module2

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim tagList As New List(Of NXOpen.Tag)
Dim exportFolder As String
Dim theBodies As New List(Of Body)
Dim bodyNames As New List(Of String)

lw.Open()

exportFolder = IO.Path.GetDirectoryName(workPart.FullPath)

If SelectObjects("Select solid bodies", theBodies) = Selection.Response.Cancel Then
Return
End If

For Each obj As Body In theBodies
If obj.IsOccurrence Then
ExportParasolid(obj, IO.Path.Combine(exportFolder, obj.OwningComponent.DisplayName & ".x_t"))
Else
ExportParasolid(obj, IO.Path.Combine(exportFolder, obj.OwningPart.Leaf & ".x_t"))
End If
Next

lw.Close()

End Sub

Function SelectObjects(ByVal prompt As String, ByRef objList As List(Of Body)) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Selection"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)
If resp = Selection.Response.Ok Then
For Each tempObj As Body In selObj
objList.Add(tempObj)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Sub ExportParasolid(ByVal aBody As Body, ByVal fileName As String)

If My.Computer.FileSystem.FileExists(fileName) Then
Try
My.Computer.FileSystem.DeleteFile(fileName)
Catch ex As Exception
lw.WriteLine(ex.GetType.ToString & " : " & ex.Message)
Exit Sub
End Try
End If
'lw.WriteLine("Output file: " & fileName)

Dim tagList(0) As Tag
tagList(0) = aBody.Tag

ufs.Ps.ExportData(tagList, fileName)

End Sub

End Module
[/code]

This journal export each individual body as a parasolid. Is it possible to export all the selected bodies to one (1) parasolid?

Patrick Delisse
DutchAero

The code to do that can be found in the following article:
http://nxjournaling.com/content/export-parasolid

Thank you this did exactly what I was looking for.