hanskellner / Fusion360ParaParam

Parametrically drive a user parameter in Autodesk Fusion 360

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When exporting .STL name and export bodies separately

beikeland opened this issue · comments

With export for 3d-printing in mind it would be beneficial to export multiple bodies or components into separate files, named accordingly.

My use case is to have a parameter clearance or something to that effect, and export say a snap fit case for electronics with 0.1 to 0.3mm clearance in 0.05mm steps. Currently a two piece part is exported as a single .stl file.

I've experimented a little and came up with something that works; I'll leave it here if anyone comes looking to do the same. (maybe one day I'll fork and polish it for 3d printing, picking bodies etc, but that day is not today:)

@@ -346,11 +346,23 @@ function run(context) {
                         break;

                     case PARAM_OPERATION.EXPORT_STL:
-                        var stlOptions = exportMgr.createSTLExportOptions(design.rootComponent, exportFilename+'.stl');
-                        //stlOptions.isBinaryFormat = true;
-                        //stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementHigh;
-                        resExport = exportMgr.execute(stlOptions);
-                        break;
+                    var bodies=design.rootComponent.bRepBodies;
+                    console.log("bodies: "+bodies)
+                    for (var iBodies=0; iBodies < bodies.count; iBodies++)
+                    {
+                      var body=bodies.item(iBodies);
+                      var name=body.name;
+                      console.log("body "+body);
+                      console.log("name "+name);
+                      exportFilename = exportFilenamePrefix + '_' + name + '_' + curParam.name + '_' + val; // TODO value to string
+                      var stlOptions = exportMgr.createSTLExportOptions(body, exportFilename+'.stl');
+                     //stlOptions.isBinaryFormat = true;
+                      //stlOptions.isBinaryFormat = true;
+                      //stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementHigh;
+                      resExport = exportMgr.execute(stlOptions);
+                    }
+                    break;
+
                 }
             }
             else { // Not a leaf node so iterate downward
commented

That's a nice modification. I'll take a look at adding a flag to support exporting a single or multiple as in what you've done.

Some sanity check on body names going into filename is probably a good idea.

Removing (or urlencoding) any of these could be a good start perhaps.

 "\"'´`<>()[]?*\,;:&%#$!"
commented

@beikeland Just updated the code to include your suggestion.