pythonscad from commandline

9 views
Skip to first unread message

Matthieu Hendriks

unread,
Oct 5, 2025, 10:35:53 AMOct 5
to PythonSCAD
Is it possible and if yes how to start pythonscad from the commandline and passing some parameters like with openscad:

Something like: 
pythonscad -q  -D 'label="LabelTekst"'  labels.py -o labels.3mf

And is it also possible to do a lazy union so multiple objects can be recognized als different objects with different color for the (bambu) 3d printer?



Guenther Sohler

unread,
Oct 6, 2025, 4:50:57 AMOct 6
to Matthieu Hendriks, PythonSCAD
This functionality was there already, but got somehow lost

Now we have it again in the latest version. in the git master branch
you can write:

pythonscad --trust-python -D't="Hello"' model.py -o model.3mf

Of course you can also put  several objects into the same 3mf file, but this requires
use of export() function in the python script.




--
You received this message because you are subscribed to the Google Groups "PythonSCAD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonscad+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/pythonscad/a2dd22a3-c1fd-4103-a256-d5b39cf16296n%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthieu Hendriks

unread,
Oct 17, 2025, 10:37:18 AMOct 17
to PythonSCAD
pythonscad --trust-python -D'run="all"' -D'label="rabbit"' planklabel.py -o "rabbit.3mf"

I think the values are not transferred to the py program. When running above command  the variables are stil the default value. 

Some hints to solve this?

It's a very simple program to create plant-labels.

#####################
# Title: planklabel  
# Author: Matthieu Hendriks
# Date: 2025-10-05
# License: t.b.d
#
#####################
# Title: planklabel  
# start include section
#####################
# Title: planklabel  
from python.mhlib.mhlib import *
from python.mhscrews.mhscrews import *
import os

#####################
# start constants section
#####################
# constants
fn=128;
run="all"
xPlank=120
wall=2
yPlank=22
zVleugel=100
xVleugel=80
label="Knoflook"
#####################
# start module section
#####################

label="Konijn"
print(label)
def zijde(r=90):
    obj=mvz(rotx(mvz(triangle(xVleugel,zVleugel,d=5,z=wall),-wall/2),r),5/2)
    return(obj)
def top():
    obj=plate(x=xPlank,y=yPlank+2*wall,z=wall,d=5)
    return(obj)

def print_label():
    o1=mv(zijde(r=87),0,-yPlank/2-wall/2+0.2,0.4)
    o2=top()
    o3=mv(zijde(r=93),0,yPlank/2+wall/2-0.2,0.4)

    o4=union(o1,o2,o3)
    obj=difference(o4,print_text())
    return(obj)

def print_text(txt=label,size=14,h=1):
    t = text(txt, size=size, font="Liberation Sans", halign="center", valign="center")
    obj =roty( mvz(color(linear_extrude(t,height=h),"Red"),-h),180)
    return(obj)

def print_zijde():
    obj=triangle(xPlank-5,zVleugel,d=5,z=wall)
    return (obj)
#####################
# start run section
#####################
# runstart Start:autogenerated run file
os.makedirs("/home/matthieu/pyscad_drawings/slicer_files/planklabel", exist_ok=True)
parts={}
parts["text"]=print_text()
parts["label"]=print_label()
num=1
fname=label.strip(' ')
for name, obj in parts.items():
    path = f"/home/matthieu/pyscad_drawings/slicer_files/planklabel/{name}.3mf"
    export(obj, path)
    num=num+1
    export(obj, path)

if run == "all":
    show(list(parts.values()))
    path=f"/home/matthieu/pyscad_drawings/slicer_files/planklabel/planklabel_{fname}.3mf"
    export(parts, path)
else:
    show(parts[run])


# runeind End:autogenerated run file

Op maandag 6 oktober 2025 om 10:50:57 UTC+2 schreef guenthe...@gmail.com:

Matthieu Hendriks

unread,
Oct 17, 2025, 10:49:59 AMOct 17
to PythonSCAD
Never mind, found it:

add_parameter("label","Garlic")

Op vr 17 okt 2025 om 16:37 schreef Matthieu Hendriks <matthieu...@gmail.com>:

Matthieu Hendriks

unread,
Oct 17, 2025, 11:11:08 AMOct 17
to PythonSCAD
I thought I solved it with the add_parameter("label","default") and then  the commandline : pythonscad --trust-python -D'label="rabbit"' planklabel.py -o t.3mf

But the value wasn't transferred to label, so I think  it's a bug.

I tried passing the label on many ways, al ending in an error or the deault value and not the passed value.

I'm running on linux, compiled the latest version.
####
yPlank=22
zVleugel=100
xVleugel=80
add_parameter("label","Knoflook")
add_parameter("run","all")

#####################
# start module section
#####################

print("Werkelijke waarde tijdens runnen:"+label)


Op vr 17 okt 2025 om 16:37 schreef Matthieu Hendriks <matthieu...@gmail.com>:
pythonscad --trust-python -D'run="all"' -D'label="rabbit"' planklabel.py -o "rabbit.3mf"
Reply all
Reply to author
Forward
0 new messages