Message 1 of 7
I AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
essageBox('Failed: {}'.format(str(e)))
essageBox('Failed: {}'.format(str(e)))
yes please give try i am not able to do please help
Hi,
I was able to build it with a copy & rotate & move it from the left side panel.
This is the full script which includes some optimizations to avoid duplicates bodies and sketches:
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.
panel_profile_points = [
(0, 0, 0),
(0, 0, 65),
(0, -5, 65),
(0, -5, 5),
(0, -795, 5),
(0, -795, 65),
(0, -800, 65),
(0, -800, 0)
]
# Create lines connecting the corners to form the panel profile.
lines = panel_sketch.sketchCurves.sketchLines
for i_ppp in range(len(panel_profile_points)):
lines.addByTwoPoints(
adsk.core.Point3D.create(*panel_profile_points[i_ppp]),
adsk.core.Point3D.create(*panel_profile_points[(i_ppp + 1) % len(panel_profile_points)])
)
# 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 a hole on the bottom plane of the panel.
back_plane = panel_comp.xZConstructionPlane
hole_sketch = panel_comp.sketches.add(back_plane)
hole_radius = 8 # Adjust the radius as needed
for z in range(50, 150, 50):
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(z, -40, -800) # Adjust the position as needed
# Create a circle for the hole.
hole_sketch.sketchCurves.sketchCircles.addByCenterRadius(hole_center, hole_radius)
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
# Create a hole on the bottom plane of the panel.
for i in range(7):
r-=50
# 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)),-800) # Adjust the position 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_oc = adsk.core.ObjectCollection.createWithArray([prof for prof in hole_sketch.profiles])
hole_ext_input = panel_comp.features.extrudeFeatures.createInput(hole_oc, 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
top_plane_sketch = panel_comp.sketches.add(top_plane)
# Define the rectangle's corner points.
top_plane_points = [
(0, 0, 0), # Adjust the position as needed
(5, 0, 0), # Adjust the position as needed
(5, -800, 0), # Adjust the position as needed
(0, -800, 0), # Adjust the position as needed
]
rect_lines = top_plane_sketch.sketchCurves.sketchLines
for i_point in range(len(top_plane_points)):
rect_lines.addByTwoPoints(
adsk.core.Point3D.create(*top_plane_points[i_point]),
adsk.core.Point3D.create(*top_plane_points[(i_point + 1) % len(top_plane_points)])
)
# Create a profile from the rectangle.
rect_profile = top_plane_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)
side_plane = panel_comp.yZConstructionPlane
hole_sketch = panel_comp.sketches.add(side_plane)
hole_radius = 8 # Adjust the radius as needed
for z in range(100, 800, 100):
# Create a hole on the left plane of the panel.
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(-40, -z,0) # Adjust the position as needed
# Create a circle for the hole.
hole_sketch.sketchCurves.sketchCircles.addByCenterRadius(hole_center, hole_radius)
hole_oc = adsk.core.ObjectCollection.createWithArray([prof for prof in hole_sketch.profiles])
hole_ext_input = panel_comp.features.extrudeFeatures.createInput(hole_oc, 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)
#stiffner
# Create a sketch for the stiffener on the XZ plane
stiffener_plane = panel_comp.xYConstructionPlane
stiffener_sketch = panel_comp.sketches.add(stiffener_plane)
for m in range(0, -600, -300):
# Define the rectangle's corner points.
i_points = [
(0, -270+m, 45),
(0, -230+m ,45),
(0, -230+m, 39),
(0, -247+m, 39),
(0,-247+m, 11),
(0, -230+m, 11),
(0, -230+m, 5),
(0, -270+m, 5),
(0, -270+m, 11),
(0, -253+m, 11),
(0,-253+m, 39),
(0, -270+m, 39)
]
lines = stiffener_sketch.sketchCurves.sketchLines
for i_point in range(len(i_points)):
lines.addByTwoPoints(
adsk.core.Point3D.create(*i_points[i_point]),
adsk.core.Point3D.create(*i_points[(i_point + 1) % len(i_points)])
)
for iprofile_profile in stiffener_sketch.profiles:
# 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)
# copy, rotate and move left panel
# - copy the boby into the same component
tilt_left_panel: adsk.fusion.BRepBody = rect_ext.bodies[0].copyToComponent(new_comp)
# - select the edge to rotate it (the longest, lowest and internal edge)
tilt_edge = sorted(tilt_left_panel.edges,
key = lambda e: e.length + e.startVertex.geometry.x - e.startVertex.geometry.z,
reverse = True)[0]
# - rotate the body
move_feature_input = panel_comp.features.moveFeatures.createInput2(adsk.core.ObjectCollection.createWithArray([tilt_left_panel]))
move_feature_input.defineAsRotate(tilt_edge, adsk.core.ValueInput.createByReal(math.radians(180) - angle))
panel_comp.features.moveFeatures.add(move_feature_input)
# - move the body at the end of the angled_line
move_feature_input = panel_comp.features.moveFeatures.createInput2(adsk.core.ObjectCollection.createWithArray([tilt_left_panel]))
source_point = tilt_edge.startVertex if tilt_edge.startVertex.geometry.y == 0 else tilt_edge.endVertex
move_feature_input.defineAsPointToPosition(
source_point,
adsk.core.ValueInput.createByReal(150 + length * math.cos(math.radians(-150))),
adsk.core.ValueInput.createByReal(0),
adsk.core.ValueInput.createByReal(-length * math.sin(math.radians(-150))),
True
)
panel_comp.features.moveFeatures.add(move_feature_input)
# combine feature to group all body-parts
panel_comb_fea = panel_comp.features.combineFeatures
tool_bodies_oc = adsk.core.ObjectCollection.createWithArray(
[panel_comp.bRepBodies[i] for i in range(1, panel_comp.bRepBodies.count)]
)
comb_input: adsk.fusion.CombineFeatureInput = panel_comb_fea.createInput(
panel_comp.bRepBodies[0],
tool_bodies_oc
)
comb_input.isKeepToolBodies = False
comb_input.operation = adsk.fusion.FeatureOperations.JoinFeatureOperation
panel_comb_fea.add(comb_input)
except Exception as e:
if ui:
# ui.messageBox('Failed: {}'.format(str(e)))
ui.messageBox('Failed: {}'.format(traceback.format_exc()))
This is the final result I get:
Regards,
Jorge Jaramillo
Software Engineer
HELLO SIR THANK YOU GIVING ME PRECIOUS TIME AND ALSO A PROPER SOLUTION .
SIR , I HAVE ONE MORE PROBLEM PLEASE SGIVE SOME PROPER SOLUTION I AM NOT ABLE TO SOLVE .
import adsk.core, adsk.fusion, traceback, math
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(300,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 = -300
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.
panel_profile_points = [
(0, 0, 0),
(0, 0, 65),
(0, -5, 65),
(0, -5, 5),
(0, -95, 5),
(0, -95, 65),
(0, -100, 65),
(0, -100, 0)
]
# Create lines connecting the corners to form the panel profile.
lines = panel_sketch.sketchCurves.sketchLines
for i_ppp in range(len(panel_profile_points)):
lines.addByTwoPoints(
adsk.core.Point3D.create(*panel_profile_points[i_ppp]),
adsk.core.Point3D.create(*panel_profile_points[(i_ppp + 1) % len(panel_profile_points)])
)
# 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 a hole on the bottom plane of the panel.
back_plane = panel_comp.xZConstructionPlane
hole_sketch = panel_comp.sketches.add(back_plane)
hole_radius = 8 # Adjust the radius as needed
for z in range(50, 300, 50):
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(z, -40, -100) # Adjust the position as needed
# Create a circle for the hole.
hole_sketch.sketchCurves.sketchCircles.addByCenterRadius(hole_center, hole_radius)
off_set = 40
angle_for_holes = math.radians(30)
xo = 300 + off_set*math.sin(angle_for_holes/2)
r = 300+ off_set*math.sin(angle_for_holes/2)
yo = -40
# Create a hole on the bottom plane of the panel.
for i in range (5):
r-=50
# 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)),-100) # Adjust the position 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_oc = adsk.core.ObjectCollection.createWithArray([prof for prof in hole_sketch.profiles])
hole_ext_input = panel_comp.features.extrudeFeatures.createInput(hole_oc, adsk.fusion.FeatureOperations.CutFeatureOperation)
hole_ext_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(150)) # 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
top_plane_sketch = panel_comp.sketches.add(top_plane)
# Define the rectangle's corner points.
top_plane_points = [
(0, 0, 0), # Adjust the position as needed
(5, 0, 0), # Adjust the position as needed
(5, -100, 0), # Adjust the position as needed
(0, -100, 0), # Adjust the position as needed
]
rect_lines = top_plane_sketch.sketchCurves.sketchLines
for i_point in range(len(top_plane_points)):
rect_lines.addByTwoPoints(
adsk.core.Point3D.create(*top_plane_points[i_point]),
adsk.core.Point3D.create(*top_plane_points[(i_point + 1) % len(top_plane_points)])
)
# Create a profile from the rectangle.
rect_profile = top_plane_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)
side_plane = panel_comp.yZConstructionPlane
hole_sketch = panel_comp.sketches.add(side_plane)
hole_radius = 8 # Adjust the radius as needed
for z in range(50,100,50):
# Create a hole on the left plane of the panel.
# Define the center and radius of the hole.
hole_center = adsk.core.Point3D.create(-40, -z,0) # Adjust the position as needed
# Create a circle for the hole.
hole_sketch.sketchCurves.sketchCircles.addByCenterRadius(hole_center, hole_radius)
hole_oc = adsk.core.ObjectCollection.createWithArray([prof for prof in hole_sketch.profiles])
hole_ext_input = panel_comp.features.extrudeFeatures.createInput(hole_oc, 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)
# copy, rotate and move left panel
# - copy the boby into the same component
tilt_left_panel: adsk.fusion.BRepBody = rect_ext.bodies[0].copyToComponent(new_comp)
# - select the edge to rotate it (the longest, lowest and internal edge)
tilt_edge = sorted(tilt_left_panel.edges,
key = lambda e: e.length + e.startVertex.geometry.x - e.startVertex.geometry.z,
reverse = True)[0]
# - rotate the body
move_feature_input = panel_comp.features.moveFeatures.createInput2(adsk.core.ObjectCollection.createWithArray([tilt_left_panel]))
move_feature_input.defineAsRotate(tilt_edge, adsk.core.ValueInput.createByReal(math.radians(180) - angle))
panel_comp.features.moveFeatures.add(move_feature_input)
# - move the body at the end of the angled_line
move_feature_input = panel_comp.features.moveFeatures.createInput2(adsk.core.ObjectCollection.createWithArray([tilt_left_panel]))
source_point = tilt_edge.startVertex if tilt_edge.startVertex.geometry.y == 0 else tilt_edge.endVertex
move_feature_input.defineAsPointToPosition(
source_point,
adsk.core.ValueInput.createByReal(300 + length * math.cos(math.radians(-150))),
adsk.core.ValueInput.createByReal(0),
adsk.core.ValueInput.createByReal(-length * math.sin(math.radians(-150))),
True
)
panel_comp.features.moveFeatures.add(move_feature_input)
# combine feature to group all body-parts
panel_comb_fea = panel_comp.features.combineFeatures
tool_bodies_oc = adsk.core.ObjectCollection.createWithArray(
[panel_comp.bRepBodies[i] for i in range(1, panel_comp.bRepBodies.count)]
)
comb_input: adsk.fusion.CombineFeatureInput = panel_comb_fea.createInput(
panel_comp.bRepBodies[0],
tool_bodies_oc
)
comb_input.isKeepToolBodies = False
comb_input.operation = adsk.fusion.FeatureOperations.JoinFeatureOperation
panel_comb_fea.add(comb_input)
except Exception as e:
if ui:
# ui.messageBox('Failed: {}'.format(str(e)))
ui.messageBox('Failed: {}'.format(traceback.format_exc()))
sDGgfvdxhn
YOU CAN TAKE APPROPRIATE PLEASE SIR HELP ME