Difference between revisions of "PythonScad"

From BITPlan Wiki
Jump to navigation Jump to search
 
(13 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
== Installation ==
 
== Installation ==
 
* Install {{Link|target=OpenSCAD}}
 
* Install {{Link|target=OpenSCAD}}
=== On MacOS ==
+
* Install viewscad <source lang='bash'>pip install viewscad</source>
 +
* Install jupyterlab <source lang='bash'>pip install jupyterlab</source> see https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html
 +
=== On MacOS ===
 
create script $HOME/openscad
 
create script $HOME/openscad
 
<source lang='bash'>
 
<source lang='bash'>
Line 12: Line 14:
 
# call OpenSCAD command line
 
# call OpenSCAD command line
 
/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD $@
 
/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD $@
 +
</source>
 +
=== check version ===
 +
<source lang='bash'>
 +
openscad -v
 +
OpenSCAD version 2021.01
 +
npm --version
 +
8.8.0
 +
jupyter labextension list
 +
JupyterLab v3.4.7
 +
/Users/wf/Library/Python/3.10/share/jupyter/labextensions
 +
        jupyter-threejs v2.4.0 enabled OK (python, pythreejs)
 +
        jupyterlab-datawidgets v7.1.2 enabled OK
 +
        jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
 +
        @jupyter-widgets/jupyterlab-manager v5.0.3 enabled OK (python, jupyterlab_widgets)
 +
 +
Other labextensions (built into JupyterLab)
 +
  app dir: /Users/wf/Library/Python/3.10/share/jupyter/lab
 
</source>
 
</source>
  
 +
== start ==
 
<source lang='bash'>
 
<source lang='bash'>
jupyter labextension install jupyter-threejs
+
jupyter lab
 +
</source>
 +
== Example ==
 +
<source lang='python'>
 +
# cell 1
 +
from solid import *
 +
import viewscad
 +
r=viewscad.Renderer()
 +
# cell 2
 +
c=cylinder(r=5,h=2)
 +
c-=minkowski()(translate([0,0,1]) (cylinder(r=3,h=1.5)),sphere(r=0.2))
 +
c-=cylinder(r=1,h=3,center=True)
 +
c-=translate([0,-1,0]) (cube([6,2,3]))
 +
r.render(c)
 
</source>
 
</source>
 +
[[File:viewscad_example_2022-09-22.png|400px]]
 +
 +
= Videos =
 +
== Minkowski ==
 +
 
<youtube>lPgLZgnbREk&t=46s</youtube>
 
<youtube>lPgLZgnbREk&t=46s</youtube>
 
[[Category:3DPrint]]
 
[[Category:3DPrint]]

Latest revision as of 07:09, 22 September 2022

ViewSCAD

Installation

On MacOS

create script $HOME/openscad

#!/bin/bash
# call OpenSCAD command line
/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD $@

check version

openscad -v
OpenSCAD version 2021.01
npm --version
8.8.0
jupyter labextension list
JupyterLab v3.4.7
/Users/wf/Library/Python/3.10/share/jupyter/labextensions
        jupyter-threejs v2.4.0 enabled OK (python, pythreejs)
        jupyterlab-datawidgets v7.1.2 enabled OK
        jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
        @jupyter-widgets/jupyterlab-manager v5.0.3 enabled OK (python, jupyterlab_widgets)

Other labextensions (built into JupyterLab)
   app dir: /Users/wf/Library/Python/3.10/share/jupyter/lab

start

jupyter lab

Example

# cell 1
from solid import *
import viewscad
r=viewscad.Renderer()
# cell 2
c=cylinder(r=5,h=2)
c-=minkowski()(translate([0,0,1]) (cylinder(r=3,h=1.5)),sphere(r=0.2))
c-=cylinder(r=1,h=3,center=True)
c-=translate([0,-1,0]) (cube([6,2,3]))
r.render(c)

Viewscad example 2022-09-22.png

Videos

Minkowski