#Author- #Description-Will import .step/.stp file, and rotate it import adsk.core, adsk.fusion, adsk.cam, traceback, os.path, math def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface design = app.activeProduct rootComp = design.rootComponent ################################## IMPORT THE CREATED STP FILE ##################################### fileName = "SmallCube.step" # get the script location scriptDir = os.path.dirname(os.path.realpath(__file__)) fileLocnName = scriptDir + "/" + fileName # Get import manager importManager = app.importManager # Get step import options stpFileName = fileLocnName #+ ".stp" ###'C:\\APISampleImportNeutralStp.stp' stpOptions = importManager.createSTEPImportOptions(stpFileName) stpOptions.isViewFit = False # Import step file to root component importManager.importToTarget(stpOptions, rootComp) ################################## Rotate newly imported component ##################################### #get array of occurrences occurrences = rootComp.occurrences.asList #get first component occurrence_first = occurrences.item(0) # Get the current transform of the first occurrence transform = occurrence_first.transform transformStart = transform #### TranformBy method: #### # Create a transformation matrix rotZ= adsk.core.Matrix3D.create() # Create an input for the angle to transform by Transform_angle = math.pi/5 # Set the data of the transformation matrix rotZ.setToRotation(Transform_angle, adsk.core.Vector3D.create(0,0,1), adsk.core.Point3D.create(0,0,0)) # Change the occurence's transform data by rotating around Z+ axis (using the transformation matrix) transformNew = transformStart.transformBy(rotZ) # Create a collection of entities to move entities1 = adsk.core.ObjectCollection.create() # Addition recommended by goyals occs = rootComp.occurrences occ = occs[0] child_component = occ.component child_bodies = child_component.bRepBodies body = child_bodies[0] entities1.add(body) # Move the body moveInput = rootComp.features.moveFeatures.createInput(entities1, rotZ) ##can the second argument just be 'rotZ'? arg2:'transformNew' rootComp.features.moveFeatures.add(moveInput) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))