Using Fusion (formerly Fusion 360) python scripting, I am trying to generate some orthographic and isometric views as .pngs given a .step file.
This is what I have so far (these are 2 of the 4 images generated):
I am having trouble with two things:
- Programmatically changing the RGB color and the roughness setting of this CAD object
- Programmatically turning off the shadows on the ground and near the edges and bends of the object
I have attempted to solve both of these by consulting the docs, as you will see in my script, to no avail. Any help or guidance would be much appreciated. Code is commented by AI for readability.
import adsk.core, adsk.fusion, adsk.cam, os, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
importManager = app.importManager
# Define file path and output directory
file_path = r'pathtostep.step'
output_folder = r'outputpath'
# Import the STEP file
stepOptions = importManager.createSTEPImportOptions(file_path)
rootComp = design.rootComponent
importManager.importToTarget(stepOptions, rootComp)
# Load a local material library and get an appearance
materialLibs = app.materialLibraries
matLib = materialLibs.load(r'pathtoAPISampleMaterialLibrary2.adsklib')
appear = matLib.appearances.itemByName("Steel - Satin") # Adjust appearance name as necessary
# Copy the appearance into the design
newAppear = design.appearances.addByCopy(appear, f'{appear.name}_Copied')
# Apply the appearance to all bodies
allBodies = rootComp.bRepBodies
for body in allBodies:
body.appearance = newAppear
# Setup camera
camera = app.activeViewport.camera
camera.cameraType = adsk.core.CameraTypes.OrthographicCameraType
# Define views
views = {
'Front': adsk.core.ViewOrientations.FrontViewOrientation,
'Top': adsk.core.ViewOrientations.TopViewOrientation,
'Right': adsk.core.ViewOrientations.RightViewOrientation,
'Iso': adsk.core.ViewOrientations.IsoTopRightViewOrientation
}
# Adjust scene settings for no specular reflections and no shadows
renderManager = design.renderManager
sceneSettings = renderManager.sceneSettings
sceneSettings.backgroundSolidColor = adsk.core.Color.create(255, 255, 255, 0) # White background
sceneSettings.ambientLightIntensity = 0.8
sceneSettings.reflectionsEnabled = False
sceneSettings.shadowsEnabled = False
# Process each view
for view_name, orientation in views.items():
camera.viewOrientation = orientation
app.activeViewport.camera = camera
app.activeViewport.refresh()
app.activeViewport.fit()
sceneSettings.shadowsEnabled = False
# Save images
image_path = os.path.join(output_folder, f"{view_name}_render.png")
app.activeViewport.saveAsImageFile(image_path, 384, 384)
except Exception as e:
if ui:
ui.messageBox('Failed:n{}'.format(traceback.format_exc()))