Intro to API in Fusion 360 Part 7 - Creating a Script to Make a Sketch Profile #Fusion360 #API

preview_player
Показать описание
In this video we will continue to learn the Fusion 360 API using Python by creating a script that will make a 2020Aluminum extrusion profile that we can use for an extrude or sweep feature.

We will be covering the Object Model again as well as diving into some useful code like Arrays, For loops and If statements. The end result will be a script that will create a 2020 extrusion in a sketch currently being edited.

Here is the AL 2020 sketch used in the video. (note sometimes these don't work when they only contain sketches but you don't need it)

Here are some helpful links to the Fusion help file on API

And here are the chapters:
00:00 Intro
00:15 2020 Profile Review
04:31 Getting Started With A New Script
05:14 Reviewing the default Script
07:06 Writing a Script to Create a Sketch
22:18 Writing a Script to add Lines and Rectangles
31:32 Writing a Script to access to a current edit sketch
42:45 Writing a new Script to create a 2020 Extrusion Profile
01:21:44 Recap
Рекомендации по теме
Комментарии
Автор

This is what I was looking for! Thank you Matt, you're the best Fusion instructor by far! I just wish your channel gets the attention it deserves so you can continue this amazing work! Keep it up.

NabilBennaniKerrout
Автор

Great video again! This would be a nice start for a series called "making an frame generator add-in "😁 especially since there is no frame generator in Fusion 360 (at least not for mac). Consider the suggestion 😄

osvald
Автор

so practical thank you so much for the tutorial!

udjan
Автор

@24:28 you can write `sketch: adsk.fusion.Sketch = and you should continue getting autofill and tooltips on the sketch variable

edit: watched a few more minutes and you did exactly that lol

ryanpeterson
Автор

Love it awesome 🤩 work please make more of this nice content great work thanks man🤩

gold-junge
Автор

Thank you for the video..could you pls provide the API of FEA in Fusion 360

anilyasasvi
Автор

I made a few edits in the code. Is my code memory efficient:

#Author- Learn Everything About Design
#Description - Creating a profile using api

import adsk.core, adsk.fusion, adsk.cam, traceback
import math

def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design =
rootComp = design.rootComponent

if
ui.messageBox("A sketch must be active!!")
return

sketch =
sketchLines =
sketchCurves =
sketchCircles =

x_array = [0, 2.25/10, 5.5/10, 5.5/10, 3.1/10, 3.1/10, 8.5/10]
y_array = [3.1/10, 3.1/10, 6.35/10, 8.2/10, 8.2/10, 10/10, 10/10]
positive_array = list(zip(x_array, y_array))
mirrored_array = list(zip(y_array[::-1], x_array[::-1]))


for i in

## First block: 1st qdrt
start_point1 = adsk.core.Point3D.create(positive_array[i][0], positive_array[i][1], 0)
end_point1 = adsk.core.Point3D.create(positive_array[i+1][0], positive_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point1, end_point1)

start_point2 = adsk.core.Point3D.create(mirrored_array[i][0], mirrored_array[i][1], 0)
end_point2 = adsk.core.Point3D.create(mirrored_array[i+1][0], mirrored_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point2, end_point2)

### 2nd block:2nd qdrt

start_point1 = adsk.core.Point3D.create(positive_array[i][0], -positive_array[i][1], 0)
end_point1 = adsk.core.Point3D.create(positive_array[i+1][0], -positive_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point1, end_point1)

start_point2 = adsk.core.Point3D.create(mirrored_array[i][0], -mirrored_array[i][1], 0)
end_point2 = adsk.core.Point3D.create(mirrored_array[i+1][0], -mirrored_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point2, end_point2)

## 3rd block: 3rd qdrt

start_point1 = adsk.core.Point3D.create(-positive_array[i][0], -positive_array[i][1], 0)
end_point1 = adsk.core.Point3D.create(-positive_array[i+1][0], -positive_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point1, end_point1)

start_point2 = adsk.core.Point3D.create(-mirrored_array[i][0], -mirrored_array[i][1], 0)
end_point2 = adsk.core.Point3D.create(-mirrored_array[i+1][0], -mirrored_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point2, end_point2)

## 4th block: 4th qdrt

start_point1 = adsk.core.Point3D.create(-positive_array[i][0], positive_array[i][1], 0)
end_point1 = adsk.core.Point3D.create(-positive_array[i+1][0], positive_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point1, end_point1)

start_point2 = adsk.core.Point3D.create(-mirrored_array[i][0], mirrored_array[i][1], 0)
end_point2 = adsk.core.Point3D.create(-mirrored_array[i+1][0], mirrored_array[i+1][1], 0)
sketchLines.addByTwoPoints(start_point2, end_point2)


##1st arc
start_arc = adsk.core.Point3D.create(0.85, 1.0, 0)
centerPoint = adsk.core.Point3D.create(0.85, 0.85, 0)
arcstart = sketchCurves.addByCenterStartSweep(centerPoint,
start_arc, sweepAngle = -1.5708)

##2nd arc
start_arc = adsk.core.Point3D.create(1, -0.85, 0)
centerPoint = adsk.core.Point3D.create(0.85, -0.85, 0)
arcstart= sketchCurves.addByCenterStartSweep(centerPoint, start_arc,
sweepAngle=-1.5708)

##3rd arc
start_arc = adsk.core.Point3D.create(-1, -0.85, 0)
centerPoint = adsk.core.Point3D.create(-0.85, -0.85, 0)
arcstart= sketchCurves.addByCenterStartSweep(centerPoint, start_arc,
sweepAngle=1.5708)

##4th arc
start_arc = adsk.core.Point3D.create(-1, 0.85, 0)
centerPoint = adsk.core.Point3D.create(-0.85, 0.85, 0)
arcstart= sketchCurves.addByCenterStartSweep(centerPoint, start_arc,
sweepAngle=-1.5708)

### Making the circle at the center
sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), radius = 2.5/10)


# ui.messageBox('Hello script')

except:
if ui:

abhijitbhandari
Автор

You can also save a lot of boilerplate with createPoint = adsk.core.Point3D.create

ryanpeterson