There are two ways to accomplish the rotation. First, because the imported step is added to a separate component, you can rotate the occurrence that represents that component. Second, you can do what you were trying to do and rotate the body in the component. Which one you choose would depend on what you'll be doing with the model and in many cases it probably doesn't matter. Here's some code that demonstrates both approaches, just change the if statement between True and False to get it to run the block of code for the type you want to see.
def importRotate(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
rootComp = design.rootComponent
################################## IMPORT THE CREATED STP FILE #####################################
# Get import manager
importManager = app.importManager
# Get step import options
fileName = "C:/Temp/SimpleBlock.step"
stpFileName = fileName
stpOptions = importManager.createSTEPImportOptions(stpFileName)
stpOptions.isViewFit = False
# Import step file to root component
result = importManager.importToTarget2(stpOptions, rootComp)
# Get the resulting occurrence.
occ = adsk.fusion.Occurrence.cast(result.item(0))
if False:
# Rotate the occurrence.
angle = math.pi * 0.25
mat = adsk.core.Matrix3D.create()
mat.setWithCoordinateSystem(adsk.core.Point3D.create(0,0,0),
adsk.core.Vector3D.create(math.cos(angle), math.sin(angle), 0),
adsk.core.Vector3D.create(math.cos(angle + (math.pi/2)), math.sin(angle + (math.pi/2)), 0),
adsk.core.Vector3D.create(0,0,1))
occ.transform = mat
else:
# Rotate the body.
bodyComp = occ.component
body = bodyComp.bRepBodies.item(0)
inputEnts = adsk.core.ObjectCollection.create()
inputEnts.add(body)
angle = math.pi * 0.25
mat = adsk.core.Matrix3D.create()
mat.setToRotation(angle, adsk.core.Vector3D.create(0,0,1), adsk.core.Point3D.create(0,0,0))
moveInput = bodyComp.features.moveFeatures.createInput(inputEnts, mat)
bodyComp.features.moveFeatures.add(moveInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com