@ -11,7 +11,7 @@
}
},
"source": [
"from build123d import * \n",
"\n",
"from ocp_vscode import show\n",
"\n",
"\n",
@ -20,6 +20,7 @@
" Box(10, 30, 20)\n",
" return p.part\n",
"\n",
"\n",
"show(make_test())"
],
"outputs": [
@ -44,29 +45,32 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-05-12T15:43:51.244991561 Z",
"start_time": "2026-05-12T15:43:51.223161624 Z"
"end_time": "2026-05-12T19:20:08.027100644 Z",
"start_time": "2026-05-12T19:20:07.828843337 Z"
}
},
"cell_type": "code",
"source": [
"from build123d import *\n",
"from ocp_vscode import *\n",
"\n",
"vis_diam = 4 + 1\n",
"vis_ecrou_diam = 7 + 2\n",
"vis_longueur = 15\n",
"vis_ecrou_hauteur = 3.2 + 0.15\n",
"with BuildPart() as p:\n",
" Box(15, 15, vis_longueur)\n",
" top_face = faces().filter_by(Plane.XY).filter_by(Axis.Z)[-1]\n",
" with Locations(top_face) as sk:\n",
" # Position relative au centre de la face (origine du sketch)\n",
" Hole(radius=vis_diam / 2, depth=vis_longueur - 1)\n",
" with BuildSketch(Plane(top_face).offset(-10)) as sk:\n",
" RegularPolygon(radius=vis_ecrou_diam / 2, side_count=6)\n",
"\n",
" extrude(amount=-vis_ecrou_hauteur, mode=Mode.SUBTRACT)\n",
"\n",
"# Créer une face plate (exemple : un carré dans le plan XY)\n",
"box = Box(10, 10, 10)\n",
"face = box.faces().filter_by(Plane.YX).sort_by(Axis.Z)[0]\n",
"print(face.center())\n",
"print(\"Normal avant inversion :\", face.orientation) # Affiche le vecteur normal (ex: (0, 0, 1))\n",
"\n",
"# Inverser le vecteur normal\n",
"face_reversed = -face\n",
"print(\"Normal après inversion :\", face_reversed.orientation) # Affiche le vecteur normal inversé\n",
"\n",
"print(Plane(face))\n",
"print(Plane(face).reverse())\n",
"print(Plane.XY)\n",
"print(Plane.XY.reverse())\n",
"print(Plane.YX)"
"show(p.part)\n",
"export_stl(p.part, \"/tmp/test_ecrou.stl\")"
],
"id": "7450390859017a41",
"outputs": [
@ -74,18 +78,95 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Vector(0, 0, -5)\n",
"Normal avant inversion : Vector(0, 0, 0)\n",
"Normal après inversion : Vector(0, 0, 0)\n",
"Plane(o=(0.00, 0.00, -5.00), x=(1.00, 0.00, 0.00), z=(-0.00, -0.00, -1.00))\n",
"Plane(o=(0.00, 0.00, -5.00), x=(1.00, 0.00, 0.00), z=(0.00, 0.00, 1.00))\n",
"Plane(o=(0.00, 0.00, 0.00), x=(1.00, 0.00, 0.00), z=(0.00, 0.00, 1.00))\n",
"Plane(o=(0.00, 0.00, 0.00), x=(1.00, 0.00, 0.00), z=(-0.00, -0.00, -1.00))\n",
"Plane(o=(0.00, 0.00, 0.00), x=(0.00, 1.00, 0.00), z=(0.00, 0.00, -1.00))\n"
"+\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 23
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2026-05-12T20:49:38.331665787Z",
"start_time": "2026-05-12T20:49:38.112592978Z"
}
},
"cell_type": "code",
"source": [
"from build123d import *\n",
"from ocp_vscode import *\n",
"\n",
"encoche_profondeur = 4\n",
"encoche_longueur = 20\n",
"encoche_largueur = 10 / 3\n",
"\n",
"with BuildPart() as p_top:\n",
" Box(30, 10, 10)\n",
" bottom_face = faces().filter_by(Plane.XY).sort_by(Axis.Z)[0]\n",
" bottom_plane = Plane(\n",
" origin=(0, 0, bottom_face.center().Z),\n",
" z_dir=(0, 0, 1)\n",
" )\n",
" with BuildSketch(bottom_plane):\n",
" Rectangle(encoche_longueur, encoche_largueur)\n",
" extrude(amount=encoche_profondeur, mode=Mode.SUBTRACT)\n",
"\n",
" top_edges = edges(Select.LAST).filter_by_position(Axis.Z,\n",
" minimum=bottom_plane.origin.Z + encoche_profondeur - 0.01,\n",
" maximum=bottom_plane.origin.Z + encoche_profondeur )\n",
" print(top_edges)\n",
" chamfer(top_edges, length=1)\n",
"\n",
"with BuildPart() as p_bottom:\n",
" Box(30, 10, 10)\n",
" top_face = faces().filter_by(Plane.XY).sort_by(Axis.Z)[-1]\n",
" top_plane = Plane(\n",
" origin=(0, 0, top_face.center().Z),\n",
" z_dir=(0, 0, 1)\n",
" )\n",
" with BuildSketch(top_plane):\n",
" Rectangle(encoche_longueur - 0.3, encoche_largueur - 0.3)\n",
" extrude(amount=encoche_profondeur - 0.3, mode=Mode.ADD)\n",
" top_edges = edges(Select.LAST).filter_by_position(Axis.Z, minimum=top_plane.origin.Z + encoche_profondeur / 2,\n",
" maximum=top_plane.origin.Z + encoche_profondeur * 2)\n",
" chamfer(top_edges, length=1)\n",
"\n",
"c = Compound(children=[p_top.part, p_bottom.part])\n",
"show(p_top, p_bottom)\n",
"export_step(c, \"/tmp/test_emboitement.step\")"
],
"id": "daba6eff56e1a97c",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[<build123d.topology.one_d.Edge object at 0x7edf3047ded0>, <build123d.topology.one_d.Edge object at 0x7edf3047e2d0>, <build123d.topology.one_d.Edge object at 0x7edf3047f190>, <build123d.topology.one_d.Edge object at 0x7edf3047d510>]\n",
"c+\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 13
"execution_count": 48
},
{
"metadata": {