-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHilbert.py
52 lines (48 loc) · 1.94 KB
/
Hilbert.py
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
import adsk.core, adsk.fusion, adsk.cam, traceback, math
from .simplelogo import SimpleLogo
app = adsk.core.Application.get()
if app:
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
sketches = rootComp.sketches
xyPlane = rootComp.xYConstructionPlane
def hilbert(logo, depth, turn, size):
if (depth == 0):
return
logo.right(turn)
hilbert(logo, depth - 1, -turn, size)
logo.forward(size)
logo.left(turn)
hilbert(logo, depth - 1, turn, size)
logo.forward(size)
hilbert(logo, depth - 1, turn, size)
logo.left(turn)
logo.forward(size)
hilbert(logo, depth - 1, -turn, size)
logo.right(turn)
def run(context):
try:
s = 0.6
sketch = sketches.add(xyPlane)
lines = sketch.sketchCurves.sketchLines
arcs = sketch.sketchCurves.sketchArcs
logo = SimpleLogo()
logo.lines = lines
logo.arcs = arcs
hilbert(logo, 4, 90, s)
sketch2 = sketches.add(rootComp.xYConstructionPlane)
lines2 = sketch2.sketchCurves.sketchLines
l1 = lines2.addByTwoPoints(adsk.core.Point3D.create(0, -s / 4, 0), adsk.core.Point3D.create(0, s / 4, 0))
l2 = lines2.addByTwoPoints(adsk.core.Point3D.create(0, s / 4, 0), adsk.core.Point3D.create(0, s / 4, s / 2))
l3 = lines2.addByTwoPoints(adsk.core.Point3D.create(0, s / 4, s / 2), adsk.core.Point3D.create(0, -s / 4, s / 2))
l4 = lines2.addByTwoPoints(adsk.core.Point3D.create(0, -s / 4, s / 2), adsk.core.Point3D.create(0, -s / 4, 0))
prof = sketch2.profiles.item(0)
path = rootComp.features.createPath(logo.paths)
sweeps = rootComp.features.sweepFeatures
sweepInput = sweeps.createInput(prof, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
sweep = sweeps.add(sweepInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))