Message 1 of 6
HOW TO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
import adsk.core, adsk.fusion, traceback, math
import adsk.core, adsk.fusion, traceback, math
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
model = design.activeComponent
# 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
xy_plane = panel_comp.xYConstructionPlane
panel_sketch = sketches.add(xy_plane)
# Define the corners of the panel profile.
corner1 = adsk.core.Point3D.create(0, 0, 0)
corner2 = adsk.core.Point3D.create(0, 1588, 0)
corner3 = adsk.core.Point3D.create(200, 1717, 0)
corner4 = adsk.core.Point3D.create(200, 0, 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, corner1)
# Create the panel extrusion.
extrudes = panel_comp.features.extrudeFeatures
prof = panel_sketch.profiles.item(0) # Check if there's a profile before accessing it.
if prof:
ext_input = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(65)) # Adjust the extrusion length as needed
ext = extrudes.add(ext_input)
# Create a sketch for the cutting profile.
cutting_sketch = sketches.add(xy_plane)
cutting_lines = cutting_sketch.sketchCurves.sketchLines
# Define the corners for the cut profile, leaving a 5mm border.
cut_corner1 = adsk.core.Point3D.create(5,5,5)
cut_corner2 = adsk.core.Point3D.create(5, 1583, 5) # 1588 - 5
cut_corner3 = adsk.core.Point3D.create(195,1712,5) # 1717 - 5
cut_corner4 = adsk.core.Point3D.create(195, 5, 5)
# Create lines connecting the corners to form the cut profile.
cut_line1 = cutting_lines.addByTwoPoints(cut_corner1, cut_corner2)
cut_line2 = cutting_lines.addByTwoPoints(cut_corner2, cut_corner3)
cut_line3 = cutting_lines.addByTwoPoints(cut_corner3, cut_corner4)
cut_line4 = cutting_lines.addByTwoPoints(cut_corner4, cut_corner1)
# Create a "Cut" extrude feature to remove the portion outside the cut profile.
cutting_ext_input = extrudes.createInput(cutting_sketch.profiles.item(0), adsk.fusion.FeatureOperations.CutFeatureOperation)
cutting_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(65)) # Same depth as the original extrusion
cutting_ext = extrudes.add(cutting_ext_input)
# Create a hole on the left plane of the panel.
a = 100
for i in range(10):
if i==1:
a += 200
elif i==2:
a +=200
elif i==3:
a +=250
elif i==4:
a +=250
elif i==5:
a +=100
elif i==6:
a +=150
elif i==7:
a +=100
elif i==8:
a +=150
elif i==9:
a +=100
# Create a hole on the bottom 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, a, 200)
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)
# Create a hole on the left plane of the panel.
a = 100
for i in range(9):
if i==1:
a += 200
elif i==2:
a +=200
elif i==3:
a +=250
elif i==4:
a +=250
elif i==5:
a +=100
elif i==6:
a +=150
elif i==7:
a +=100
elif i==8:
a +=150
# Create a hole on the SIDE 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, a, 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)
# Create a hole on the bottom plane of the panel.
x = 0
for i in range(3):
x += 50
# Create a hole on the bottom plane of the panel.
bottom_plane = panel_comp.xZConstructionPlane
hole_sketch = panel_comp.sketches.add(bottom_plane)
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(x,-40,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)
# Create an I-profile on the left face.
Right_plane = panel_comp.xYConstructionPlane
iprofile_sketch = panel_comp.sketches.add(Right_plane)
# Define the coordinates of the I-profile.
# Define the rectangle's corner points.
iprofile_corner1 = adsk.core.Point3D.create(5, 930, 25) # Adjust the position as needed
iprofile_corner2 = adsk.core.Point3D.create(5, 920, 25) # Adjust the position as needed
iprofile_corner3 = adsk.core.Point3D.create(5, 920, 20) # Adjust the position as needed
iprofile_corner4 = adsk.core.Point3D.create(5, 923, 20) # Adjust the position as needed
iprofile_corner5 = adsk.core.Point3D.create(5, 923, 10) # Adjust the position as needed
iprofile_corner6 = adsk.core.Point3D.create(5, 920, 10) # Adjust the position as needed
iprofile_corner7 = adsk.core.Point3D.create(5, 920, 5) # Adjust the position as needed
iprofile_corner8 = adsk.core.Point3D.create(5, 930, 5) # Adjust the position as needed
iprofile_corner9 = adsk.core.Point3D.create(5, 930, 10) # Adjust the position as needed
iprofile_corner10 = adsk.core.Point3D.create(5, 927, 10) # Adjust the position as needed
iprofile_corner11 = adsk.core.Point3D.create(5, 927, 20) # Adjust the position as needed
iprofile_corner12 = adsk.core.Point3D.create(5, 930, 20) # Adjust the position as needed
# Create lines connecting the corners to form the I-profile.
# Create lines connecting the corners to form the I-profile.
lines = iprofile_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 = iprofile_sketch.profiles.item(0)
# Extrude the I-profile in the opposite direction.
i_ext_input = extrudes.createInput(iprofile_profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
i_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(-190)) # Adjust the extrusion height as needed
i_ext = extrudes.add(i_ext_input)
#wall tie
z = 0
for i in range(4):
if i == 0:
z = 0
elif i == 1:
z += 400
elif i == 2:
z += 500
elif i == 3:
z += 500
plane = panel_comp.xYConstructionPlane
hole_sketch1 = panel_comp.sketches.add(plane) # Use a different variable name
corner1 = adsk.core.Point3D.create(0, 80 + z, 0) # Adjust the position as needed
corner2 = adsk.core.Point3D.create(3.5, 80 + z, 0) # Adjust the position as needed
corner3 = adsk.core.Point3D.create(3.5, 120 + z, 0) # Adjust the position as needed
corner4 = adsk.core.Point3D.create(0, 120+ z, 0)
lines = hole_sketch1.sketchCurves.sketchLines
line1 = lines.addByTwoPoints(corner1, corner2)
line2 = lines.addByTwoPoints(corner2, corner3)
line3 = lines.addByTwoPoints(corner3, corner4)
line4 = lines.addByTwoPoints(corner4, corner1)
hole_prof1 = hole_sketch1.profiles[0]
hole_ext_input1 = extrudes.createInput(hole_prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)
hole_ext_input1.setDistanceExtent(False, adsk.core.ValueInput.createByReal(65)) # Adjust the depth of the hole as needed
hole_ext1 = extrudes.add(hole_ext_input1)
z=0
for i in range(4):
if i==0:
z = 0
elif i==1:
z +=400
elif i==2:
z +=500
elif i==3:
z +=500
hole_sketch2 = panel_comp.sketches.add(plane)
corner1 = adsk.core.Point3D.create(200-3.5, 80+z, 0) # Adjust the position as needed
corner2 = adsk.core.Point3D.create(200, 80+z, 0) # Adjust the position as needed
corner3 = adsk.core.Point3D.create(200, 120+z, 0) # Adjust the position as needed
corner4 = adsk.core.Point3D.create(200-3.5, 120+z, 0)
lines = hole_sketch2.sketchCurves.sketchLines
line1 = lines.addByTwoPoints(corner1, corner2)
line2 = lines.addByTwoPoints(corner2, corner3)
line3 = lines.addByTwoPoints(corner3, corner4)
line4 = lines.addByTwoPoints(corner4, corner1)
hole_prof2 = hole_sketch2.profiles[0]
hole_ext_input2 = extrudes.createInput(hole_prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
hole_ext_input2.setDistanceExtent(False, adsk.core.ValueInput.createByReal(65)) # Adjust the depth of the hole as needed
hole_ext2 = extrudes.add(hole_ext_input2)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))