Batch rendering amd batch converting? with script

Batch rendering amd batch converting? with script

Anonymous
Not applicable
2,827 Views
11 Replies
Message 1 of 12

Batch rendering amd batch converting? with script

Anonymous
Not applicable

Is there a way to batch render and batch convert 3d cad models in fusion 3d with or without a script?

Is it possible to convert and render thousands of 3d models in an automated manner?

 

Thanks,

Arthur

0 Likes
2,828 Views
11 Replies
Replies (11)
Message 2 of 12

hutchij
Alumni
Alumni

Hi there,

 

We don't have that exposed formally through API, but we might be able to cobble this together. Some questions: 

 

- what file formats are you thinking? 

- render quality really depends on having good materials and lights, do you think these files will contain such data? 

- is the camera view you want to render defined in the file or an external parameter

- depending on quality and resolution, thousands of renderings could imply cost. The currency for rendering is cloud credits.  

 

John

0 Likes
Message 3 of 12

Anonymous
Not applicable

Any update on this thread?

0 Likes
Message 4 of 12

ekinsb
Alumni
Alumni

There are a couple of things that would be possible today using Fusion to do the rendering and possibly keep the entire process local.  But it depends on what the existing data is and what kind of results are needed.  For example, if the data exists in one of the formats that Fusion is able to locally translate (IGES, SAT, STEP, SMT, and f3d), then you can create a new file by importing that data locally.  This is the equivalent of the "New design from file" command in Fusion.  Once it's imported you can manipulate the view to get the desired orientation and save the rendered image to a file.  This uses the basic rendering in Fusion.  Unfortunately there is not currently API support for the Rendering workspace and the ray tracing it provides.

 

If the model data is in another format you can use the Fusion API to upload it to A360 where A360 will convert it to the Fusion format so it can be opened in Fusion.  The local renderer can then be used to render and save the image.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 12

Anonymous
Not applicable

thanks for the quick reply.  The locall rendering engine will suffice for now then.   I've seen an example or two for manipulating the camera but not on saving the rendered image.  Can you reference me to any examples?

0 Likes
Message 6 of 12

ekinsb
Alumni
Alumni

Here's a script that demonstrates changing the value of a parameter through a series of values and capturing an image of the view at each step to create the images that could be used as an animation.  There is a know propblem where the size of the image isn't the same as the view.  This will be fixed in an upcoming update.  What's there still works it just that the size is slight off.

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface        
        des = adsk.fusion.Design.cast(app.activeProduct)

        paramName = 'Length'
        startValue = 10
        endValue = 15
        increment = .1
        resultFolder = 'C:/Temp/Animate/'
        
        param = des.allParameters.itemByName(paramName)
        currentValue = startValue
        param.value = currentValue
        
        cnt = 0
        while param.value < endValue:
            param.value = currentValue
            currentValue += increment
            adsk.doEvents()
            filename = resultFolder + "frame" + str(cnt).zfill(4)
            app.activeViewport.saveAsImageFile(filename, 0, 0)                
            cnt += 1
            
        ui.messageBox('done')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 12

Anonymous
Not applicable

For my script I need to automate loading the CAD model (STEP file); however, my Fusion 360 script (python) crashes unless I manually open a STEP file first.

In this scenario, the script below runs but crashes with the error "Error: Autodesk Translation Services failed to translate the step file, please make sure the step file isn't corrupt!"

 

#Author-Ivan Walker
#Description-Automate the rendering task

import adsk.core, adsk.fusion, adsk.cam, traceback, math, time

app = None
ui = None


app = adsk.core.Application.get()
if app:
    ui  = app.userInterface

def run(context):
    ui = None
    try:
        user = app.userName
        ui  = app.userInterface

        #######################################################################
        # Load a STEP file
        #######################################################################
        # Get import manager
        importManager = app.importManager
        # Get active design
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        design = adsk.fusion.Design.cast(app.activeProduct)
        
        #move_camera(app, app.activeViewport)

        # Get root component
        rootComp = design.rootComponent
 #       rootComp.activateRootComponent()
        
        # Get step import options
        stpFileName = '/Volumes/Ivan' + '\'' + 's Spare Tire/Partpic/Parts DB/Part 1/91247A679.STEP'
        stpOptions = importManager.createSTEPImportOptions(stpFileName)
        
        # Import step file to root component
        importManager.importToTarget(stpOptions, rootComp)
        #######################################################################
        adsk.terminate()
0 Likes
Message 8 of 12

ekinsb
Alumni
Alumni

I just tested your program with a STEP file of my own and it worked as expected.  Is the filename being constructed correctly?  Are you also saying that your program works if you first manually open a STEP file or do you mean that you can manually open this STEP file but not from a program?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 9 of 12

Anonymous
Not applicable

If I manually open the STEP file first, then it works.  Doesn't matter if the file is closed after I open it or remains open.  Seems to initialize something that my script needs.

0 Likes
Message 10 of 12

ekinsb
Alumni
Alumni

I don't know what's happening.  I started Fusion fresh and without doing anything else ran your script and it successfully imported my STEP file.  Can you send me your STEP file just in case it is file specific?  You can either post it here or send it to [email protected]

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 11 of 12

Anonymous
Not applicable

STEP file attached.

0 Likes
Message 12 of 12

ekinsb
Alumni
Alumni

I still don't think I'm seeing the same problem you're having.  I did find something that caught me.  I was using the standard backslash as the folder delimiter, i.e. "C:\Temp\Test.STEP" and it was failing saying the file doesn't exist.  If I use forward slash, "C:/Temp/Test.STEP" or double backslash, "C:\\Temp\\Test.STEP", then it works ok.  Can you check the filename that you're building to see if that might be a problem.  Otherwise I'm not sure what else to try.


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