-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdate_Lens_Diam_Single.py
More file actions
64 lines (48 loc) · 2.45 KB
/
Update_Lens_Diam_Single.py
File metadata and controls
64 lines (48 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Luis Medina -
# Update the diameter of Lens Cap Holder and save each version as STL
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
defaultInputMinDiam = '35'
minLensDiam_Input = ui.inputBox('Input diameter in mm: ',
'Define minimum diameter', defaultInputMinDiam)
defaultInputMaxDiam = '80'
maxLensDiam_Input = ui.inputBox('Input diameter in mm: ',
'Define maximum diameter', defaultInputMaxDiam)
defaultInputWidth = '35'
StrapWidth_Input = ui.inputBox('Input width in mm: ',
'Define strap width', defaultInputWidth)
ui.messageBox(f'Input is = {StrapWidth_Input[0]}')
defaultInputFolder = r'C:\\'
folderInput = ui.inputBox('Input path to save folder: ',
'Define Save Folder', defaultInputFolder)
folder = folderInput[0]
diameters = list(range(int(minLensDiam_Input[0])-1,int(maxLensDiam_Input[0])+1,1))
# Get the root component of the active design
rootComp = design.rootComponent
# Get the parameters named "Length" and "Width" to change.
LensDiam_par = design.allParameters.itemByName('LensDiam')
StrapWidth_par = design.allParameters.itemByName('StrapWidth')
for dim in diameters:
Diam_set = dim
Width_set = StrapWidth_Input[0]
LensDiam_par.expression = str(Diam_set)
StrapWidth_par.expression = str(Width_set)
# Let the view have a chance to paint just so you can watch the progress.
adsk.doEvents()
# Construct the output filename.
filename = f'{folder}\LensCapHolder_D{Diam_set}mm_Strap_{Width_set}mm.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)
ui.messageBox('Finished.')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))