Print() problem

Print() problem

brad.bylls
Collaborator Collaborator
584 Views
1 Reply
Message 1 of 2

Print() problem

brad.bylls
Collaborator
Collaborator

Working on a script and having a problem.

 

app = adsk.core.Application.get()
        ui  = app.userInterface
        size=ui.inputBox('Screw size','SHCS','')

This creates an input dialog box.

I enter: 1/4

 

Later in the code I read a csv file:

        dlg = ui.createFileDialog()
        dlg.title = 'Open CSV File'
        dlg.filter = 'Comma Separated Values (*.csv);;All Files (*.*)'
        if dlg.showOpen() != adsk.core.DialogResults.DialogOK :
            return
        
        filename = dlg.filename
        f = open(filename, 'r')
        line = f.readline()
        data = []
        while line:
            pntStrArr = line.split(',')
            for pntStr in pntStrArr:
                data.append( str(pntStr))
        
            if len(data)>=5 :
                screw = data[0]
                string = (data[0], data[1], data[2], data[3], data[4])
#                if screw = size :
                print(size)
                print(screw)
                #input(string)
            line = f.readline()
            data.clear()

        f.close()          

The csv file contains lines:

1/4,.375,.5,.75,1/4

1/2,.625,.75,1.0,1/2

and so on.

 

The red lines:

print(size)     Prints:1/4

print(screw)  Prints: ['1/4', False]

 

If it is reading 1/4 from the file, why is it printing ['1/4', False] ?

 

 

Brad Bylls
0 Likes
Accepted solutions (1)
585 Views
1 Reply
Reply (1)
Message 2 of 2

ekinsb
Alumni
Alumni
Accepted solution

The inputBox method returns two values; the value the user entered and a boolean indicating if the dialog was canceled or not.  In Python this is returned as the single result which because there are two values is returned as a list.  You can see this in the documentation for the inputBox method (http://help.autodesk.com/view/NINVFUS/ENU/?guid=GUID-110bf712-8527-4ccd-a11d-f7266d69773e).

 

You should be doing something like this:

 

result = ui.inputBox('Screw size', 'SHCS', '')

# Check to see if the dialog was cancelled.
if result[1] == True:
    return
	
size = result[0]

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes