csv script

csv script

daniel_lyall
Mentor Mentor
5,180 Views
28 Replies
Message 1 of 29

csv script

daniel_lyall
Mentor
Mentor

is it possible at this time to create a script to take all parameters from a file, they will be user created parameters put it out as a csv file, then have a script to import the csv file and it put's the user parameter back in as user parameters or would it be easyer to put them back in as modle parameters.

 

this just a question at this time as this would be handy for doing cabint makeing. it is something I may try to do soon but I am not very good with codeing.


Win10 pro | 16 GB ram | 4 GB graphics Quadro K2200 | Intel(R) 8Xeon(R) CPU E5-1620 v3 @ 3.50GHz 3.50 GHz

Daniel Lyall
The Big Boss
Mach3 User
My Websight, Daniels Wheelchair Customisations.
Facebook | Twitter | LinkedIn

0 Likes
Accepted solutions (1)
5,181 Views
28 Replies
Replies (28)
Message 21 of 29

marshaltu
Autodesk
Autodesk
Hello,

It seemed that there were duplicate parameters in the file you shared. For example:
The first line:
d64_1,208 mm,mm,20.8,,Model,12mm finger tenions (3)

The 81st line:
d64_1,0.1,,0.1,,Model,12mm finger tenions (3)

I am not clear how you got the csv file? It seemed that it was not from the two models you shared to us.

In addition, I would like to get more information why you exported symbol "∞" instead of "deg" unit in the CSV file. You said it was from "Press Pull". Did you mean "Press Pull" command in Fusion 360? I cannot still reproduce that in my side. Could you please tell which OS you were working on and which region and language you were using?

Thanks,
Marshal


Marshal Tu
Fusion Developer
>
0 Likes
Message 22 of 29

daniel_lyall
Mentor
Mentor

it's a diffrent file it was the first to fail the other ones I posted where fine.

 

 these are from imported components 

d64_1,208 mm,mm,20.8,,Model,12mm finger tenions (3)

 

The 81st line: d64_1,0.1,,0.1,,Model,12mm finger tenions (3)

 

this  "∞" I dont know and yes press pull comand, windows 7, new zealand english


Win10 pro | 16 GB ram | 4 GB graphics Quadro K2200 | Intel(R) 8Xeon(R) CPU E5-1620 v3 @ 3.50GHz 3.50 GHz

Daniel Lyall
The Big Boss
Mach3 User
My Websight, Daniels Wheelchair Customisations.
Facebook | Twitter | LinkedIn

0 Likes
Message 23 of 29

daniel_lyall
Mentor
Mentor

@marshaltu give me an hour I will do a screen cast of all my settings and the paramaters of some sketches.


Win10 pro | 16 GB ram | 4 GB graphics Quadro K2200 | Intel(R) 8Xeon(R) CPU E5-1620 v3 @ 3.50GHz 3.50 GHz

Daniel Lyall
The Big Boss
Mach3 User
My Websight, Daniels Wheelchair Customisations.
Facebook | Twitter | LinkedIn

0 Likes
Message 24 of 29

marshaltu
Autodesk
Autodesk

Hello,

 

Thank you for your time. I have been able to reproduce the issue with systom format "English (Zimbabwe)" in Region and Language. I will investigate how we can fix the issue? The workaround for you would be to use the format "English (United States)".

 

In addition, I also find a potential bug in previous script I gave today. The method "insertParameter" would not work as expected for some case as below:

 

d1, d2 + 10 mm, mm, 3, , user

d2, d3 + 10 mm, mm, 2, , user

d3, 10 mm, mm, 1, , user

 

def insertParameter(param, allParams):
    allParams.append(param)
    dependentParams = param.dependentParameters
    for dependentParam in dependentParams:
        if dependentParam in allParams:
            allParams.remove(dependentParam)
            insertParameter(dependentParam, allParams)

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 25 of 29

daniel_lyall
Mentor
Mentor

@marshaltu I have reset the settings to defult and the deg thing is fixed here is the screen cast http://autode.sk/1QR9mdr.

 

the file that is bad is here http://a360.co/1NaBCRt, it has other problems with it now, it is just a play Model.

 

here is another file that fails its part of the one above http://a360.co/1N0VXtg this may be what is stuffing up the modle above.


Win10 pro | 16 GB ram | 4 GB graphics Quadro K2200 | Intel(R) 8Xeon(R) CPU E5-1620 v3 @ 3.50GHz 3.50 GHz

Daniel Lyall
The Big Boss
Mach3 User
My Websight, Daniels Wheelchair Customisations.
Facebook | Twitter | LinkedIn

0 Likes
Message 26 of 29

marshaltu
Autodesk
Autodesk

Hello,

 

Thank you for sharing dataset. There were two issues as below:

 

