- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
See my code below, if anyone can help it would be appreciated.
Like most here, I'm just starting down the Fusion 360 API coding path.
The .offset command is terribly documented. I've googled this, and read every possible answer.
I'm surprised there are not more examples of every possible API command. 😞
I am creating random squares, and for each one I need to create an offset (in or out, it doesn't matter) by some value such as 1mm.
In my particular scenario, I can easily just make a 2nd rectangle for each that is slightly smaller or larger but that seems like a cheat. I'd like be able to use the .offset() command as well to determine if it is the better way to go.
How can this be achieved. I am struggling with the first parameter, curves, and how to get them.
Thanks,
Alan
import adsk.core, adsk.fusion, traceback
import random
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Create a document.
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# Get the root component of the active design
rootComp = design.rootComponent
# Create a sketch
sketches = rootComp.sketches
sketch1 = sketches.add(rootComp.yZConstructionPlane)
print(sketch1.revisionId)
# Get sketch lines
sketchLines = sketch1.sketchCurves.sketchLines
mx = 100
my = 100
offset = 2
for i in range(0, 100, 10):
# Calculate the limits
x = random.randint(0,mx)
y = random.randint(0,my)
h = random.randint(20,mx-20)
w = random.randint(20,my-20)
# Create sketch rectangle
centerPoint = adsk.core.Point3D.create(x, y, 0)
cornerPoint = adsk.core.Point3D.create(x+h, y+w, 0)
sketch = sketchLines.addCenterPointRectangle(centerPoint, cornerPoint)
#create an offset here, but how?
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.