×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Journal to export selected (multiple) bodies to temp part, and remove parameters

Journal to export selected (multiple) bodies to temp part, and remove parameters

Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
How can I modify this journal, to select multipe bodies to export to a temp part, as opposed it just selecting one body to export?

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 options as UFPart.ExportOptions
        With options
            .expression_mode = UFPart.ExportExpMode.CopyExpShallowly
            .new_part = True
            .params_mode = UFPart.ExportParamsMode.RemoveParams
        End With

    theUFSession.Part.ExportWithOptions("C:\temp\6118251.prt", 1, objects, options)

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 a body", _
            Selection.SelectionScope.AnyInAssembly, _
            Selection.SelectionAction.ClearAndEnableSpecific, _
            False, False, mask, obj, cursor)

        Return obj

    End Function

End Module 

Thanks in advance!

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

What version of NX? I ask because there were some changes to the selection functions around NX 8.

www.nxjournaling.com

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
It's for NX 8.5 cowski.

Thanks for your help

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

The following function will return an array of body objects. It isn't a direct replacement for the function that you have. You will need to make a few other changes in your code:
  • create an array variable of type "body" to hold the selected body object
  • pass this array into the selection function
  • extract the tag from each body into an array for input to the .ExportWithOptions method


CODE

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 

www.nxjournaling.com

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
Thanks , but I am still struggling with the other changes that are required, and where about to put them. :)

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

Warning: untested code ahead...

CODE

Option Strict Off
Imports System
Imports System.Collections.Generic
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
        If SelectBodies("select bodies", abody) = Selection.Response.Cancel Then
            Return
        End If

        Dim bodyTags As New List(Of Tag)

        For Each temp As Body In abody
            bodyTags.Add(temp.Tag)
        Next

        Dim options As UFPart.ExportOptions
        With options
            .expression_mode = UFPart.ExportExpMode.CopyExpShallowly
            .new_part = True
            .params_mode = UFPart.ExportParamsMode.RemoveParams
        End With

        theUFSession.Part.ExportWithOptions("C:\temp\6118251.prt", 1, bodyTags.ToArray, options)

    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 

www.nxjournaling.com

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
Again, thank you for your help. Im sure it is close to working now.
I currently get a "casting" runtime error:

CODE -->

Runtime error:
System.InvalidCastException: Unable to cast object of type 'NXOpen.TaggedObject[]' to type 'NXOpen.Body[]'.
   at NXJournal.Main() in C:\Users\tempuser\AppData\Local\Temp\NXJournals6524\journal.vb:line 15 

I am now googling to try and find out how to resolve the error..

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

Try this:

CODE

Option Strict Off
Imports System
Imports System.Collections.Generic
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 TaggedObject
        If SelectBodies("select bodies", abody) = Selection.Response.Cancel Then
            Return
        End If

        Dim bodyTags As New List(Of Tag)

        For Each temp As TaggedObject In abody
            bodyTags.Add(temp.Tag)
        Next

        Dim options As UFPart.ExportOptions
        With options
            .expression_mode = UFPart.ExportExpMode.CopyExpShallowly
            .new_part = True
            .params_mode = UFPart.ExportParamsMode.RemoveParams
        End With

        theUFSession.Part.ExportWithOptions("C:\temp\6118251.prt", 1, bodyTags.ToArray, options)

    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 

www.nxjournaling.com

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
Awesome work cowski!

It no longer throws errors.
However, when multiple bodies are selected, it only exports the first body selected, and fails to export the other bodies that were selected.

:)

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

Apparently, you have to tell the function how many items are in the array.

CODE

theUFSession.Part.ExportWithOptions("C:\temp\6118251.prt", bodyTags.Count, bodyTags.ToArray, options) 

www.nxjournaling.com

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
Understood, but is there any way around this cowski? Otherwise we would need to count the bodies that we want to export before running the journal?

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

I gave you the fix in the post above. Edit the listed line in the journal; the required change has been highlighted.

www.nxjournaling.com

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
Sorry cowski, what I was meaning, was that in order to run the journal I would need to count up all the bodies that I wish to export into the temp part before running the journal.
Then I would enter the number of bodies and run the journal (4 bodies for example below)

CODE -->

theUFSession.Part.ExportWithOptions("C:\temp\Exported.prt", 4, bodyTags.ToArray, options) 

Is there a way to do this without haveing to enter the exact number of bodies in the code before the journal is run?

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

Yes, I gave you the solution above. Find the "ExportWithOptions" line in the journal code timestamped: 15 Jul 15 14:53 and replace it with the new line posted at timestamp: 15 Jul 15 15:15.

Run the newly edited journal and it should work for any number of objects chosen.

www.nxjournaling.com

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

(OP)
Ahh, sorry for being a muppet! That works just great!
Thank you very much for your help and patience!

RE: Journal to export selected (multiple) bodies to temp part, and remove parameters

Glad you got it working!

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources