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:
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?
Solved! Go to Solution.
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:
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.
theUI = NXOpen.UI.GetUI()
myMsgBox = theUI.NXMessageBox
myMsgBox.Show("Test", NXOpen.NXMessageBox.DialogType.Information,"Hello World")
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")
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))