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 CONSTRUCT A PLANE AT AN ANNGLE I SEEN THE DOCUMENTATION AND I IMPLEMENT BUT IN MY PROGRAM IT IS NOT RUNING

0 REPLIES 0
Reply
Message 1 of 1
sHubamyadav016
53 Views, 0 Replies

I WANT TO CONSTRUCT A PLANE AT AN ANNGLE I SEEN THE DOCUMENTATION AND I IMPLEMENT BUT IN MY PROGRAM IT IS NOT RUNING

import adsk.core, adsk.fusion, traceback, math

def clear_design_data(design😞
    # Delete all components except the root component.
    root_comp = design.rootComponent
    for component in root_comp.allOccurrences:
        if component.component.name != root_comp.name:
            component.deleteMe()

    # Delete all sketches.
    for sketch in root_comp.sketches:
        sketch.deleteMe()

    # Delete all features.
    for feature in root_comp.features:
        feature.deleteMe()

def create_construction_planes(panel_comp, sketch, extrude😞
    # Get the profile again since the sketch has been edited.
    prof = sketch.profiles.item(0)

    # Get construction planes
    planes = panel_comp.constructionPlanes

    # Create construction plane input
    planeInput = planes.createInput()

    # Add construction plane by angle
    angle = adsk.core.ValueInput.createByString('122.0 deg')
    planeInput.setByAngle(sketch.sketchCurves.sketchLines.item(2), angle, prof)
    planes.add(planeInput)





def run(context😞
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct
        model = design.activeComponent

        # Show a file dialog to select a CSV file.
        file_dialog = ui.createFileDialog()
        file_dialog.isMultiSelectEnabled = False
        file_dialog.title = "Select CSV File"
        file_dialog.filter = "CSV Files (*.csv)"
        file_dialog.filterIndex = 0

        dialog_result = file_dialog.showOpen()
        if dialog_result == adsk.core.DialogResults.DialogOK:
            csvFilePath = file_dialog.filename
            ui.messageBox(f'Selected CSV file path: {csvFilePath}')

            # Now you can open and read the CSV file and process its data.
            with open(csvFilePath, 'r') as file:
                my_var = 0
                for line in file:
                    pieces = line.split(',')

            #set parameters for panel
            panel_width = design.unitsManager.evaluateExpression(pieces[1], 'mm')
            panel_length1 = design.unitsManager.evaluateExpression(pieces[2], 'mm')
            panel_length2 = design.unitsManager.evaluateExpression(pieces[3], 'mm')
            panel_thickness = design.unitsManager.evaluateExpression(pieces[4], 'mm')
            panel_height    = design.unitsManager.evaluateExpression(pieces[5], 'mm')

             # Clear the design data from the previous iteration.
            clear_design_data(design)

            # design code
            app = adsk.core.Application.get()

            if not design:
                ui = app.userInterface
                ui.messageBox('It is not supported in the current workspace. Please change to the MODEL workspace and try again.')
                return
           
             # 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, panel_length1, 0)
            corner3 = adsk.core.Point3D.create(panel_width, panel_length2, 0)
            corner4 = adsk.core.Point3D.create(panel_width, 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(panel_height))  # 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(panel_thickness, panel_thickness, panel_thickness)
            cut_corner2 = adsk.core.Point3D.create(panel_thickness, panel_length1-panel_thickness, panel_thickness)  # 1588 - 5
            cut_corner3 = adsk.core.Point3D.create(panel_width-panel_thickness, panel_length2-panel_thickness, panel_thickness)  # 1717 - 5
            cut_corner4 = adsk.core.Point3D.create(panel_width-panel_thickness, panel_thickness, panel_thickness)

            # 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(panel_height))  # Same depth as the original extrusion
            cutting_ext = extrudes.add(cutting_ext_input)

               

                # Create a hole on the left plane of the panel.
            a = 10
            for i in range(10😞
                if i==1:
                    a += 20
                elif i==2:
                    a +=20
                elif i==3:
                    a +=25
                elif i==4:
                    a +=25
                elif i==5:
                    a +=10
                elif i==6:
                    a +=15
                elif i==7:
                    a +=10
                elif i==8:
                    a +=15
                elif i==9:
                    a +=10


                # 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(-4, a, 20)  # 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(-0.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 = 10
            for i in range(9😞
                if i==1:
                    a += 20
                elif i==2:
                    a +=20
                elif i==3:
                    a +=25
                elif i==4:
                    a +=25
                elif i==5:
                    a +=10
                elif i==6:
                    a +=15
                elif i==7:
                    a +=10
                elif i==8:
                    a +=15
                   


                # 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(-4, a, 0)  # Adjust the position as needed
                hole_radius = 0.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(0.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 += 5
                # 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,-4,0)  # Adjust the position as needed
                hole_radius = 0.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(0.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(panel_thickness, 93, 2.5)  # Adjust the position as needed
                iprofile_corner2 = adsk.core.Point3D.create(panel_thickness, 92, 2.5)  # Adjust the position as needed
                iprofile_corner3 = adsk.core.Point3D.create(panel_thickness, 92, 2.0)  # Adjust the position as needed
                iprofile_corner4 = adsk.core.Point3D.create(panel_thickness, 92.3, 2.0)  # Adjust the position as needed
                iprofile_corner5 = adsk.core.Point3D.create(panel_thickness, 92.3, 1.0)  # Adjust the position as needed
                iprofile_corner6 = adsk.core.Point3D.create(panel_thickness, 92.0, 1.0)  # Adjust the position as needed
                iprofile_corner7 = adsk.core.Point3D.create(panel_thickness, 92.0, 0.5)   # Adjust the position as needed
                iprofile_corner8 = adsk.core.Point3D.create(panel_thickness, 93.0, 0.5)   # Adjust the position as needed
                iprofile_corner9 = adsk.core.Point3D.create(panel_thickness, 93.0, 1.0)  # Adjust the position as needed
                iprofile_corner10 = adsk.core.Point3D.create(panel_thickness, 92.7, 1.0)  # Adjust the position as needed
                iprofile_corner11 = adsk.core.Point3D.create(panel_thickness, 92.7, 2.0)  # Adjust the position as needed
                iprofile_corner12 = adsk.core.Point3D.create(panel_thickness, 93.0, 2.0)  # 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(-19))  # 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 += 40
                elif i == 2:
                  z += 50
                elif i == 3:
                  z += 50
         

                plane = panel_comp.xYConstructionPlane
                hole_sketch1 = panel_comp.sketches.add(plane)  # Use a different variable name

                corner1 = adsk.core.Point3D.create(0, 8 + z, 0)  # Adjust the position as needed
                corner2 = adsk.core.Point3D.create(0.35, 8 + z, 0)  # Adjust the position as needed
                corner3 = adsk.core.Point3D.create(0.35, 12 + z, 0)  # Adjust the position as needed
                corner4 = adsk.core.Point3D.create(0, 12 + 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(panel_height))  # 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 +=40
                elif i==2:
                  z +=50
                elif i==3:
                  z +=50
       
                hole_sketch2 = panel_comp.sketches.add(plane)
                corner1 = adsk.core.Point3D.create(panel_width-0.35 , 8+z, 0)  # Adjust the position as needed
                corner2 = adsk.core.Point3D.create(panel_width, 8+z, 0)  # Adjust the position as needed
                corner3 = adsk.core.Point3D.create(panel_width, 12+z, 0)  # Adjust the position as needed
                corner4 = adsk.core.Point3D.create(panel_width-0.35, 12+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(panel_height))  # Adjust the depth of the hole as needed
                hole_ext2 = extrudes.add(hole_ext_input2)
                 # Create construction planes based on the panel geometry
                create_construction_planes(root_comp, panel_sketch, ext)

                 

               


                 


                 # Specify the path and filename for the STEP file.
                my_var += 1
                step_file_name = "{}0B{}0".format(int(panel_width), int(panel_length1))
                step_file_path = "C:/Test_step/" + step_file_name

                # Get the export manager.
                export_mgr = design.exportManager

                # Create a STEP export options object.
                step_options = export_mgr.createSTEPExportOptions(step_file_path)

           

             

           
        file.close()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


0 REPLIES 0

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