• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python library to generate OpenSCAD source code. This library provides intuitive interface when you handle 3D data.

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.

More Repositories

1

pymesh

Library for manipulating (Translate, Rotate and Scale) 3D data using numpy. Currently, this library supports STL & OBJ.
Python
47
star
2

b2mine

Blender add-on to convert object into colored blocks and transfer it to minecraft
Python
13
star
3

pyomni

Python library to manipulate omnifocus
Python
12
star
4

PolymerForm

PolymerForm is jQuery plugin that enables you to change HTML input style from ordinary style to polymer-like style.
HTML
8
star
5

convert-svg-path-to-polygon

Sample source to convert svg path to svg polygon by sampling points on the path.
Java
7
star
6

pyzxcvbn

Python version library of zxcvbn
Python
5
star
7

ng2-swagger-example

Example of angular2 and swagger codegen
JavaScript
4
star
8

godu

Alternative du command with useful option implemented by golang
Go
4
star
9

fusion360-learnings-expander

Expand fusion360 learning page in order to read contents easily
JavaScript
3
star
10

ModelUtils

Calculator for 3d model (.obj, .stl) implemented with Java
Java
3
star
11

pytidy

Python DI (Dependency Injection) library using type annotation
Python
2
star
12

ndb_prop_gen

Google Appengine ndb Property Generater
Python
1
star
13

camo-pattern

Camouflage Pattern Generator
TypeScript
1
star
14

stone

Stone language Python implementation
Python
1
star
15

bravado-core-example

Examples of bravado-core
Python
1
star
16

flask-bravado-core

Example application of bravado-core (OpenAPI fka Swagger library) usage example in Flask application.
Python
1
star
17

tokyo-emblem

3D model data of Tokyo olympic 2020 emblem coded by OpenSCAD
OpenSCAD
1
star
18

angular2-simple-gulp-webpack

Simple Angular2 project pattern using gulp and webpack. This repository constructs the same application with official's 5 MIN QUICKSTART (https://angular.io/docs/ts/latest/quickstart.html).
JavaScript
1
star
19

CamCapture

Image capturing with iOS Device by using AVCaptureSession.
Objective-C
1
star
20

gopher

Download randomly generated gopher image from gopherize.me.
Python
1
star
21

similator

Application for 3331α art hack day http://arthackday.jp/
C
1
star
22

alc-save

You can add "Save" button in your ALC (http://www.alc.co.jp/) search result so that you can save your favorite words to your google spreadsheet for your English study.
TypeScript
1
star