Cancel
Showing results for 
Search instead for 
Did you mean: 

NXopen Python show message box in NX 10

Siemens Creator Siemens Creator
Siemens Creator

 

Hi I try to show a messagebox with NX python.

I was used to it in Java in and C# but in Python i get some problems:

This is my code:

 

NXOpen.NXMessageBox.Show("test",NXOpen.NXMessageBoxDialogType.Information,"Hello World")

 

 

TypeError: descriptor 'Show' requires a 'NXOpen.NXMessageBox' object but received a 'str'.

 

But why? what is the object. In the documentation there is only the method Show described which requires :

  • Show(title, msgboxType, message)

What is wrong in my call?

5 REPLIES

Re: NXopen Python show message box in NX 10

Siemens Phenom Siemens Phenom
Siemens Phenom

 

 

Good morning.  It is hard to tell from just one line of code what might be happening, although I don't see any obvious errors in that line.

 

There is an example program in the NX10 folders that uses this call, at:

 

...\UGOPEN\SampleNXOpenApplications\Python\Selection\Selection.Py

 

You might take a close look at the example and see if you can spot any differences in your program.  I tested the example, and it worked fine for me - it posted the message box several times successfully.

 

Re: NXopen Python show message box in NX 10

Siemens Phenom Siemens Phenom
Siemens Phenom

 

This worked:


    theUI = NXOpen.UI.GetUI()
    myMsgBox = theUI.NXMessageBox
    myMsgBox.Show("Test", NXOpen.NXMessageBox.DialogType.Information,"Hello World")

Re: NXopen Python show message box in NX 10

Siemens Phenom Siemens Phenom
Siemens Phenom

Your line of code is simply the name of the class (NXOpen.NXMessagebox), which is a string (str).

 

To call the Show method, you first need to instantiate an object of the NXMessageBox class from the NXOpen.UI object. The NXOpen.UI object in turn is instantiated from UI.GetUI:

 

theUI = NXOpen.UI.GetUI()
theNxMessageBox = theUI.NXMessageBox
theNxMessageBox.Show("test", NXOpen.NXMessageBox.DialogType.Information,"Hello World")

 

If you really want a single line of code, the following will work:

 

NXOpen.UI.GetUI().NXMessageBox.Show("test", NXOpen.NXMessageBox.DialogType.Information, "Hello World")

Re: NXopen Python show message box in NX 10

Siemens Creator Siemens Creator
Siemens Creator

Thank you that works

Re: NXopen Python show message box in NX 10

Genius
Genius

You can also use the listing window

 

import NXOpen.UF

self.theSession = NXOpen.Session.GetSession()
self.theLw = self.theSession.ListingWindow


#open console and print to it
self.theLw.Open()
self.theLw.WriteLine("Your variable  name is "+str(variable))