Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I WANT TO USE COMBINE FEATURE TO COMBINE BODIES I WANT TO GIVE TOOL BODIES AND TARGET BODIES HOW TO DO

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
sHubamyadav016
268 Views, 9 Replies

I WANT TO USE COMBINE FEATURE TO COMBINE BODIES I WANT TO GIVE TOOL BODIES AND TARGET BODIES HOW TO DO

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

9 REPLIES 9
Message 2 of 10

Hi,

I'd suggest you to re-post your code using this tool (yellow highlighted) and choosing Python as language:

Jorge_Jaramillo_0-1701757831182.png

 

It is very hard to read/review your code without indentation.

 

regards,

Jorge Jaramillo

Software Engineer

 

 

 

Message 3 of 10

 

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)

           

        
                        
            
                    

           
            
            

           

                






                          


              
          

           

            
        




            
        
       

        




            

       

    except Exception as e:
      if ui:
         ui.messageBox('Failed: {}'.format(str(e)))

 

 

Message 4 of 10

NOW I WANT TO COMBINE THE BODIES SO HOW CAN I GIVE TOOL BODY AND TARGET BODY AND HOW I WILL DEFINE

Message 5 of 10

fxcjgfv

 

THE OUTPUT OF PROGRAM IS THE PANEL AND SEE SOME OVERLAPING IS THERE SO I WANT TO COMBINE THESE BODIES SO DESIGN SHOULD LOOK GOOD HOW TO DO 

Message 6 of 10

Hi,

 

With the following code snippet at the end of your code (line 309) it will combine all existing bodies into a single one:

        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)

 

This is the result (a single body in the component):

Jorge_Jaramillo_0-1701811392802.png

 

 

I saw in your code you create some bodies more than once.

If I had some time later, I will send a optimized copy of your code.

 

I hope this is what you're looking for.

 

Regards,

Jorge Jaramillo

Software Engineer

 

Message 7 of 10

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=50
        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, -320+m, 45)  # Adjust the position as needed
            iprofile_corner2 = adsk.core.Point3D.create(0, -280+m ,45)  # Adjust the position as needed
            iprofile_corner3 = adsk.core.Point3D.create(0, -280+m, 39)  # Adjust the position as needed
            iprofile_corner4 = adsk.core.Point3D.create(0, -297+m, 39)  # Adjust the position as needed
            iprofile_corner5 = adsk.core.Point3D.create(0,-297+m, 11)  # Adjust the position as needed
            iprofile_corner6 = adsk.core.Point3D.create(0, -280+m, 11)  # Adjust the position as needed
            iprofile_corner7 = adsk.core.Point3D.create(0, -280+m, 5)   # Adjust the position as needed
            iprofile_corner8 = adsk.core.Point3D.create(0, -320+m, 5)   # Adjust the position as needed
            iprofile_corner9 = adsk.core.Point3D.create(0, -320+m, 11)  # Adjust the position as needed
            iprofile_corner10 = adsk.core.Point3D.create(0, -303+m, 11)  # Adjust the position as needed
            iprofile_corner11 = adsk.core.Point3D.create(0,-303+m, 39)  # Adjust the position as needed
            iprofile_corner12 = adsk.core.Point3D.create(0, -320+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)
            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)))
Message 8 of 10

I ATTACHED THE CODE BUT IT IS NOT RUNING

Message 9 of 10

You added the code inside a loop.
Take it out of the loop, just removing indentation.
Message 10 of 10

Thanks bro for helping me I was trying from many days thanks.

I have one more doubt regarding the holes i posted if you can solve please solve

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report