1. Duplicated parameters were found when dump to CSV file.

    It was because there was xref component in "book shelf" model. We allow parameters can be duplicated in two different designs. A quick fix would be not to export those parameters from external design to CSV file. The updated script is as below. Please let me know if you want them to be exported. Then I could modify script to support that. We have to make parameter name be unique in CSV file.

 

#Author-Brian Ekins
#Description-Dumps out parameter info to a specified csv file.

import adsk.core, adsk.fusion, traceback

def insertParameter(param, allParams):
    allParams.append(param)
    dependentParams = param.dependentParameters
    for dependentParam in dependentParams:
        if dependentParam in allParams:
            allParams.remove(dependentParam)
            insertParameter(dependentParam, allParams)

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        des = app.activeProduct
        
        if des.designType == adsk.fusion.DesignTypes.DirectDesignType:
            ui.messageBox('No parameters exists in the design.') 
            return
        
        # Get the name of the file to write to.
        fileDialog = ui.createFileDialog()
        fileDialog.isMultiSelectEnabled = False
        fileDialog.title = "Specify result filename"
        fileDialog.filter = 'CSV files (*.csv)'
        fileDialog.filterIndex = 0
        dialogResult = fileDialog.showSave()
        if dialogResult == adsk.core.DialogResults.DialogOK:
            filename = fileDialog.filename
        else:
            return

        # Get sorted parameter list according to dependencies
        allParams = []
        modelParamCompNames = {}
        for userParam in des.userParameters:
            insertParameter(userParam, allParams)
            
        for comp in des.allComponents:
            if comp.parentDesign == des:
                for modelParam in comp.modelParameters:
                    insertParameter(modelParam, allParams)
                    modelParamCompNames[modelParam.name] = comp.name

        result = 'Name,Expression,Units,Value (database units),Comment,Type,Component\n'
        
        # Get the data for all parameters.
        for param in allParams:
            compName = modelParamCompNames.get(param.name)
            if compName != None:
                result += (param.name + ',' + param.expression + ',' + param.unit + 
                           ',' + str(param.value) + ',' + param.comment + ',Model,' + compName + '\n')
            else:
                result += (param.name + ',' + param.expression + ',' + param.unit + ',' + 
                       str(param.value) + ',' + param.comment + ',User\n')

        output = open(filename, 'w')
        output.writelines(result)
        output.close()
        
        ui.messageBox('File written to "' + filename + '"')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

2. No parameters exist in direct modeling design. 

    The model "secret fingertrip" was the case. A friendly message should be prompted. I modified the script to do that.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 27 of 29

daniel_lyall
Mentor
Mentor

dude your the man it works good no crashing or anything so all good just one thing.

 

in the attached image the one on the left is from the model the second and 3rd column are the same units,

 

the one on the right the expression is correct, the value (what is the 4th column on the left pick) on the right it's cm not mm it should be mm as well I only work in mm or in so don't know why it is different, its no biggey.

 

last problem.jpg


Win10 pro | 16 GB ram | 4 GB graphics Quadro K2200 | Intel(R) 8Xeon(R) CPU E5-1620 v3 @ 3.50GHz 3.50 GHz

Daniel Lyall
The Big Boss
Mach3 User
My Websight, Daniels Wheelchair Customisations.
Facebook | Twitter | LinkedIn

0 Likes
Message 28 of 29

marshaltu
Autodesk
Autodesk
Accepted solution

Hello,

 

It was intended to make Parameter.value property be more useful for clients. Clients would not need to consider the conversion between two units(cm, mm, inch, feet etc) when they want to change the value. The parameter value is always calculate in database unit(e.g. cm). Clients could use "UnitManager.evaluateExpression(expression, units)" to evaluate the value in specific units.

 

The value in database units in CSV file would be changed to honor parameter unit when you import them to design.

 

Thanks,

Marshal

 

--------------------------------

Parent Object: Parameter

Description

"Gets and sets the real value (a double) of the parameter in database units. Setting this property will set/reset the expression value for this parameter

 

http://fusion360.autodesk.com/learning/learning.html?guid=GUID-A92A4B10-3781-4925-94C6-47DA85A4F65A



Marshal Tu
Fusion Developer
>
0 Likes
Message 29 of 29

daniel_lyall
Mentor
Mentor

thank you very much @marshaltu you have done a very good job, it all works fine so yer you the man.

 

with how I do the user parmaters now there are no problems at all with the import and dump, all the other one's I am going to be redoing them as thay are wrong and all fail at some point.

 

 


Win10 pro | 16 GB ram | 4 GB graphics Quadro K2200 | Intel(R) 8Xeon(R) CPU E5-1620 v3 @ 3.50GHz 3.50 GHz

Daniel Lyall
The Big Boss
Mach3 User
My Websight, Daniels Wheelchair Customisations.
Facebook | Twitter | LinkedIn

0 Likes