Export Part (modify Journal)

Hello,

I have a journal (*.vb) that exports the part to the OS-Filesystem from a managed NX session.

Everything works as it should. The only thing I would like to change is, that the user is able to select more than one solid in NX.
Right now, the export starts as soon as the user selects one solid.

Can anyone tell me how to modify that code to be able to select more than one solid?

I am a beginner with NXOpen :-)

Thanks!!

Regards,
Thomas

Here is the code:

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()

Dim abody As Body = SelectABody("Export")

Dim objects() as Tag = { abody.Tag }

Dim itemName as String = theSession.Parts.Work.GetUserAttribute("DB_PART_NAME", NXObject.AttributeType.String, -1).StringValue
Dim itemId as String = theSession.Parts.Work.GetUserAttribute("DB_PART_NO", NXObject.AttributeType.String, -1).StringValue
Dim itemId_Rev as String = theSession.Parts.Work.GetUserAttribute("DB_PART_REV", NXObject.AttributeType.String, -1).StringValue

Dim fileName as String = "C:\Temp" + itemId + "_" + itemId_Rev + "_" + itemName + ".prt"

theUFSession.Part.Export(fileName, 1, objects)

End Sub

Function SelectABody(ByVal prompt As String) As Body

Dim ui As UI = GetUI()
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_solid_type
.Subtype = UFConstants.UF_solid_body_subtype
.SolidBodySubtype = 0
End With
Dim obj As NXObject = Nothing
Dim cursor As Point3d = Nothing

ui.SelectionManager.SelectObject(prompt, "Select Body",
Selection.SelectionScope.AnyInAssembly,
Selection.SelectionAction.ClearAndEnableSpecific,
False, False, mask, obj, cursor)

Return obj

End Function

End Module

http://www.nxjournaling.com/content/using-mask-triples-selectobject-routine

The last code example in the link above shows how to use the .SelectObjects method. This will allow the user to select multiple objects.

Note that since that article was posted, the .SelectObject and .SelectObjects methods have been deprecated. The preferred methods are .SelectTaggedObject and .SelectTaggedObjects. The syntax is identical to the old versions, if my memory is correct.

One example of using the .SelectTaggedObjects method can be found here:
http://www.nxjournaling.com/comment/1585#comment-1585

A quick search of the site may turn up more.

Hi!

Thanks for your help!
I will have a look at these links!

Regards,
Thomas

Hello,

I tried to change the journal myself, but I am not able to get that right.
Since I am very new in programming and just start to learn VB, it will take a while I guess.
Would it be possible that someone changes the existing journal for me?

Thanks!

Regards,
Thomas

Try this version:

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI

Module Module145
Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow

lw.Open()
Dim theBodies() As TaggedObject = Nothing
If SelectBodies("select bodies for export", theBodies) = Selection.Response.Cancel Then
Return
End If

Dim bodyTags As New List(Of Tag)
For Each temp As TaggedObject In theBodies
bodyTags.Add(temp.Tag)
Next

Dim itemName As String = theSession.Parts.Work.GetUserAttribute("DB_PART_NAME", NXObject.AttributeType.String, -1).StringValue
Dim itemId As String = theSession.Parts.Work.GetUserAttribute("DB_PART_NO", NXObject.AttributeType.String, -1).StringValue
Dim itemId_Rev As String = theSession.Parts.Work.GetUserAttribute("DB_PART_REV", NXObject.AttributeType.String, -1).StringValue

Dim fileName As String = "C:\Temp\" + itemId + "_" + itemId_Rev + "_" + itemName + ".prt"
'lw.WriteLine("filename: " & fileName)
Try
theUFSession.Part.Export(fileName, bodyTags.Count, bodyTags.ToArray)

Catch ex As Exception
lw.WriteLine("error: " & ex.Message)
End Try

End Sub

Function SelectBodies(ByVal prompt As String, ByRef selObj() As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select one or more bodies"
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.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
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
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

End Module