- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
import adsk.core
import adsk.fusion
import adsk.cam
import traceback
import math
from adsk.core import Vector3D
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
design = adsk.fusion.Design.cast(app.activeProduct)
unitsMgr = design.unitsManager
rootComp = design.rootComponent
sketches = rootComp.sketches
planes = rootComp.constructionPlanes
features = rootComp.features
sweeps = rootComp.features.sweepFeatures
extrudes = rootComp.features.extrudeFeatures
root = app.activeProduct.rootComponent
features = root.features
# Create a new component for the panel.
root_comp = design.rootComponent
new_comp = root_comp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
panel_comp = new_comp.component
# Create a new sketch for the panel.
sketches = panel_comp.sketches
xZ_plane = panel_comp.xZConstructionPlane
panel_sketch = sketches.add(xZ_plane)
# Define the corners of the panel profile.
corner1 = adsk.core.Point3D.create(0,0,0)
corner = adsk.core.Point3D.create(150,0,0)
# Create lines connecting the corners to form the panel profile.
lines = panel_sketch.sketchCurves.sketchLines
line = lines.addByTwoPoints(corner1, corner)
# Create an angled line at corner (147.21 degrees).
angle = math.radians(-150)
length = -400
end_point1 = adsk.core.Point3D.create(corner.x + length * math.cos(angle),
corner.y + length * math.sin(angle),
0)
m= corner.x + length * math.cos(angle)
s= corner.y + length * math.sin(angle)
p= corner.x + (length+5) * math.cos(angle)
q= corner.y + (length+5) * math.sin(angle)
angled_line = lines.addByTwoPoints(corner, end_point1)
# Merge the two lines
line.endSketchPoint.merge(angled_line.startSketchPoint)
# Get the root component of the active design.
rootComp = app.activeProduct.rootComponent
# Get the left plane of the root component.
leftPlane = rootComp.xYConstructionPlane
# Create a sketch on the left plane.
panel_sketch = rootComp.sketches.add(leftPlane)
# Define the corners of the panel profile.
corner1 = adsk.core.Point3D.create(0, 0, 0)
corner2 = adsk.core.Point3D.create(0, 0, 65)
corner3 = adsk.core.Point3D.create(0, -5, 65)
corner4 = adsk.core.Point3D.create(0, -5, 5) # Adjusted for thickness
corner5 = adsk.core.Point3D.create(0, -795, 5) # Adjusted for thickness
corner6 = adsk.core.Point3D.create(0, -795, 65) # Adjusted for thickness
corner7 = adsk.core.Point3D.create(0, -800, 65) # Adjusted for thickness
corner8 = adsk.core.Point3D.create(0, -800, 0)
# Create lines connecting the corners to form the panel profile.
lines = panel_sketch.sketchCurves.sketchLines
line1 = lines.addByTwoPoints(corner1, corner2)
line2 = lines.addByTwoPoints(corner2, corner3)
line3 = lines.addByTwoPoints(corner3, corner4)
line4 = lines.addByTwoPoints(corner4, corner5)
line5 = lines.addByTwoPoints(corner5, corner6)
line6 = lines.addByTwoPoints(corner6, corner7)
line7 = lines.addByTwoPoints(corner7, corner8)
line8 = lines.addByTwoPoints(corner8, corner1)
# Now, create a profile from the closed sketch
panel_profile = panel_sketch.profiles.item(0)
# Create a path and let it find connected curves automatically
path = panel_comp.features.createPath(line)
# Create a sweep input
sweeps = panel_comp.features.sweepFeatures
sweepInput = sweeps.createInput(panel_profile, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
sweepInput.taperAngle = adsk.core.ValueInput.createByString('0 deg')
sweepInput.twistAngle = adsk.core.ValueInput.createByString('0deg')
# Create the sweep.
sweep = sweeps.add(sweepInput)
# Create holes on the back plane of the panel.
# Create holes on the back plane of the panel.
z = 0
for i in range(2):
z += 50 # Increment z by 50 in each iteration
if i < 2:
# Create a hole on the bottom plane of the panel.
back_plane = panel_comp.xZConstructionPlane
hole_sketch = panel_comp.sketches.add(back_plane)
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(z, -40, -800) # Adjust the position as needed
hole_radius = 8 # Adjust the radius as needed
# Create a circle for the hole.
hole_sketch.sketchCurves.sketchCircles.addByCenterRadius(hole_center, hole_radius)
# Extrude the hole sketch to create the hole on the side face.
hole_prof = hole_sketch.profiles[0]
hole_ext_input = panel_comp.features.extrudeFeatures.createInput(hole_prof, adsk.fusion.FeatureOperations.CutFeatureOperation)
hole_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(850)) # Adjust the depth of the hole as needed
hole_ext = panel_comp.features.extrudeFeatures.add(hole_ext_input)
off_set = 40
angle_for_holes = math.radians(30)
xo = 150 + off_set*math.sin(angle_for_holes/2)
r = 400+ off_set*math.sin(angle_for_holes/2)
yo = -40
for i in range(7):
r-=50
# Create a hole on the bottom plane of the panel.
back_plane = panel_comp.xZConstructionPlane
hole_sketch = panel_comp.sketches.add(back_plane)
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(xo + r * math.cos(angle_for_holes), (yo + r * math.sin(angle_for_holes)),0) # Adjust the position as needed
hole_radius = 8 # Adjust the radius as needed
# Create a circle for the hole.
hole_sketch.sketchCurves.sketchCircles.addByCenterRadius(hole_center, hole_radius)
# Extrude the hole sketch to create the hole on the side face.
hole_prof = hole_sketch.profiles[0]
hole_ext_input = panel_comp.features.extrudeFeatures.createInput(hole_prof, adsk.fusion.FeatureOperations.CutFeatureOperation)
hole_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(-850)) # Adjust the depth of the hole as needed
hole_ext = panel_comp.features.extrudeFeatures.add(hole_ext_input)
# Create a rectangle and extrude it in the LEFT plane.
top_plane = panel_comp.xYConstructionPlane
sketch = panel_comp.sketches.add(top_plane)
# Define the rectangle's corner points.
rect_corner1 = adsk.core.Point3D.create(0, 0, 0) # Adjust the position as needed
rect_corner2 = adsk.core.Point3D.create(5, 0, 0) # Adjust the position as needed
rect_corner3 = adsk.core.Point3D.create(5, -800, 0) # Adjust the position as needed
rect_corner4 = adsk.core.Point3D.create(0, -800, 0) # Adjust the position as needed
# Create lines connecting the corners to form the rectangle.
rect_lines = sketch.sketchCurves.sketchLines
rect_line1 = rect_lines.addByTwoPoints(rect_corner1, rect_corner2)
rect_line2 = rect_lines.addByTwoPoints(rect_corner2, rect_corner3)
rect_line3 = rect_lines.addByTwoPoints(rect_corner3, rect_corner4)
rect_line4 = rect_lines.addByTwoPoints(rect_corner4, rect_corner1)
# Create a profile from the rectangle.
rect_profile = sketch.profiles.item(0)
# Extrude the sketch to create the rectangle.
extrudes = panel_comp.features.extrudeFeatures
prof = panel_sketch.profiles[0]
rect_ext_input = extrudes.createInput(rect_profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
rect_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(65)) # Adjust the extrusion height as needed
rect_ext = extrudes.add(rect_ext_input)
# Create a rectangle and extrude it in the LEFT plane.
top_plane = panel_comp.xYConstructionPlane
sketch = panel_comp.sketches.add(top_plane)
# Define the rectangle's corner points.
rect_corner1 = adsk.core.Point3D.create(m, 0, -s) # Adjust the position as needed
rect_corner2 = adsk.core.Point3D.create(m, -800, -s) # Adjust the position as needed
rect_corner3 = adsk.core.Point3D.create(p, -800, -q) # Adjust the position as needed
rect_corner4 = adsk.core.Point3D.create(p, 0, -q) # Adjust the position as needed
# Create lines connecting the corners to form the rectangle.
rect_lines = sketch.sketchCurves.sketchLines
rect_line1 = rect_lines.addByTwoPoints(rect_corner1, rect_corner2)
rect_line2 = rect_lines.addByTwoPoints(rect_corner2, rect_corner3)
rect_line3 = rect_lines.addByTwoPoints(rect_corner3, rect_corner4)
rect_line4 = rect_lines.addByTwoPoints(rect_corner4, rect_corner1)
# Create a profile from the rectangle.
rect_profile2 = sketch.profiles.item(0)
# Extrude the sketch to create the rectangle.
extrudes = panel_comp.features.extrudeFeatures
prof = panel_sketch.profiles[0]
rect_ext_input = extrudes.createInput(rect_profile2, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
rect_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(65)) # Adjust the extrusion height as needed
rect_ext = extrudes.add(rect_ext_input)
z=100
for i in range(7):
# Create a hole on the left plane of the panel.
side_plane = panel_comp.yZConstructionPlane
hole_sketch = panel_comp.sketches.add(side_plane)
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(-40, -z,0) # Adjust the position as needed
hole_radius = 8 # Adjust the radius as needed
# Create a circle for the hole.
hole_sketch.sketchCurves.sketchCircles.addByCenterRadius(hole_center, hole_radius)
# Extrude the hole sketch to create the hole on the bottom face.
hole_prof = hole_sketch.profiles[0]
hole_ext_input = extrudes.createInput(hole_prof, adsk.fusion.FeatureOperations.CutFeatureOperation)
hole_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(5)) # Adjust the depth of the hole as needed
hole_ext = extrudes.add(hole_ext_input)
z+=100
#stiffner
m = 0
for i in range(2):
if(i > 0):
m -= 300
# Create a sketch for the stiffener on the XZ plane
stiffener_plane = panel_comp.xYConstructionPlane
stiffener_sketch = panel_comp.sketches.add(stiffener_plane)
# Define the rectangle's corner points.
iprofile_corner1 = adsk.core.Point3D.create(0, -270+m, 45) # Adjust the position as needed
iprofile_corner2 = adsk.core.Point3D.create(0, -230+m ,45) # Adjust the position as needed
iprofile_corner3 = adsk.core.Point3D.create(0, -230+m, 39) # Adjust the position as needed
iprofile_corner4 = adsk.core.Point3D.create(0, -247+m, 39) # Adjust the position as needed
iprofile_corner5 = adsk.core.Point3D.create(0,-247+m, 11) # Adjust the position as needed
iprofile_corner6 = adsk.core.Point3D.create(0, -230+m, 11) # Adjust the position as needed
iprofile_corner7 = adsk.core.Point3D.create(0, -230+m, 5) # Adjust the position as needed
iprofile_corner8 = adsk.core.Point3D.create(0, -270+m, 5) # Adjust the position as needed
iprofile_corner9 = adsk.core.Point3D.create(0, -270+m, 11) # Adjust the position as needed
iprofile_corner10 = adsk.core.Point3D.create(0, -253+m, 11) # Adjust the position as needed
iprofile_corner11 = adsk.core.Point3D.create(0,-253+m, 39) # Adjust the position as needed
iprofile_corner12 = adsk.core.Point3D.create(0, -270+m, 39) # Adjust the position as needed
# Create lines connecting the corners to form the I-profile.
lines = stiffener_sketch.sketchCurves.sketchLines
line1 = lines.addByTwoPoints(iprofile_corner1, iprofile_corner2)
line2 = lines.addByTwoPoints(iprofile_corner2, iprofile_corner3)
line3 = lines.addByTwoPoints(iprofile_corner3, iprofile_corner4)
line4 = lines.addByTwoPoints(iprofile_corner4, iprofile_corner5)
line5 = lines.addByTwoPoints(iprofile_corner5, iprofile_corner6)
line6 = lines.addByTwoPoints(iprofile_corner6, iprofile_corner7)
line7 = lines.addByTwoPoints(iprofile_corner7, iprofile_corner8)
line8 = lines.addByTwoPoints(iprofile_corner8, iprofile_corner9)
line9 = lines.addByTwoPoints(iprofile_corner9, iprofile_corner10)
line10 = lines.addByTwoPoints(iprofile_corner10, iprofile_corner11)
line11 = lines.addByTwoPoints(iprofile_corner11, iprofile_corner12)
line12 = lines.addByTwoPoints(iprofile_corner12, iprofile_corner1)
# Create a profile from the I-profile sketch.
iprofile_profile = stiffener_sketch.profiles.item(0)
# Create a path and let it find connected curves automatically
path = panel_comp.features.createPath(line)
# Create a sweep input
sweeps = panel_comp.features.sweepFeatures
sweepInput = sweeps.createInput( iprofile_profile, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
sweepInput.taperAngle = adsk.core.ValueInput.createByString('0 deg')
sweepInput.twistAngle = adsk.core.ValueInput.createByString('0deg')
# Create the sweep.
sweep = sweeps.add(sweepInput)
TargetBody = root.bRepBodies.itemByName(' iprofile_profile')
ToolBodies = adsk.core.ObjectCollection.create()
ToolBodies.add(root.bRepBodies.itemByName('rect_profile'))
CombineCutInput = root.features.combineFeatures.createInput(TargetBody, ToolBodies )
CombineCutFeats = features.combineFeatures
Solved! Go to Solution.