Consecutive multiple stl export

Consecutive multiple stl export

Anonymous
Not applicable
1,382 Views
7 Replies
Message 1 of 8

Consecutive multiple stl export

Anonymous
Not applicable
Trying to automate the process which is possible via fusion 360 user interface, running in quite a few syntax problems, and other stuff which I don't know where to even begin troubleshoot. Hopping to get a piece of working code which I can tweak further. Thanks in advance.
 
Need a script, or addon (whatever takes lesser toll on the computer memory while not in use)
"Export bundle" 
 
In the f3d document there is 6 or more occurences, four of which are named. The other two or more will have a deffault name.
Names:
CompOne:1
CompTwo:1
CompThree:1
CompFour:1
Componnent 1:1
Componnent 2:1
,etc.
 
The prefix for exports in a unitless expression (12345) of the user parameter named "name_ID"
The script or add-on should be a button on the ribbon in the solid model workspace, promoted by default.
 
This is how i see the flow:
define exp_bundle()
{
nID=user parameter ('nameID')
eID=nID.expression
tID=str(eID)
Show open/save dialog
Populate save dialog with tID+'.txt'
dFile=dialog's filename with path and extension
pFile=filepath of (dFile)
fnFile=only the filename without the path or extension
pID=pFile + fnFile
 exp_f(pID)
 exp_m(pID)
 exp_s(pID)
 exp_g(pID)
if there are no errors then
Display mesage (fnFile + 'bundle has been saved')
}
define exp_f(pID)
{
#compose name
ena =(pID)
export fusion archive to (ena)
if export fails show message-box (ena + ' failed to export') # preferably without the path somehow
}
 
define exp_m(pID)
{
#compose name
ena =(pID+'_m.stl')
#turn on required objects
turn lightbulb on (CompTwo:1)
turn lightbulb on (CompThree:1)
#perform export
export root component (all visible) to stl (ena)
#turn off required objects
turn lightbulb off (CompTwo:1)
turn lightbulb off (CompThree:1)
if export fails show message-box (ena + ' failed to export') # preferably without the path somehow
}
 
define exp_s(pID)
{
#compose name
ena =(pID+'_s.stl')
#turn on required objects
turn lightbulb on (CompThree:1)
#perform export
export root component (all visible) to stl (ena)
#turn off required objects
turn lightbulb off (CompThree:1)
if export fails show message-box (ena + ' failed to export') # preferably without the path somehow
}
 
define exp_g(pID)
{
#compose name
ena =(pID+'_g.stl')
#isolate on required objects
isolate on (CompTwo:1)
#perform export
export root component (all visible) to stl (ena)
#unisolate required objects
turn lightbulb off (CompTwo:1)
if export fails show message-box (ena + ' failed to export') # preferably without the path somehow
}
 
When I tweaked some add-on code to do something like this I remember hiting following issues:
1. while f3d file saves locally and overrides if file with the same name exists, stl file will most certanly give me an error when trying to save on top of an existing file. 
My goal is to click this one button and export as is configuration and I would preffer override action by default.
 
2. when saving more then one stl consecutively most of the times I get an error while saving the second file. Maybe it need some delay or clear export-manager's buffer??
 
3. isolate script-step worked as expected, but un-isolate didnt, so at the completion of the script the picture in the ui dramatically changes with different stuff displaying. I would like it to work more like export progress kind of action, so after execution of the script or add-on the assembly to be in the same visibility and isolation states as at the beginning of the script, so the used can hit that export button all day long. 
 
Thanks Everyone 
Accepted solutions (1)
1,383 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Anyone?

Please help or at least stear me to the right direction.

 

Thank you!

0 Likes
Message 3 of 8

Shawn.Hice
Alumni
Alumni

Hello,

 

Saw this and thought I would give some feedback because I'm working on a similar addin.

 

Currently what I do is:

  1. Create a new workspace
  2. Add a toolbar to the workspace
  3. Add the buttons to the toolbar for the exporting command
  4. Buttons trigger a palette window which is html injected into a popup similar to the export command
  5. Then I find each subcomponent and computer a triangle mesh to store in my own binaries with json attributes for joints and such.

I'm not the very best at using the API but what you want to do seems very straightforward to me, I can help you get on the right track in terms of code but it would be nice If I can know a little more about the language preferences you have (Python/C++). An addin in my opinion would be better than a script because it reduces the work if you have to do this a lot by making it run on startup and automatically add the button. 

 

If I am understanding it correctly your best workflow works a little like this:

  1. Open Fusion
  2. Open Model
  3. Button for exporting in the modeling workspace (assuming you load the addin on start of application)
  4. Uses an export manager to assign names that are denoted as their component ID numbers
  5. Computes STL and saves it to the directory the local part is cached in / or opens file dialog to select a file.

Sorry for the late response I usually don't post on this forum a lot but hopefully we can help get going in the right direction.

0 Likes
Message 4 of 8

Anonymous
Not applicable
Oh, thank you for any response.
I prefer python.
Add in is good.
As I tried to explain earlier that i am working of the template which has
several known components (i would prefer to call them by (occurrence by
name) within a function, so if I add any in the future and change the order
of timeline, the Add-on should still find them. If any needed components
are missing Let it abort the add-on and show message.

I tried to do it all myself but it looks like stl export manager is pretty
picky about exporting (like if the file already exist in the destination it
is guaranteed to cause the error, this also applies to the ui).

I would not mind attaching timestamp to the name to make them unique, if
thats a only way to go.

Also I am purposely trying it on a slowest pc I have (with 4gb RAM), to
make sure that anyone who uses this rather simple plugin is not required to
have a monter pc.

When I did consecutive exports and Isolates not everything went as planned.
Maybe I need some delay or a refresh of some sort.

Thank you again!
0 Likes
Message 5 of 8

Shawn.Hice
Alumni
Alumni

Out of curiosity what was the result when you tried the consecutive export? (If it's a bug/unexpected behavior I can log it so that it might be better documented or maybe fixed in the future.)

 

What I would recommend in terms of having an issue with similar file names is creating a sub-directory with root component ID and then timestamp if it's accessible via a library and if the expected user is an administrator (not a school computer - if it is then there are other solutions such as making a GUID attributed name). I see now what you mean by occurrences within the timeline and that all makes sense to me.

 

Is the code open source or publicly listed on a repo somewhere?

 

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

The result would give me an error that line such and such could not run.

 Code got scraped and simplified to do only one export. Its not posted anywhere.
 Looking to write from a clean slate, do it as plan vs keep tweaking example codes possible making new problems.
0 Likes
Message 7 of 8

BrianEkins
Mentor
Mentor
Accepted solution

What you're trying to do should certainly be possible.  Here's what you can do to write out to an existing file.  Use Python file functions to check to see if the file already exists and if it does, delete it.  Then you can use the export function to write to that file.

import os.path

if os.path.isfile(fname):
    os.remove(fname)
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 8 of 8

Anonymous
Not applicable

Hi,

for now it looks like 

if os.path.isfile(cstl):

os.remove(cstl)

does the trick.

 

Can anyone test if 

occurence.isIsolated = True

then 

occurence.isIsolated = False

 

will do what is expected or is it a bug?

0 Likes