Axel Richter
Published © CC BY-NC

Design any part with ChatGPT for 3D printing.

Create any 3D model fast by prompting in ChatGPT without using a CAD system. Create parts in STEP or STL format for manufacturing.

AdvancedFull instructions provided2 hours4,369
Design any part with ChatGPT for 3D printing.

Things used in this project

Hardware components

SMA socket
×1

Software apps and online services

3D-Designer

Story

Read more

Custom parts and enclosures

U-Bracket: STEP file generated by a script coded by 3D-Designer

View in CAD Viewer of your choice and save as STL-File for 3D slicing and printing.

5.8-GHz-WiFi-Hornantenna STEP-File

STEP file of the generated horn antenna.

Code

u_bracket__example_file_generated_by_3d_designer_V2.py

Python
Example Python script for generating a bracket.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Generated with ChatGPT-4 by OpenAI
# Date: 2024-02-10

import OCC.Core.BRepPrimAPI as BRepPrimAPI
import OCC.Core.BRepAlgoAPI as BRepAlgoAPI
import OCC.Core.BRepBuilderAPI as BRepBuilderAPI
import OCC.Core.gp as gp
import OCC.Display.SimpleGui as SimpleGui
import OCC.Core.STEPControl as STEPControl

class UBracket:
    def __init__(self, outer_dimensions, inner_dimensions, hole_radius, hole_position, hole_length):
        self.outer_dimensions = outer_dimensions
        self.inner_dimensions = inner_dimensions
        self.hole_radius = hole_radius
        self.hole_position = hole_position
        self.hole_length = hole_length
        self.bracket_shape = self._create_bracket()

    def _create_bracket(self):
        # Create outer cube
        outer_cube = BRepPrimAPI.BRepPrimAPI_MakeBox(*self.outer_dimensions).Shape()

        # Create inner cube and shift it
        inner_cube = BRepPrimAPI.BRepPrimAPI_MakeBox(*self.inner_dimensions).Shape()
        trsf = gp.gp_Trsf()
        trsf.SetTranslation(gp.gp_Vec(5, 5, 0))  # Shift 5 mm right and up
        inner_cube_moved = BRepBuilderAPI.BRepBuilderAPI_Transform(inner_cube, trsf).Shape()

        # Subtract inner cube from outer cube
        u_shaped = BRepAlgoAPI.BRepAlgoAPI_Cut(outer_cube, inner_cube_moved).Shape()

        # Drill hole in x direction (1,0,0)
        hole_dir = gp.gp_Dir(1, 0, 0)  # Direction of the hole
        hole_axis = gp.gp_Ax2(gp.gp_Pnt(*self.hole_position), hole_dir)
        hole = BRepPrimAPI.BRepPrimAPI_MakeCylinder(hole_axis, self.hole_radius, self.hole_length).Shape()
        bracket_with_hole = BRepAlgoAPI.BRepAlgoAPI_Cut(u_shaped, hole).Shape()

        return bracket_with_hole

    def display(self):
        display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()
        display.DisplayShape(self.bracket_shape, transparency=0.5, color="BLUE")
        start_display()

    def export_step(self, filename):
        step_writer = STEPControl.STEPControl_Writer()
        step_writer.Transfer(self.bracket_shape, STEPControl.STEPControl_AsIs)
        status = step_writer.Write(filename)
        if status != STEPControl.STEPControl_Done:
            raise Exception("Error in exporting STEP file")

def main():
    outer_dimensions = (40, 30, 20)
    inner_dimensions = (30, 30, 20)
    hole_radius = 3
    hole_position = (0, 20, 10)
    hole_length = 10

    ubracket = UBracket(outer_dimensions, inner_dimensions, hole_radius, hole_position, hole_length)
    ubracket.display()
    ubracket.export_step("ubracket.stp")

if __name__ == "__main__":
    main()

Credits

Axel Richter

Axel Richter

1 project • 3 followers
Senior EE and tech enthusiast.

Comments