Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
The following python code is just for trying to learn the python script code for The Fusion 360 and does not produce any valuable output. However, does anybody know why the following code does not work and generates the error message below ?
#Author- #Description- import adsk.core, adsk.fusion, adsk.cam, traceback text='string' print(1,'=',text) def run(context): ui = None try: global text app = adsk.core.Application.get() ui = app.userInterface # ui.messageBox('Hello script') newProj = app.data.dataProjects.add('myNewProj') newFold = newProj.rootFolder.dataFolders.add('myNewFold') newDoc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType) # product = app.activeProduct # design = adsk.fusion.Design.cast(product) design = adsk.fusion.Design rootComp = design.rootComponent occ = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create()) occ.activate() newComp = occ.component newComp.name = 'Beam' sketches = newComp.sketches text='newstring' # print(2,'=',text) xyPlane = newComp.xYConstructionPlane sketch = sketches.add(xyPlane) sketch.name = 'FirstSketch' # xzPlane = rootComp.xZConstructionPlane # sketch = sketches.add(xzPlane) # sketch.name = 'SecondComponent' lines = sketch.sketchCurves.sketchLines lines1 = lines.addByTwoPoints(adsk.core.Point3D.create(0,0,0)\ ,adsk.core.Point3D.create(3,1,0)) lines2 = lines.addByTwoPoints(lines1.endSketchPoint\ ,adsk.core.Point3D.create(1,4,0)) lines.addByTwoPoints(lines2.endSketchPoint\ ,lines1.startSketchPoint) prof = sketch.profiles.item(0) triExt = newComp.features.extrudeFeatures\ .addSimple(prof,adsk.core.ValueInput.createByReal(50)\ ,adsk.fusion.FeatureOperations.NewBodyFeatureOperation) extBody = triExt.bodies.item(0) extBody.name = 'TriangleBeam' newDoc.saveAs('myDoc',newFold,'','') exportMgr = design.exportManager fusionExportOptions = exportMgr.\ createFusionArchiveExportOptions('D:/FusionData/CadTest') exportMgr.execute(fusionExportOptions) return text except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) #print('B',run('dummy_arg')) print(3,'=',text)
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
instead of
design = adsk.fusion.Design
(as in the current code)
the code works properly.
I thought that the .cast() just handles the "hints" and that the code would work properly without the .cast(), but perhaps my knowledge is still to poor.
Best Regards
Peter
Solved! Go to Solution.