Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal to display directory of selected object 2

Status
Not open for further replies.

Fast4d

Aerospace
Mar 14, 2024
2
Hello,

I’m new to using journals in NX and eager to learn. Finally joined eng-tips and making my first post.

My first attempt at journaling is to create a journal to select an object from an assembly while in modeling and display the directory it’s currently loaded from.

Iv researched in eng-tips and found code which does it, however, it displays the directory of the work part, not of the component.

I do use information > Loaded Parts very often, however that brings up info for all the loaded parts. I’d like to be able to select the object, then get info.

Can someone help?
 
Replies continue below

Recommended for you

Here's a quick example. It prompts the user to select a component and reports the name, tag, and component file path.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF

Module Module220

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

    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        lw.Open()

        'prompt user to select component
        Dim selComponent As Assemblies.Component = Nothing
        If SelectComponent("select a component", selComponent) = Selection.Response.Cancel Then
            'user cancelled selection, end journal
            Return
        End If

        'user selected something, report the component name, tag, and part file path
        lw.WriteLine("selected component: " & selComponent.Name & ", tag: " & selComponent.Tag.ToString)
        lw.WriteLine("component part path: " & selComponent.Prototype.OwningPart.FullPath)
        lw.WriteLine("")

        lw.Close()

    End Sub

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

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a component"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_component_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt,
         title, scope, selAction,
         includeFeatures, keepHighlighted, selectionMask_array,
         selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function


End Module

www.nxjournaling.com
 
I think this journal could be very useful to me.
I've just tried it out, but a long path seems to fail.
what I mean is this.... I ran the journal in a large assembly, and the info window pops up, then I open a windows explorer,.... copy the path text, from the info window, paste, into the explorer top line, <enter>.
If the path is long, the explorer errors out, If the path is shorter, it works fine.
So there's nothing wrong with the journal, it must be the windows, window...

But if I have that same location open, in a window, and copy that path, from its top line, and paste THAT into another explorer window <enter>, it doesn't error.
Any idea why this happens??
Capture_jgtzps.jpg
 
@moog3,
That's a strange situation. How long is the file path? After running the journal, open notepad and paste the text in there; move your cursor to the end of the line (if necessary) and check the "column" number at the bottom of the notepad window. I think Windows 10 has a soft limit of 260 characters for compatibility reasons.

Also, while you have notepad open, copy the resulting text from notepad and paste it into windows explorer to see if that makes any difference. If it does, it might be a text encoding issue. Notepad defaults to UTF-8 encoding (shown in the bottom right corner), I'm not sure what encoding the NX information window uses.

www.nxjournaling.com
 
@cowski thank you so much! Worked perfect!
 
Cowski,
I've noticed what is doing it, (see image)
long_path_wyrdzr.jpg

when the NX window pops up, it puts the end of the path, on another line.
when I highlight the text, copy & paste into the explorer window, It only takes the first line, not the last bit on the second line.
I can fix it, by putting my cursor, at that point in the NX text window, and backspace, to put it back on one line, THEN copy THAT text.
would it be possible to format the NX window to write longer lines?
 
Unfortunately, it appears that the information window only allows journals to write 132 characters per line. Fortunately, there are several things we can do to circumvent that. The journal below copies the selected component file path to the clipboard so you can just paste it when needed. It also opens windows explorer to the part file. Pick the option that works for you and delete or comment out the others.

Windows tip: instead of pressing [kbd]Ctrl[/kbd] + [kbd]V[/kbd] to paste, use [kbd]Windows[/kbd] (Windows key) + [kbd]V[/kbd]. It will pull up a menu with several of the last things that you copied to the clipboard.



Code:
Option Strict Off
Imports System
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF

Module Module220

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

    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        lw.Open()

        'prompt user to select component
        Dim selComponent As Assemblies.Component = Nothing
        If SelectComponent("select a component", selComponent) = Selection.Response.Cancel Then
            'user cancelled selection, end journal
            Return
        End If

        'user selected something, report the component name, tag, and part file path
        lw.WriteLine("selected component: " & selComponent.Name & ", tag: " & selComponent.Tag.ToString)
        lw.WriteLine("component part path: " & selComponent.Prototype.OwningPart.FullPath)
        lw.WriteLine("")

        'Open Windows explorer to the file
        Process.Start("explorer.exe", "/select," & selComponent.Prototype.OwningPart.FullPath)

        'Copy the file path to the clipboard
        Clipboard.SetText(selComponent.Prototype.OwningPart.FullPath)

        lw.Close()

    End Sub

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

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a component"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_component_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt,
         title, scope, selAction,
         includeFeatures, keepHighlighted, selectionMask_array,
         selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function


End Module

www.nxjournaling.com
 
I think you are making things more complicated than needed.
Components are simple, the top assembly is more difficult. , It's three clicks...:)

If you want the directory for a component, -select that component and press Ctrl+i
the listing window will report the directory.

Regards,
Tomas





The more you know about a subject, the more you know how little you know about that subject.
 
Toost said:
I think you are making things more complicated than needed.

Writing a journal for this information may be overkill, but based on Fast4d's first post, I think this is intended as more of a learning experience rather than a practical tool.

www.nxjournaling.com
 
It's all great info guys', don't knock people for trying to help, or share knowledge.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor