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: 

Rendering with the API

1 REPLY 1
Reply
Message 1 of 2
Anonymous
897 Views, 1 Reply

Rendering with the API

I'm a beginner in Fusion360 and will like to know how to render object with the python API. In the below script I'm rotation the body of the root component and rendering all possible positions. This is part of the requirement the other part will be to Zoom(in/out) the objects. I'm currently exporting the object as an .STL file but will like to render the images as a JPEG. Will this be possible using the python API? Below is my code. Any help will be appreciated. 

import adsk.core, adsk.fusion, adsk.cam, traceback
import random 


def multipleRotations(iterAll=True, size=None):
    ui = None
    
    def get_cube_root(num):
        return num ** (1. / 3)
        
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComp = design.rootComponent
        folder = 'C:/Users/595241/Desktop/CAD/Airplanes/Airplanes_Renderings/'        
        exportMgr = adsk.fusion.ExportManager.cast(design.exportManager)
        body = rootComp.bRepBodies.item(0)#adsk.fusion.BRepBody.cast(ui.selectEntity('Select a body', 'Bodies').entity)
        
        if body:
            if iterAll:
                X = list(range(-360, 361))
                Y = list(range(-360, 361))
                Z = list(range(-360, 361))
            else:
                if size != None:
                    X = random.sample(range(-360, 360), int(get_cube_root(size)))
                    Y = random.sample(range(-360, 360), int(get_cube_root(size)))
                    Z = random.sample(range(-360, 360), int(get_cube_root(size)))
                    
            for x in X:
                for y in Y:
                    for z in Z:
                        trans = adsk.core.Matrix3D.create()
                        
                        rotX = adsk.core.Matrix3D.create()
                        rotX.setToRotation(x, adsk.core.Vector3D.create(1,0,0), adsk.core.Point3D.create(0,0,0))
                        trans.transformBy(rotX)
                        
                        rotY = adsk.core.Matrix3D.create()
                        rotY.setToRotation(y, adsk.core.Vector3D.create(0,1,0), adsk.core.Point3D.create(0,0,0))
                        trans.transformBy(rotY)
                        
                        rotZ = adsk.core.Matrix3D.create()
                        rotZ.setToRotation(z, adsk.core.Vector3D.create(0,0,1), adsk.core.Point3D.create(0,0,0))
                        trans.transformBy(rotZ)
                        
                        ents = adsk.core.ObjectCollection.create()
                        ents.add(body)
                        moveInput = rootComp.features.moveFeatures.createInput(ents, trans)
                        rootComp.features.moveFeatures.add(moveInput)
                        
                        filename = folder + 'Boeing737_' + 'x_' + str(x)+ '_' + 'y_' + str(y) + '_' + 'z_' + str(z) + '.stl'        
                        stlOptions = exportMgr.createSTLExportOptions(rootComp)
                        stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementMedium
                        stlOptions.filename = filename
                        exportMgr.execute(stlOptions)            
                        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    ui = None
    try:       
        multipleRotations(False, 11)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
1 REPLY 1
Message 2 of 2
marshaltu
in reply to: Anonymous

Hello,

 

You can probably refer to the following sample for how to save current view as image.

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-33127518-f20a-11e5-bab1-a0a8cd5c2c67

 

In addition, you should be able to zoom/rotate bodies by changing camera.

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2358aa1b-6965-4e46-b6af-d38e6e2f0f68

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report