### Install Viewer Dependencies Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/README.md Installs the necessary Python packages for the PyOpenSCAD viewer examples, including PyOpenGL, PyOpenGL-accelerate, PyGLM, and manifold3d. ```bash pip install PyOpenGL PyOpenGL-accelerate PyGLM manifold3d ``` -------------------------------- ### Run OpenSCAD Offset Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Command to run the PythonOpenSCAD example for offset in a viewer. ```bash python -m pythonopenscad.examples.gists_transforms.offset_example --view ``` -------------------------------- ### Run Basic Viewer Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/README.md Demonstrates creating and displaying 3D models using the PyOpenSCAD viewer. Requires PyOpenGL, PyOpenGL-accelerate, and PyGLM. ```python python viewer_example.py ``` -------------------------------- ### Install PythonOpenScad Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Installs the PythonOpenScad library using pip. Requires Python 3.10 or later. ```bash pip install pythonopenscad ``` -------------------------------- ### Run OpenSCAD Rotate Extrude Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Command to run the PythonOpenSCAD example for rotate extrude in a viewer. ```bash python -m pythonopenscad.examples.gists_transforms.rotate_extrude_example --view ``` -------------------------------- ### Run OpenSCAD Combine Modifiers Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md Command to run the OpenSCAD combine modifiers example using the pythonopenscad library. ```bash python -m pythonopenscad.examples.gists_other.modifier_combinations_example --view ``` -------------------------------- ### Run M3D Renderer Integration Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/README.md Shows integration with M3dRenderer for visualizing Manifold3D objects, including complex shapes using CSG operations. Requires PyOpenGL, PyOpenGL-accelerate, PyGLM, and manifold3d. ```python python m3d_viewer_example.py ``` -------------------------------- ### Run OpenSCAD Debug Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md Command to run the OpenSCAD debug modifier example using the pythonopenscad library. ```bash python -m pythonopenscad.examples.gists_other.modifier_debug_example --view ``` -------------------------------- ### OpenSCAD Combine Modifiers Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md Demonstrates combining modifiers (# and %) in OpenSCAD to control rendering and visibility. This example shows a cube and a sphere with different colors and combined modifiers. ```openscad union() { color(c="limegreen") { cube(size=10.0); } #%color(c="violet") { sphere(r=7.0); } } ``` -------------------------------- ### OpenSCAD Offset Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md OpenSCAD code equivalent to the Python Offset example. It uses the difference operation to subtract a square from an offset square, illustrating the offset functionality. ```openscad difference() { offset(delta=2.0, chamfer=false) { square(size=10.0); } square(size=10.0); } ``` -------------------------------- ### Hull Operation Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Hull operation in PythonOpenSCAD, which creates a convex hull around multiple objects. This example hulls a red sphere and a blue cube. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Color, Cube, Hull, Sphere, Translate MODEL = Hull()( Color("red")(Translate([-10,0,0])(Sphere(r=5))), Color("blue")(Translate([10,0,0])(Cube([1,1,15], center=True))) ) ``` ```openscad hull() { color(c="red") { translate(v=[-10.0, 0.0, 0.0]) { sphere(r=5.0); } } color(c="blue") { translate(v=[10.0, 0.0, 0.0]) { cube(size=[1.0, 1.0, 15.0], center=true); } } } ``` -------------------------------- ### Create Cube Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_3d/README.md Generates a 3D cube with specified dimensions and center alignment. This example uses the `Cube` class from the pythonopenscad library. ```python from pythonopenscad import Cube MODEL = Cube(size=[10, 15, 5], center=True) ``` ```openscad cube(size=[10.0, 15.0, 5.0], center=true); ``` ```bash python -m pythonopenscad.examples.gists_3d.cube_example --view ``` -------------------------------- ### Minkowski Sum Operation Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Minkowski sum operation in PythonOpenSCAD, which adds the shapes of two objects together. This example combines a square and a circle. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Circle, Minkowski, Square MODEL = Minkowski()(Square([10, 2]), Circle(r=2)) ``` ```openscad minkowski() { square(size=[10.0, 2.0]); circle(r=2.0); } ``` -------------------------------- ### OpenSCAD Modifier Debug Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md Demonstrates the use of the DEBUG modifier (#) in OpenSCAD to control rendering. This example combines a cube and a sphere with different colors and modifiers. ```openscad union() { color(c="limegreen") { cube(size=10.0); } #color(c="violet") { sphere(r=7.0); } } ``` -------------------------------- ### Create Sphere Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_3d/README.md Generates a 3D sphere with a given radius and resolution. This example utilizes the `Sphere` class from the pythonopenscad library. ```python from pythonopenscad import Sphere MODEL = Sphere(r=10, _fn=128) ``` ```openscad sphere(r=10.0, $fn=128); ``` ```bash python -m pythonopenscad.examples.gists_3d.sphere_example --view ``` -------------------------------- ### Modules and LazyUnion in PythonOpenSCAD Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md This example illustrates the use of Modules and LazyUnion in pythonopenscad for code organization and reusability. It defines and reuses modules, demonstrating how LazyUnion optimizes the output by processing modules only once. ```python from pythonopenscad import Cube, Cylinder, LazyUnion, Module, Sphere, Translate MODEL = LazyUnion()( Module("my_module")(Sphere(r=10), Cylinder(h=12, r=4)), Module("my_other_module")( Translate([10, 0, 0])(Cube(10), Module("my_module")(Sphere(r=10), Cylinder(h=12, r=4))) ) ) # Notice the openscad version of this code only shows up once: # Module("my_module")(Sphere(r=10), Cylinder(h=12, r=4)) # This allows for more compact code and less duplicated processing. ``` ```openscad // Start: lazy_union my_module(); my_other_module(); // End: lazy_union // Modules. module my_module() { sphere(r=10.0); cylinder(h=12.0, r=4.0, center=false); } // end module my_module module my_other_module() { translate(v=[10.0, 0.0, 0.0]) { cube(size=10.0); my_module(); } } // end module my_other_module ``` ```bash python -m pythonopenscad.examples.gists_other.modules_example --view ``` -------------------------------- ### Create Polyhedron Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_3d/README.md Generates a 3D polyhedron from a list of points and faces. This example utilizes the `Polyhedron` class from the pythonopenscad library. ```python from pythonopenscad import Polyhedron MODEL = Polyhedron( points=[[10,10,0],[10,-10,0],[-10,-10,0],[-10,10,0], [0,0,10]], faces=[[0,1,4],[1,2,4],[2,3,4],[3,0,4], [3,2,1,0]] ) ``` ```openscad polyhedron(points=[[10.0, 10.0, 0.0], [10.0, -10.0, 0.0], [-10.0, -10.0, 0.0], [-10.0, 10.0, 0.0], [0.0, 0.0, 10.0]], faces=[[0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [3, 2, 1, 0]], convexity=10); ``` ```bash python -m pythonopenscad.examples.gists_3d.polyhedron_example --view ``` -------------------------------- ### Create Cylinder Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_3d/README.md Generates a 3D cylinder with specified height, radii, and center alignment. This example uses the `Cylinder` class from the pythonopenscad library. ```python from pythonopenscad import Cylinder MODEL = Cylinder(h=20, r1=5, r2=10, center=True, _fn=128) ``` ```openscad cylinder(h=20.0, r1=5.0, r2=10.0, center=true, $fn=128); ``` ```bash python -m pythonopenscad.examples.gists_3d.cylinder_example --view ``` -------------------------------- ### Mirror Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a mirroring transformation to a cube. This example demonstrates mirroring a shape across a plane and combining it with other transformations and colors. ```python from pythonopenscad import Color, Cube, Mirror, Translate MODEL = Mirror([1, 1, 0])(Translate([10, 0, 0])(Color('green')(Cube(size=5)))) \ + Translate([10, 0, 0])(Color('red')(Cube(size=5))).setMetadataName("not mirrored") ``` ```openscad union() { mirror(v=[1.0, 1.0, 0.0]) { translate(v=[10.0, 0.0, 0.0]) { color(c="green") { cube(size=5.0); } } } // 'not mirrored' translate(v=[10.0, 0.0, 0.0]) { color(c="red") { cube(size=5.0); } } } ``` ```bash python -m pythonopenscad.examples.gists_transforms.mirror_example --view ``` -------------------------------- ### Python Offset Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Python code using PythonOpenSCAD to create an offset shape. It subtracts a square from an offset version of another square, demonstrating the Offset and Square modules. ```python from pythonopenscad import Offset, Square MODEL = Offset(delta=2)(Square(10)) - Square(10) ``` -------------------------------- ### Union Operation (Functional) Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Union operation using the functional approach in PythonOpenSCAD. It combines a red cube and a blue sphere. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Color, Cube, Sphere, Translate, Union MODEL = Union()( Color("red")(Cube(10)), Color("blue")(Translate([5,5,5])(Sphere(r=7))) ) ``` ```openscad union() { color(c="red") { cube(size=10.0); } color(c="blue") { translate(v=[5.0, 5.0, 5.0]) { sphere(r=7.0); } } } ``` -------------------------------- ### Snake Case Style in PythonOpenSCAD Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md This example showcases the use of snake_case style for functions in pythonopenscad, aligning with Python conventions. It demonstrates a difference operation between a colored cube and a colored sphere. ```python from pythonopenscad import color, cube, difference, sphere MODEL = difference()( color("red")(cube(10, center=True)), color("blue")(sphere(r=7)) ) ``` ```openscad difference() { color(c="red") { cube(size=10.0, center=true); } color(c="blue") { sphere(r=7.0); } } ``` ```bash python -m pythonopenscad.examples.gists_other.snake_case_style_example --view ``` -------------------------------- ### Union Operation (Operator) Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Union operation using the '+' operator in PythonOpenSCAD. It combines a red cube and a blue sphere. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Color, Cube, Sphere, Translate MODEL = Color('red')(Cube(10)) + Color('blue')(Translate([5,5,5])(Sphere(r=7))) ``` ```openscad union() { color(c="red") { cube(size=10.0); } color(c="blue") { translate(v=[5.0, 5.0, 5.0]) { sphere(r=7.0); } } } ``` -------------------------------- ### Linear Extrude Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a linear extrude transformation to a square. This example demonstrates extruding a 2D shape into 3D with options for height, center, scale, and twist. ```python from pythonopenscad import Linear_Extrude, Square MODEL = Linear_Extrude(height=5, center=True, scale=0.5, twist=90)(Square(10)) ``` ```openscad linear_extrude(height=5.0, center=true, twist=90.0, scale=0.5) { square(size=10.0); } ``` ```bash python -m pythonopenscad.examples.gists_transforms.linear_extrude_example --view ``` -------------------------------- ### Multmatrix Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a transformation matrix to a cube. This example demonstrates complex transformations using Multmatrix in PythonOpenSCAD and 'multmatrix' in OpenSCAD. ```python from pythonopenscad import Cube, Multmatrix MODEL = Multmatrix(m=[ [1, 0.5, 0, 5], [0, 1, 0.5, 10], [0.5, 0, 1, 0], [0, 0, 0, 1] ])(Cube(size=10)) ``` ```openscad multmatrix(m=[[1.0, 0.5, 0.0, 5.0], [0.0, 1.0, 0.5, 10.0], [0.5, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]) { cube(size=10.0); } ``` ```bash python -m pythonopenscad.examples.gists_transforms.multmatrix_example --view ``` -------------------------------- ### Projection Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a projection transformation to a combination of cube and sphere. This example uses Projection in PythonOpenSCAD and 'projection' in OpenSCAD. ```python from pythonopenscad import Cube, Projection, Sphere, Translate MODEL = Projection(cut=True)(Cube(7) + Translate([0,0,2.5])(Sphere(r=5))) ``` ```openscad projection(cut=true) { union() { cube(size=7.0); translate(v=[0.0, 0.0, 2.5]) { sphere(r=5.0); } } } ``` ```bash python -m pythonopenscad.examples.gists_transforms.projection_example --view ``` -------------------------------- ### Resize Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a resize transformation to a sphere, changing its dimensions to a new size. This example uses Resize in PythonOpenSCAD and 'resize' in OpenSCAD. ```python from pythonopenscad import Resize, Sphere MODEL = Resize(newsize=[30, 10, 5])(Sphere(r=5)) ``` ```openscad resize(newsize=[30.0, 10.0, 5.0]) { sphere(r=5.0); } ``` ```bash python -m pythonopenscad.examples.gists_transforms.resize_example --view ``` -------------------------------- ### OpenSCAD Rotate Extrude Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Demonstrates how to use rotate_extrude in OpenSCAD to create a 3D shape by rotating a 2D circle. The rotation is applied with a specified angle and resolution. ```openscad rotate_extrude(angle=270.0, $fn=128) { translate(v=[5.0, 0.0, 0.0]) { circle(r=2.0); } } ``` -------------------------------- ### Python OpenSCAD Modifier Debug Example Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md Python code to create an OpenSCAD model with a colored cube and sphere, applying the DEBUG modifier to the sphere. ```python from pythonopenscad import BACKGROUND, Color, Cube, DEBUG, Sphere MODEL = Color("limegreen")(Cube(10)) + Color("violet")(Sphere(r=7)).add_modifier(DEBUG, BACKGROUND) ``` -------------------------------- ### Lazy Union and Module Usage Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Demonstrates the use of `LazyUnion` and `Module` for creating complex models with shared components. `LazyUnion` acts as the top-level node, and `Module` allows for code reuse by abstracting repeated geometry. The example shows how PythonOpenSCAD automatically handles module name generation and collision resolution. ```python from pythonopenscad import LazyUnion, Module, Text, Translate thing1 = Text("Hello world!", size=15).linear_extrude(height=2).translate([-60, 20, 0]) thing2 = Text("Hello world 2!", size=15).linear_extrude(height=2).translate([-60, 0, 0]) print( LazyUnion()( Module("my_module")(thing1), Module("my_module")(thing2), Translate(v=[0, -40, 0])(Module("my_module")(thing1)), ) ) ``` ```openscad // Start: lazy_union my_module(); my_module_1(); translate(v=[0.0, -40.0, 0.0]) { my_module(); } // End: lazy_union // Modules. module my_module() { translate(v=[-60.0, 20.0, 0.0]) { linear_extrude(height=2.0) { text(text="Hello world!", size=15.0); } } } // end module my_module module my_module_1() { translate(v=[-60.0, 0.0, 0.0]) { linear_extrude(height=2.0) { text(text="Hello world 2!", size=15.0); } } } // end module my_module_1 ``` -------------------------------- ### Difference Operation (Functional) Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Difference operation using the functional approach in PythonOpenSCAD. It subtracts a blue sphere from a red cube. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Color, Cube, Difference, Sphere MODEL = Difference()( Color("red")(Cube(10, center=True)), Color("blue")(Sphere(r=7)) ) ``` ```openscad difference() { color(c="red") { cube(size=10.0, center=true); } color(c="blue") { sphere(r=7.0); } } ``` -------------------------------- ### Color Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a color transformation to a sphere. This example shows how to set the color of a shape using Color in PythonOpenSCAD and 'color' in OpenSCAD. ```python from pythonopenscad import Color, Sphere MODEL = Color("green")(Sphere(r=10)) ``` ```openscad color(c="green") { sphere(r=10.0); } ``` ```bash python -m pythonopenscad.examples.gists_transforms.color_example --view ``` -------------------------------- ### Scale Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a scaling transformation to a sphere. This example shows how to resize a shape along different axes using Scale in PythonOpenSCAD and 'scale' in OpenSCAD. ```python from pythonopenscad import Scale, Sphere MODEL = Scale([1.5, 1, 0.5])(Sphere(r=10)) ``` ```openscad scale(v=[1.5, 1.0, 0.5]) { sphere(r=10.0); } ``` ```bash python -m pythonopenscad.examples.gists_transforms.scale_example --view ``` -------------------------------- ### Translate Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a translation transformation to a cube. This example shows how to move a shape in 3D space using the Translate function in PythonOpenSCAD and the equivalent 'translate' in OpenSCAD. ```python from pythonopenscad import Cube, Translate MODEL = Translate([10, -10, 5])(Cube(size=5, center=True)) ``` ```openscad translate(v=[10.0, -10.0, 5.0]) { cube(size=5.0, center=true); } ``` ```bash python -m pythonopenscad.examples.gists_transforms.translate_example --view ``` -------------------------------- ### Difference Operation (Operator) Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Difference operation using the '-' operator in PythonOpenSCAD. It subtracts a blue sphere from a red cube. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Color, Cube, Sphere MODEL = Color('red')(Cube(10, center=True)) - Color('blue')(Sphere(r=7)) ``` ```openscad difference() { color(c="red") { cube(size=10.0, center=true); } color(c="blue") { sphere(r=7.0); } } ``` -------------------------------- ### Rotate Extrude Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a rotational extrude transformation to a translated circle. This example demonstrates creating 3D shapes by rotating a 2D profile around an axis. ```python from pythonopenscad import Circle, Rotate_Extrude, Translate MODEL = Rotate_Extrude(angle=270, _fn=128)(Translate([5,0,0])(Circle(r=2))) ``` -------------------------------- ### Rotate Shape Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_transforms/README.md Applies a rotation transformation to a cube. This example demonstrates rotating a shape around specified axes using Rotate in PythonOpenSCAD and 'rotate' in OpenSCAD. ```python from pythonopenscad import Cube, Rotate MODEL = Rotate([45, 45, 0])(Cube(size=[10, 15, 5])) ``` ```openscad rotate(a=[45.0, 45.0, 0.0]) { cube(size=[10.0, 15.0, 5.0]); } ``` ```bash python -m pythonopenscad.examples.gists_transforms.rotate_example --view ``` -------------------------------- ### Setting Global OpenSCAD Parameters Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Illustrates how to set global OpenSCAD parameters like `$fn`, `$fa`, and `$fs` using the `POSC_GLOBALS` object in PythonOpenSCAD. These global settings affect the resolution and quality of generated 3D models. The example also shows how to override these global settings for specific objects or during the code writing process. ```python from pythonopenscad import POSC_GLOBALS, Sphere # Set global parameters POSC_GLOBALS._fn = 50 # Use 50 fragments for all circular shapes POSC_GLOBALS._fa = 6 # Minimum angle of 6 degrees POSC_GLOBALS._fs = 0.5 # Minimum segment length of 0.5 # These will be included in the generated script header sphere = Sphere(r=10) print(sphere) # Will include "$fn = 50;" etc. at the top # Override global settings for specific objects sphere_high_res = Sphere(r=10, _fn=100) # This sphere uses 100 fragments # Override when writing/dumping sphere.write('output.scad', _fn=200) # Override global _fn when writing ``` -------------------------------- ### Intersection Operation (Operator) Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Intersection operation using the '*' operator in PythonOpenSCAD. It finds the intersection of a red cube and a blue sphere. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Color, Cube, Sphere MODEL = Color('red')(Cube(10, center=True)) * Color('blue')(Sphere(r=7)) ``` ```openscad intersection() { color(c="red") { cube(size=10.0, center=true); } color(c="blue") { sphere(r=7.0); } } ``` -------------------------------- ### Intersection Operation (Functional) Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_csg/README.md Demonstrates the Intersection operation using the functional approach in PythonOpenSCAD. It finds the intersection of a red cube and a blue sphere. The equivalent OpenSCAD code is also provided. ```python from pythonopenscad import Color, Cube, Intersection, Sphere MODEL = Intersection()( Color("red")(Cube(10, center=True)), Color("blue")(Sphere(r=7)) ) ``` ```openscad intersection() { color(c="red") { cube(size=10.0, center=true); } color(c="blue") { sphere(r=7.0); } } ``` -------------------------------- ### DEBUG Modifier (#) in PythonOpenSCAD Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md This example shows the DEBUG modifier (#) in pythonopenscad. It adds a Sphere with the DEBUG modifier to a union with a Cube, which typically highlights the object during debugging. ```python from pythonopenscad import Color, Cube, DEBUG, Sphere MODEL = Color("limegreen")(Cube(10)) + Color("violet")(Sphere(r=7)).add_modifier(DEBUG) ``` ```openscad # This is a placeholder for the OpenSCAD code that would correspond to the DEBUG modifier. # The exact representation might vary based on the OpenSCAD version and context. union() { color(c="limegreen") { cube(size=10.0); } #color(c="violet") { # sphere(r=7.0); #} } ``` -------------------------------- ### DISABLE Modifier (*) in PythonOpenSCAD Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md This example shows how to use the DISABLE modifier (*) in pythonopenscad. It adds a Sphere with the DISABLE modifier to a union with a Cube, effectively excluding the sphere from the final render. ```python from pythonopenscad import Color, Cube, DISABLE, Sphere MODEL = Color("limegreen")(Cube(10)) + Color("violet")(Sphere(r=7)).add_modifier(DISABLE) ``` ```openscad union() { color(c="limegreen") { cube(size=10.0); } *color(c="violet") { sphere(r=7.0); } } ``` ```bash python -m pythonopenscad.examples.gists_other.modifier_disable_example --view ``` -------------------------------- ### Create and Render a Simple Model Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Demonstrates creating a 3D model using PythonOpenScad primitives like Sphere and Cube, applying colors and transformations, saving to an OpenSCAD file, and rendering to an STL file using M3dRenderer. The posc_main function is used to view the model. ```python from pythonopenscad.posc_main import posc_main, PoscModel from pythonopenscad import PoscBase, Cube, translate, Sphere, Color from pythonopenscad.m3dapi import M3dRenderer # Create a simple model def make_model() -> PoscBase: return Sphere(r=10) - Color("red")( Cube([10, 10, 10]).translate([0, 2, 0]) ) - Color("cyan")(Cube([2, 2, 20])) model = make_model() # Save to OpenSCAD file model.write('my_model.scad') # Render to STL rc = model.renderObj(M3dRenderer()) rc.write_solid_stl("mystl.stl") # Or, view the result in a 3D viewer. posc_main([make_model]) ``` -------------------------------- ### Class Name Comparison (OpenPyScad vs. SolidPython) Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Demonstrates the equality check between equivalent classes from OpenPyScad (capitalized) and SolidPython (lowercase), showing that despite different naming conventions, they represent the same underlying objects. ```python >>> from pythonopenscad import Text, text >>> Text() == text() True >>> Text('a') == text() False ``` -------------------------------- ### PythonOpenScad Features Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Highlights key features of PythonOpenScad, including parameter validation, default value application, documentation links, support for OpenSCAD variables like $fn/$fa/$fs, and representation of objects as Python or OpenSCAD code. ```python Parameters are checked or converted and will raise exceptions if parameters are incompatible. OpenScad defaults are applied so getting attribute values will result in actual values. Documentation links to OpenScad reference docs can be found from help(object). $fn/$fa/$fs is supported everywhere it actually does something even though the docs don't say that they do. repr(object) works and produces python code. similarly str(object) produces OpenScad code. ``` -------------------------------- ### Generate Text Model (SolidPython Style) Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Generates OpenSCAD code for a 3D text model using the SolidPython style API. It extrudes text and applies a translation, demonstrating a different syntax for transformations. ```python from pythonopenscad import text, linear_extrude, translate print( translate(v=[-60, 0, 0]) ( linear_extrude(height=2) ( text(text='Hello world!', size=15) ), ) ) ``` -------------------------------- ### Create Text with pythonopenscad Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_2d/README.md Generates 2D text with specified content, size, font, and alignment using the pythonopenscad library. The resulting model is extruded to a depth of 1. ```python from pythonopenscad import Text MODEL = Text(text="POSC", size=10, font="Liberation Sans:style=Bold", halign="center") ``` ```openscad text(text="POSC", size=10.0, font="Liberation Sans:style=Bold", halign="center"); ``` ```bash python -m pythonopenscad.examples.gists_2d.text_example --view ``` -------------------------------- ### Generated OpenSCAD Code for Text Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md The OpenSCAD script generated by PythonOpenScad for creating a 3D text model. It showcases the syntax with transformations and nested structures. ```openscad // Generated OpenScad code translate(v=[-60.0, 0.0, 0.0]) { linear_extrude(height=2.0) { text(text="Hello world!", size=15.0); } } ``` -------------------------------- ### Generate Text Model (OpenPyScad Style) Source: https://github.com/owebeeone/pythonopenscad/blob/master/README.md Generates OpenSCAD code for a 3D text model using the OpenPyScad style API. It extrudes text and applies a translation. ```python from pythonopenscad import Text print( Text('Hello world!', size=15).linear_extrude(height=2) .translate([-60, 0, 0])) ``` -------------------------------- ### Create Square with pythonopenscad Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_2d/README.md Generates a 2D square with specified dimensions and centers it using the pythonopenscad library. The resulting model is extruded to a depth of 1. ```python from pythonopenscad import Square MODEL = Square(size=[15, 10], center=True) ``` ```openscad square(size=[15.0, 10.0], center=true); ``` ```bash python -m pythonopenscad.examples.gists_2d.square_example --view ``` -------------------------------- ### Create Circle with pythonopenscad Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_2d/README.md Generates a 2D circle with a specified diameter and number of facets using the pythonopenscad library. The resulting model is extruded to a depth of 1. ```python from pythonopenscad import Circle MODEL = Circle(d=10, _fn=64) ``` ```openscad circle(d=10.0, $fn=64); ``` ```bash python -m pythonopenscad.examples.gists_2d.circle_example --view ``` -------------------------------- ### BACKGROUND Modifier (%) in PythonOpenSCAD Source: https://github.com/owebeeone/pythonopenscad/blob/master/examples/gists_other/README.md This snippet demonstrates the use of the BACKGROUND modifier (%) in pythonopenscad. It applies a background color to a Sphere while rendering a Cube normally, using a difference operation. ```python from pythonopenscad import BACKGROUND, Color, Cube, Sphere MODEL = Color("limegreen")(Cube(10)) - Color("violet")(Sphere(r=7)).add_modifier(BACKGROUND) ``` ```openscad difference() { color(c="limegreen") { cube(size=10.0); } %color(c="violet") { sphere(r=7.0); } } ``` ```bash python -m pythonopenscad.examples.gists_other.modifier_background_example --view ```