Message 1 of 6
Not applicable
01-22-2021
12:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey there -
New to Fusion scripting, and I am 90% sure I am getting tangled up in object types, but thought this would be a good place to start.
I wrote a script already that imports a pile of DXF files separately. Now, what I would like to do is create a rectangle of fixed size around the *individual sketch* origin, not the origin of the entire project.
I am having 2 issues:
1) I can't create another point translated from the first for some reason
2) Trying to retrieve the origin of the sketch is proving to be difficult - I keep getting the global origin, *not* the origin on the sketch. I have a demo file attached, and code is below. Thanks for the help!
import traceback
import adsk.core
import adsk.fusion
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
cornerTrans = adsk.core.Vector3D.create(24, 24, 0)
# Get the sketch out of the root component of the active design.
rootComp = design.rootComponent
sketches = rootComp.sketches;
sketch = sketches[0]
wO = sketch.origin
xzPlane = rootComp.xZConstructionPlane
sketchNew = sketches.add(xzPlane)
sketchPoints = sketchNew.sketchPoints
lines = sketchNew.sketchCurves.sketchLines;
workOrigin = sketchPoints.add(wO)
rC = wO.translateBy(cornerTrans)
recCorner = sketchPoints.add(rC)
recLines = lines.addCenterPointRectangle(workOrigin, recCorner)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.