Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Print() problem

1 REPLY 1
SOLVED
Reply
Message 1 of 2
brad.bylls
382 Views, 1 Reply

Print() problem

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
Tags (2)
1 REPLY 1
Message 2 of 2
ekinsb
in reply to: brad.bylls

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report