Showing results for 
Search instead for 
Do you mean 
Reply

inputs from dialog box

I'm trying to gather the inputs from a custom dialog box. What would be the proper methods for getting the integer value for a linear dimension and directory name from the dialog box?

 

Right now I am using .GetProperties() and GetInteger() at the very bottom. I also tried GetEnum() and GetString()

 

I get a "No overload matches these arguments error"

 def initialize_cb(self):
global numint
try:
# Template code to establish block object references
self.group0 = self.theDialog.TopBlock.FindBlock("group0")
#object selector
self.selection0 = self.theDialog.TopBlock.FindBlock("selection0")
#linear dimension
self.numinput = self.theDialog.TopBlock.FindBlock("linear_dim0")
#directory
self.directory = self.theDialog.TopBlock.FindBlock("nativeFolderBrowser0")
self.numinput = self.theDialog.TopBlock.FindBlock("linear_dim0")
#directory
self.directory = self.theDialog.TopBlock.FindBlock("nativeFolderBrowser0")

# Get the input string and establish an empty number string
numprops = self.numinput.GetProperties()

numint = numprops.GetInteger(numprops)
numprops.Dispose()
4 REPLIES

Re: inputs from dialog box

[ Edited ]

just tried running the code in the "GetBlockProperties" function and I get a "global numint" is not defined error.

    def GetBlockProperties(self, blockID):
        global numint
        try:
            numprops = initialize_cb.numinput.GetProperties()

            numint = numprops.GetInteger(numprops)
            numprops.Dispose()
            return numint, self.theDialog.GetBlockProperties(blockID)
        except Exception as ex:
            # ---- Enter your exception handling code here -----
            self.theUI.NXMessageBox.Show("Block Styler", NXOpen.NXMessageBox.DialogType.Error, str(ex))

        return numint #

 

Re: inputs from dialog box

If self.numinput  is a linear dimension block object, then self.numinput.Value() should return a double containing the dimension value in base units.

 

If self.directory is a nativeFolderBrowser block object, then self.directory.Path() should return a string containing the selected path.

 

See the examples delivered with the installation at:

%UGII_BASE_DIR%\UGOPEN\SampleNXOpenApplications\Python\BlockStyler

Re: inputs from dialog box

[ Edited ]

Here is my code. Hope it helps someone out there doing the same thing. I'm not sure why you need to call the .Dispose() method but I got errors when I did not include it.

 

    def initialize_cb(self):

        try:

            #input your length/width dimension
            self.input = self.theDialog.TopBlock.FindBlock("linear_dim0")
            #directory
            self.directory = self.theDialog.TopBlock.FindBlock("nativeFolderBrowser0")

        except Exception as ex:
            # ---- Enter your exception handling code here -----
            self.theUI.NXMessageBox.Show("Block Styler", NXOpen.NXMessageBox.DialogType.Error, str(ex))

    #------------------------------------------------------------------------------
    # Callback Name: dialogShown_cb
    # This callback is executed just before the dialog launch. Thus any value set
    # here will take precedence and dialog will be launched showing that value.
    #------------------------------------------------------------------------------
    def dialogShown_cb(self):
        try:
            # ---- Enter your callback code here -----
            pass
        except Exception as ex:
            # ---- Enter your exception handling code here -----
            self.theUI.NXMessageBox.Show("Block Styler", NXOpen.NXMessageBox.DialogType.Error, str(ex))


    #------------------------------------------------------------------------------
    # Callback Name: apply_cb
    #------------------------------------------------------------------------------
    def apply_cb(self):
        errorCode = 0

        try:
            # ---- Enter your callback code here -----
            global input_val, save_dir

            #getting values from the dialog box
            input_props = self.input.GetProperties()
            input_val = self.input.Value
            input_props.Dispose()
            input_props = None

            dir_props = self.directory.GetProperties()
            save_dir= self.directory.Path
            dir_props.Dispose()
            dir_props = None

            ##########calling functions here#############
            newinstance=MyClass()
            newinstance.method1()
            newinstance.method2(your_argument)
           
        except Exception as ex:
            # ---- Enter your exception handling code here -----
            errorCode = 1
            self.theUI.NXMessageBox.Show("Block Styler", NXOpen.NXMessageBox.DialogType.Error, str(ex))

        return errorCode

Re: inputs from dialog box

[ Edited ]

            #getting values from the dialog box
            input_props = self.input.GetProperties()
            input_val = self.input.Value
            input_props.Dispose()
            input_props = None

            dir_props = self.directory.GetProperties()
            save_dir= self.directory.Path
            dir_props.Dispose()
            dir_props = None

 

The lines of code in bold-italic are not necessary -- you can remove them.

In general, there are two ways to get properties from a dialog block:

(1) Use the GetProperties function, or

(2) Directly use the properties of the block

 

#1 is the old way. It has numerous disadvantages. #2 is the newer (and preferred) way.

Your code mixes the two methods.

 

 

山田
yamada