- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to write a script that speeds up the process of making keyboard keycaps with legends sunk into the top.
I found another script on this forum that worked similarly and i modified it to loop through a list of characters, each time updating the sketch that the extrude was based on, and then exporting the object as an STL.
The script successfully iterates through the list, changes the text field, and exports the file with the correct name, however each file that it exports has the same letter extruded into the part.
It appears that the extrude feature is not updating after the sketch updates. I found some suggestions on the forums reccomending i roll back the timeline and back to the end to get it to update, but that didnt work.
the extrude feature displays an error: "1 Reference Failure. Cannot complete extrusion"
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
rootComp = design.rootComponent
# Get the sketch named "ChangeText"
sk = rootComp.sketches.itemByName('ChangeText')
# Get the first sketch text.
skText = sk.sketchTexts.item(0)
alphabet = ["A","B","C","D","E","F","G",'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
# Grab the sketch and first text entity
sk = rootComp.sketches.itemByName('ChangeText')
skText = sk.sketchTexts.item(0)
for i in alphabet:
# Change the text.
legend = i
skText.text = legend
# Write in the path to the folder where you want to save STL‘s
folder = r"X:\53.00 - 3d Printing\53.30 - Custom Models\Keycaps\Set 1.5\\"
# Construct the output filename. Name will be the same as you‘ve changed the text into.
filename = folder + skText.text + '.stl'
# Save the file as STL.
exportMgr = adsk.fusion.ExportManager.cast(design.exportManager)
stlOptions = exportMgr.createSTLExportOptions(rootComp)
stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementMedium
stlOptions.filename = filename
exportMgr.execute(stlOptions)
timeline = design.timeline
adsk.doEvents()
returnValue = timeline.moveToPreviousStep()
adsk.doEvents()
returnValue = timeline.moveToPreviousStep()
adsk.doEvents()
returnValue = timeline.moveToEnd()
adsk.doEvents()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.