Skip to main content

Build Status Coverage Status Python3

OpenPySCAD

Python library to generate OpenSCAD source code. This library provides intuitive interface when you handle 3D data. OpenPySCAD supports python3(3.5+).

Install

pip install openpyscad

How to use

  • Write python code as follows:
import openpyscad as ops
c1 = ops.Cube([10, 20, 10])
c2 = ops.Cube([20, 10, 10])
(c1 + c2).write("sample.scad")
  • Generated code will be written in the "sample.scad".
  • For automatic reload and preview, you need to turn on "Design > Automatic Reload and Preview" in OpenSCAD
union(){
    cube([10, 20, 10]);
    cube([20, 10, 10]);
};

Generated code examples

3D Shapes

Python:

Sphere(r=10, _fn=100)
Cube([10, 10, 10])
Cylinder(h=10, r=10)
p = 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],  [1, 0, 3], [2, 1, 3]
    ]
)

Generated OpenSCAD code:

sphere(r=10, $fn=100);
cube(size=[10, 10, 10]);
cylinder(h=10, r=10);
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], [1, 0, 3], [2, 1, 3]]);

Boolean Operations

Python:

# Union
Cube([20, 10, 10]) + Cube([10, 20, 10])

# You can also write like this
u = Union()
u.append(Cube[20, 10, 10])
u.append(Cube[10, 20, 10])

# Difference
Cube([20, 10, 10]) - Cube([10, 20, 10])

# You can also write like this
i = Difference()
i.append(Cube[20, 10, 10])
i.append(Cube[10, 20, 10])

# Intersection
Cube([20, 10, 10]) & Cube([10, 20, 10])

# You can also write like this
i = Intersection()
i.append(Cube[20, 10, 10])
i.append(Cube[10, 20, 10])

Generated OpenSCAD code:

// Union
union(){
    cube([20, 10, 10])
    cube([10, 20, 10])
};

// Difference
difference(){
    cube([20, 10, 10]);
    cube([10, 20, 10]);
};

// Intersection
intersection(){
    cube([20, 10, 10]);
    cube([10, 20, 10]);
};

Transformations

Python:

# Translate
Cube([20, 10, 10]).translate([10, 10, 10])

# Rotate
Cube([20, 10, 10]).rotate([0, 0, 45])

# Scale
Cube([20, 10, 10]).scale([2, 1, 1])

# Resize
Cube([20, 10, 10]).resize([2, 1, 1])

# Mirror
Cube([20, 10, 10]).mirror([1, 1, 1])

# Color
Cube([20, 10, 10]).color("Red")

# Offset
Circle(10).offset(10)

Generated OpenSCAD code:

// Translate
translate(v=[10, 10, 10]){
    cube([20, 10, 10]);
};

// Rotate
rotate(v=[0, 0, 45]){
    cube([20, 10, 10]);
};

// Scale
scale(v=[2, 1, 1]){
    cube([20, 10, 10]);
};

// Resize
resize(newsize=[2, 1, 1]){
    cube(size=[20, 10, 10]);
};

// Mirror
mirror([1, 1, 1]){
    cube(size=[20, 10, 10]);
};

// Color
color("Red"){
    cube(size=[20, 10, 10]);
};

// Offset
offset(r=10){
    circle(r=10);
};

Modifiers

OpenPySCAD provides modifiers interfaces ("*", "!", "#" and "%").

Python:

c1 = Cube(10)
c1.disable()         # add "*" character
c1.show_only()       # add "!" character
c1.is_debug()        # add "#" character
c1.is_transparent()  # add "&" character

Interested in contribution?

Please read CONTRIBUTING.md.

Release files for openpyscad 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openpyscad 0.5.0
File Size Uploaded
openpyscad-0.5.0.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openpyscad 0.5.0
File Interpreter ABI Platform
openpyscad-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.8 kB

Release files / openpyscad-0.5.0.tar.gz

Download URL openpyscad-0.5.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2e1ea8eb10fe9e9c31c8bc5941c1ef6294e3400e4ae4b23133ce2275124d1c9b
BLAKE2b-256 checksum
How to use checksums
964c536b7bacb6df08943d2da6fe4fcb6ccb1e7c7a196eb15d3c40b8cd4624c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.5.10 Linux/4.15.0-1077-gcp

Release files / openpyscad-0.5.0-py3-none-any.whl

Download URL openpyscad-0.5.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ce23ffdb1a3d41ca0589ca813ba8d96063f4faaf0bfb0d902f5cd5df54f899c
BLAKE2b-256 checksum
How to use checksums
e788c845e63950670a56b00ef6873aa9aae327a0d73f59714d682a2c3ea81d8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.5.10 Linux/4.15.0-1077-gcp

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.2

3 release files

0.1.1

1 release file

0.1.0

3 release files

0.0.2

3 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page