Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Passing arguments to NX Open python journal from Journal Manager

Status
Not open for further replies.

onodip

Aerospace
Oct 9, 2019
4
In the journal manager of NX it is possible enter arguments, which in principle can be passed to the journal.
In a Python journal typically a [tt]main[/tt] function is called. Since the function call is part of the script, I am not sure how NX can pass anything to it. Is there any special variable for the journal manager arguments that can be imported, or can it be somehow accessed from a Session or UFSession object?

I included a simple example, where I would like a message box to pop up with the arguments from the Journal Manager (see the attached picture).


Python:
import NXOpen
import NXOpen.UF

def main(arg):
    """Takes a string argument, and shows it in a message box."""
    uf_session = NXOpen.UF.UFSession.GetUFSession()
    message = "The following arguments were passed to my journal:" + arg
    uf_session.Ui.DisplayMessage(message, 1)
if __name__ == '__main__':
    main()  # Somehow the arguments of the journal manager should be passed

args_jw7gyp.png
 
Replies continue below

Recommended for you

Hello,

Try this:

Code:
import sys
import NXOpen
import NXOpen.UF


def main(arg):
    """Takes a string argument, and shows it in a message box."""
    uf_session = NXOpen.UF.UFSession.GetUFSession()
    message = "The following arguments were passed to my journal:" + arg
    uf_session.Ui.DisplayMessage(message, 1)
if __name__ == '__main__':

    main(sys.argv[0])

Gelson Z. Nicoletto
Eng. Supervisor
Mould Desing
Brazil
 
Thanks @gelsonnicoletto. For me [tt]sys.argv[0][/tt] is the filename, but works perfectly with [tt]sys.argv[1][/tt].

Python:
import sys
import NXOpen
import NXOpen.UF


def main(arg):
    """Takes a string argument, and shows it in a message box."""
    uf_session = NXOpen.UF.UFSession.GetUFSession()
    message = "The following arguments were passed to my journal:" + arg
    uf_session.Ui.DisplayMessage(message, 1)
if __name__ == '__main__':

    main(sys.argv[1])
 
So in NX 12 (and I guess later releases) [tt]sys.argv[0][/tt] is the filename and [tt]sys.argv[1][/tt] is the argument string, and in earlier versions [tt]sys.argv[0][/tt] is the argument string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor