Skip to content

Latest commit

History

65 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

F360

These are a set of classes created with the goal of making it easier to work with the API of fuison 360. These classes simplify the code you have to write and reduce the complexity of the code by packing the formalities of Fusion's python API in wrapper classes

How to use the Classes

This section will educate you on the usage of the classes in Fusion 360.

Sketching

Let us begin with the most simple sketch: A SINGULAR LINE

The Line Class

start_point=adsk.core.Point3D.create(0, 0, 0)
end_point=adsk.core.Point3D.create(10, 0, 0)
xy_plane=app.activeProduct.rootComponent.xYConstructionPlaneline_drawer=LineDrawer(start_point, end_point, xy_plane)
line_drawer.create_line()

To explain the code: You simply define your start and end point, construction plane and create the LineDrawer class instance. After that you call the create_line function and you have a line on any plane you want. ⎹ Ekran Resmi 2023-11-29 18 06 24

The Circle Class

Let's look at how to create a circle with the circle class

app=adsk.core.Application.get()
ui=app.userInterfacedesign=app.activeProductrootComp=design.rootComponentxzPlane=rootComp.xZConstructionPlanecircle_creator=CircleCreator(adsk.core.Point3D.create(0, 0, 0), 2, xyPlane)
circle1=circle_creator.create_circle()

Here you have to define the application and ui(they aren't defined in the class). Then create a variable and assign the construction plane you want to use to it. After that you just have to define your point and radius and pass them into the class along with the plane the circle will be drawn on. ⃝

Ekran Resmi 2023-11-29 18 06 59

The Rectangle Class

app=adsk.core.Application.get()
ui=app.userInterfacecorner1=adsk.core.Point3D.create(0, 0, 0)
corner2=adsk.core.Point3D.create(10, 5, 0)
xy_plane=app.activeProduct.rootComponent.xYConstructionPlanerectangle_drawer=RectangleDrawer(corner1, corner2, xy_plane)
rectangle_drawer.draw_rectangle()

Here you have to define the application and ui(they aren't defined in the class). Then you have to define two points as you are drawing a two point rectangle also you define the plane you use then you pass them into the class. After that you just have to call the draw_rectangle function and you have a rectangle.▭

Ekran Resmi 2023-11-29 18 07 22

The Polygon Class

app=adsk.core.Application.get()
ui=app.userInterfacecenter_point=adsk.core.Point3D.create(0, 0, 0)
num_sides=6radius=3xy_plane=app.activeProduct.rootComponent.xYConstructionPlanepolygon_drawer=PolygonDrawer(center_point, num_sides, radius, xy_plane)
polygon_drawer.draw_polygon()

Here you have to define the application and ui(they aren't defined in the class). Then you have to define your side number, radius, plane and center point. After that you pass these into the class and then class the draw_polygon function and you have a polygon. ⬠

Ekran Resmi 2023-11-29 18 07 55

Three Point Arc

app=adsk.core.Application.get()
ui=app.userInterfacedesign=app.activeProductroot_comp=design.rootComponentxy_plane=root_comp.xYConstructionPlanearc_creator=ThreePointArcCreator(xy_plane)
point1=adsk.core.Point3D.create(0, 0, 0)
point2=adsk.core.Point3D.create(10, 0, 0)
point3=adsk.core.Point3D.create(10, 10, 0)
arc_creator.create_arc(point1, point2, point3)

Here you call/define app and ui also you get the design and root_comp after that you define the xy plane you then create an instance of the class and pass in the plane after that you call the create_arc function and pass in the points. After you've completed these steps you have a three point arc. ⌒

Ekran Resmi 2023-11-30 00 37 06

The ELlipse Class

importadsk.core, adsk.fusion, adsk.cam, tracebackclassEllipseDrawer:
def__init__(self, app):
self.app=appself.ui=app.userInterfaceself.design=app.activeProductself.rootComp=self.design.rootComponentdefdraw_ellipse(self, plane_name, center_x, center_y, major_axis_length, minor_axis_length):
ifplane_name.lower() =='xy':
plane=self.rootComp.xYConstructionPlaneelifplane_name.lower() =='xz':
plane=self.rootComp.xZConstructionPlaneelifplane_name.lower() =='yz':
plane=self.rootComp.yZConstructionPlaneelse:
self.ui.messageBox(f"Plane {plane_name} not recognized. Please use 'XY', 'XZ', or 'YZ'.")
returnsketches=self.rootComp.sketchessketch=sketches.add(plane)
center=adsk.core.Point3D.create(center_x, center_y, 0)
major_axis_point=adsk.core.Point3D.create(center_x+major_axis_length/2, center_y, 0)
# Calculate a point on the minor axisifplane_name.lower() =='xy'orplane_name.lower() =='xz':
minor_axis_point=adsk.core.Point3D.create(center_x, center_y+minor_axis_length/2, 0)
else: # 'YZ' planeminor_axis_point=adsk.core.Point3D.create(0, center_y+minor_axis_length/2, center_x)
sketch.sketchCurves.sketchEllipses.add(center, major_axis_point, minor_axis_point)
self.ui.messageBox(f'Ellipse drawn successfully on the {plane_name} plane!')

Features

Extrude

app=adsk.core.Application.get()
ui=app.userInterfacesketches=app.activeProduct.rootComponent.sketchesxy_plane=app.activeProduct.rootComponent.xYConstructionPlanesketch=sketches.add(xy_plane)
corner1=adsk.core.Point3D.create(0, 0, 0)
corner2=adsk.core.Point3D.create(10, 5, 0)
sketch.sketchCurves.sketchLines.addTwoPointRectangle(corner1, corner2)
rectangle_profile=sketch.profiles.item(0) extrude_creator=ExtrudeCreator(rectangle_profile, 5, 'NewBody')
extrude_creator.create_extrusion()

Firstly here you create a simple shape(here a rectangle). Then you put your profile the extrusion height and type into the class. After that you just called the creat extrusion function and now you have a 3D body.

Ekran Resmi 2023-12-07 07 24 55

Fillet

Constant Radius Fillet

Variable Radius Fillet

Chord Length Fillet

Loft

defrun(context):
try:
app=adsk.core.Application.get()
lofter=Lofter(app)
defsketch_square1(sketch):
lines=sketch.sketchCurves.sketchLinesp1=adsk.core.Point3D.create(-2.5, 2.5, 0)
p2=adsk.core.Point3D.create(2.5, 2.5, 0)
p3=adsk.core.Point3D.create(2.5, -2.5, 0)
p4=adsk.core.Point3D.create(-2.5, -2.5, 0)
lines.addByTwoPoints(p1, p2)
lines.addByTwoPoints(p2, p3)
lines.addByTwoPoints(p3, p4)
lines.addByTwoPoints(p4, p1)
xyPlane=lofter.rootComp.xYConstructionPlanelofter.add_profile(xyPlane, sketch_square1)
defsketch_square2(sketch):
lines=sketch.sketchCurves.sketchLinesp1=adsk.core.Point3D.create(-1.5, 1.5, 0)
p2=adsk.core.Point3D.create(1.5, 1.5, 0)
p3=adsk.core.Point3D.create(1.5, -1.5, 0)
p4=adsk.core.Point3D.create(-1.5, -1.5, 0)
lines.addByTwoPoints(p1, p2)
lines.addByTwoPoints(p2, p3)
lines.addByTwoPoints(p3, p4)
lines.addByTwoPoints(p4, p1)
offsetPlaneInput=lofter.rootComp.constructionPlanes.createInput()
offsetDistance=adsk.core.ValueInput.createByReal(10.0)
offsetPlaneInput.setByOffset(xyPlane, offsetDistance)
offsetPlane=lofter.rootComp.constructionPlanes.add(offsetPlaneInput)
lofter.add_profile(offsetPlane, sketch_square2)
lofter.create_loft()
except:
iflofter.ui:
lofter.ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Ekran Resmi 2024-03-28 14 46 19

Chamfer

defrun(context):
try:
app=adsk.core.Application.get()
chamfer_creator=ChamferCreator(app)
# Find the first solid body in the root component to demonstrate chamfering its edgesrootComp=chamfer_creator.design.rootComponentbodies=rootComp.bRepBodiesifbodies.count>0:
body=bodies.item(0)
edges=body.edgesifedges.count>=2:
# Attempt to chamfer the first two edges of the bodychamfer_edges= [edges.item(0), edges.item(1)]
chamfer_distance=0.5# Specify the chamfer distancechamfer_creator.create_chamfer(chamfer_edges, chamfer_distance)
else:
chamfer_creator.ui.messageBox('Not enough edges to create a chamfer.')
else:
chamfer_creator.ui.messageBox('No solid bodies found in the root component.')
except:
ifchamfer_creator.ui:
chamfer_creator.ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Ekran Resmi 2024-03-28 16 02 41

Offset

defrun(context):
try:
app=adsk.core.Application.get()
offset_creator=OffsetCreator(app)
xyPlane=offset_creator.rootComp.xYConstructionPlanesketch=offset_creator.rootComp.sketches.add(xyPlane)
circle=sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 5)
offset_distance=1.0direction_point= (0, 0, 0) # Use the center of the circle as the direction pointoffset_creator.create_offset(sketch, [circle], offset_distance, direction_point)
except:
ifoffset_creator.ui:
offset_creator.ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

About

Making Fusion360 API easier for beginners.

Resources

Stars

1 star

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages