r/OpenPythonSCAD • • Oct 25 '24

More center options on cube()

4 Upvotes

As cube() is a fundamental primitive which is needed in almost every design,

it makes sense to get more alignment options there.

Alternatively, now you can also specify a 3 character string to center, which specifies the alignment respect to the axes

-([< means : behind the origin

>]}+ means: in front of the origin

|0_ means: centered in respect to the origin

https://imgur.com/a/nzaY5Rf

Also its easy to move the cube with + or - operator and specifying 3d vector on the right hand side of the operator.


r/OpenPythonSCAD • • Nov 10 '24

append vs. union?

3 Upvotes

Just noticed append being used in the table example --- is there a reason to use it rather than union? Is there a meaningful difference?


r/OpenPythonSCAD • • Dec 29 '24

New experimental Fedora/Centos Package

3 Upvotes

Since today there is a new PythonSCAD RPM Package for download on the download package and its super slim(only 12 MB compressed) because it does not contain any other dependencies. (So more packages should be installed with DNF first)

(and it conflicts with openscad RPM package, because its a fork and literally uses the same files)

Still i am curious to learn, which packages are missing on other systems. Apparently All dependecies are met on mine ;)


r/OpenPythonSCAD • • Nov 30 '24

How to import Python class into OpenSCAD?

2 Upvotes

Okay, I now have:

https://github.com/WillAdams/gcodepreview/blob/main/gcodepreview.py

which works using:

https://github.com/WillAdams/gcodepreview/blob/main/gcodepreviewtemplate.py

or at least seems to be working:

https://forum.makerforums.info/t/rewriting-gcodepreview-with-python/88617/27

(I wonder if I was loading a local copy in the same directory rather than one from a Libraries folder....)

but this then raises the question --- how to access this w/in OpenSCAD?

One notable issue is that calling init as:

gcp = gcodepreview(Base_filename, #"export", basefilename
               True, #generategcode
               True, #generatedxf
               stockXwidth,
               stockYheight,
               stockZthickness,
               zeroheight,
               stockzero,
               retractheight,
               large_square_tool_num,
               toolradius,
               plunge,
               feed,
               speed)

requires access to a bunch of variables....

Is there something obvious I am missing? Or did I get the architecture wrong so that it will be necessary to have an init which doesn't involve any variables, then call multiple functions to pass in initial values and set things up?


r/OpenPythonSCAD • • Feb 18 '25

Status of import os?

3 Upvotes

Was this brought up before? I couldn't find that a note had been made on the wiki...

Obviously:

import os

# Get the current filename
current_filename = os.path.basename(__file__)

print(f"The current filename is: {current_filename}")

saved as "fntest.py" and then run yields:

The current filename is: fntest.py

when run in "normal" Python.

However, trying to run it in PythonSCAD yields:

ERROR: Traceback (most recent call last): File "<string>", line 4, in <module> NameError: name 'file' is not defined. Did you mean: 'name'?

Should "import os" work? If not, why not? (I promise to make a note in the wiki this time)

The question is:

How does one get the name of the current script so that it may be used as the name of a file (with a different extension) which one then loads and processes?


r/OpenPythonSCAD • • Oct 20 '24

Visitors read this first

8 Upvotes

Hi OpenPythonSCADers,

In order to prevent, that this Subreddit gets marked as SPAM channel again,

r/openpythonscad was set up as closed/private reddit.

However, if you like the topic and feel like you want to contribute here , do not hesitate to write a small message to the Mods. "Message the Mods"

We are happy to add you to the group!


r/OpenPythonSCAD • • Feb 15 '25

Source build: breakages and fixes

4 Upvotes

Fixes for 3 build failures for OpenPythonSCAD

The source build recipe for OpenPythonSCAD is mostly working. It fell over in 3 places, which are fortunately relatively easy to fix.

cmake: Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)

Solution:

sudo apt install libjpeg-dev` then repeat the cmake command

make: curl/curl.h: No such file or directory

Solution:

sudo apt install libcurl4-openssl-dev

sudo make install: INSTALL cannot find ... libfive.so

Solution:

cd ../submodules/libfive
mkdir build
cd build
cmake ..
make -j4
cd ../../build/submodules
ln -s ../../submodules/libfive/build libfive
cd ..
sudo make install

r/OpenPythonSCAD • • Jan 17 '25

Interesting architectural consequence Python errors do not block OpenSCAD when calling Python

2 Upvotes

Probably this is obvious to everyone else.

Got ahead of myself when adding Python code back in and got:

ERROR: Traceback (most recent call last): File "<string>", line 91, in <module> File "C:\Users\willa\OneDrive\Documents\OpenSCAD\libraries\gcodepreview.py", line 182, in setupstock self.writegc("(stockMin: -",str(self.stockXwidth/2),", -",str(self.stockYheight/2),"mm, -",str(self.stockZthickness),"mm)") File "C:\Users\willa\OneDrive\Documents\OpenSCAD\libraries\gcodepreview.py", line 670, in writegc self.gc.write(line_to_write) ^ AttributeError: 'gcodepreview' object has no attribute 'gc'

Execution aborted

because I added back in a bit of code before the module it called.

Interestingly, when calling the OpenSCAD template, I got a 3D model as expected and the warning:

Compiling design (CSG Tree generation)... WARNING: Python:: 'AttributeError("'gcodepreview' object has no attribute 'gc'") in line 182' in file ../../OpenSCAD/libraries/gcodepreview.scad, line 37

which is nicely informative.

Reminds me of adding \nonstopmode in (La)TeX so that one can see the current document state when it won't otherwise compile, which I've often found handy --- hopefully this can be preserved in future versions.


r/OpenPythonSCAD • • Oct 20 '24

Using your System python libraries along with PythonSCAD

4 Upvotes

There might be situations, where PythonSCAD does not automatically see your installed Python Library.

In that case, just tell PythonSCAD, where to find it.

in cmd terminal i have installed qrcode with ' pip install pyqrcode'

Later, you just need to add the correct python site-packages directory to the path variable. do this by

import sys

sys.path.append("\\path\\to'\\the\\site\\directory")

Below you can find the example from the homepage.


r/OpenPythonSCAD • • Nov 09 '24

Combing PythonSCAD with python's List comprehension

3 Upvotes

Now its possible also to use a list of translation vectors to a translate, which will in effect create multiple

instances of the same object.

Here is an example , how to create many regular holes in a plate with literally one statement


r/OpenPythonSCAD • • Dec 04 '24

The Taste of OpenSCAD++

3 Upvotes

Latest feature of Pythoncad is to use Python Classes in your SCAD code.

Lets do a Robot statemachine, something like this:

'''

use <robot.py>

robot=myrobot();

robot.draw_cube();

robot.right(2);

robot.draw_cube();

robot.front(3);

robot.draw_sphere();

robot.right(3);

robot.draw_cube();

''''


r/OpenPythonSCAD • • Oct 21 '24

Using ifrep with libfive.

3 Upvotes

Hi, I would like to use libfive with "normal" PythonOpenSCAD objects, something like this:

from openscad import *

from pylibfive import *

c = lv_coord()

p = sphere(2, fn=10)

s1 = ifrep(p)

# s1 = lv_sphere(lv_trans(c, [2, 2, 2]), 2)

b1 = lv_box(c, [2, 2, 2])

sdf = lv_union_smooth(s1, b1, 0.6)

fobj = frep(sdf, [-4, -4, -4], [4, 4, 4], 20)

output(fobj)

But how can I assign s1 to a coordinate system so that I can move it with translate (lv_trans)?


r/OpenPythonSCAD • • Oct 14 '24

Have your Libraries with you - wherever you are

3 Upvotes

The main reason why I did not use any libraries yet is, because I failed to keep them in sync between my computers and as a result it was no fun using it, and i finally forgot about them .

The only solution to that is to store them in a central place and having them locally available at the same time.

This is, why "nimport" command was born. Its like import, but you can specify an URL instead. like

nimport("http://url.to.my.file/utils.py")

Here is a working example of nimport

If you use this file on another computer, it will work. if you send to another person, it will work because its consistent.(of course you would be very carefully importing an url from somebody else, because you dont have control on the content)

PythonSCAD will try to download the URL once per session from the URL and save it in a local place, where python can "import" it.

Its very easy to host your library online, just create a GITHUB GIST or specify the URL of an RAW download of a file in your github repository.

Admittedly, nobody would want to include libraries like this, because nobody can remember such long pathes when starting a new script. This is why there is now a setting in PythonSCAD where you can register any number of nimports, which are used when starting off with a new PythonSCAD script.

Now PythonSCAD got its own Python TAB where we will collect Python specific settings.

This feature is available from today (2024-10-14).


r/OpenPythonSCAD • • Dec 16 '24

PythonSCAD as iPython

4 Upvotes

Today I managed to get PythonSCAD working as interactive python interpreter,

with all PythonSCAD functionality included, see yourself

https://www.youtube.com/watch?v=TymFtcB8K8E

Next task is to head towards Jupyter Notbook, but I am lacking some knowledge.

Who is interested in supporting me ?


r/OpenPythonSCAD • • Feb 28 '25

Setting Preferences

4 Upvotes

Hi I am an openscad user wanting to switch to this to this but cant get it to work.

I followed the instructions,

  1. Install Pythonscad - note I installed the one without libraries and didnt remove openscad first

  2. Make a .py test file (I opened using the "Python Button" and type :

from openscad import * | cube().output()

3 Set Preferences to allow Python - there was no box to tick in preferences, is there another way?

Any help appreciated


r/OpenPythonSCAD • • Jan 12 '25

Odd difficulty with re-defined definition

2 Upvotes

I have the following definition as part of a class:

def arcloopCC(self, barc, earc, xcenter, ycenter, radius, ez):
    tzinc = self.zpos() + ez / (earc - barc)
    cts = self.currenttoolshape
    toolpath = cts
    toolpath = toolpath.translate([self.xpos(),self.ypos(),self.zpos()])
    i = barc
    while i < earc: 
        toolpath = toolpath.union(self.cutline(xcenter + radius * math.cos(math.radians(i)), ycenter + radius * math.sin(math.radians(i)), self.zpos()+tzinc))
        i += 1
    if self.generatepaths == False:
        return toolpath
    else:
        return cube([0.01,0.01,0.01])

which was working fine, allowed me to do a compleat circle w/ four calls:

toolpaths = toolpaths.union(gcp.arcloopCC(0,90, gcp.xpos()-stockYheight/16, gcp.ypos(), stockYheight/16, -stockZthickness/4))
toolpaths = toolpaths.union(gcp.arcloopCC(90,180, gcp.xpos(), gcp.ypos()-stockYheight/16, stockYheight/16, -stockZthickness/2))
toolpaths = toolpaths.union(gcp.arcloopCC(180,270, gcp.xpos()+stockYheight/16, gcp.ypos(), stockYheight/16, -stockZthickness*0.75))
toolpaths = toolpaths.union(gcp.arcloopCC(270,360, gcp.xpos()+stockYheight/16, gcp.ypos(), stockYheight/16, -stockZthickness*0.99))

but since being re-written to pass in the ending Z position (ez) and to calculate the toolpath Z increment (tzinc) only works for one call, and any call after the first results in the tool digging down with a far too large tzinc value.

Hopefully it's something obviously wrong which someone can give me a clue on....


r/OpenPythonSCAD • • Dec 31 '24

Anyone using the libfive functions?

Thumbnail pythonscad.org
2 Upvotes

r/OpenPythonSCAD • • Feb 07 '25

What do I need to do to import python modules?

5 Upvotes

I just tried out pythonscad, this is the exact CAD tool that I have wanted for years. Basic python functionality is fine, but I'm having trouble with imports, and I'd love to sort that out so I can commit to switching over from openscad to python.

The website says "I've integrated libfive into OpenSCAD, but only through the Python bindings.", and the example seems quite simple, but it doesn't work for me:

ERROR: Trackback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'pylibfive'

I also get ModuleNotFoundError when importing math from python stdlib (any other stdlib module not dependent on math seems to work though). I would also like to import other non-integrated third-party libs like numpy, what are the appropriate incantations to do that?

I first got it running on a macbook, but can easily use linux instead, (or windows if that's the only option), I'm running OpenSCAD-silicon-2025-01-30.dmg, print(version()) prints [2025.0, 1.0, 0.0], print(sys.path) prints:

['/private/var/folders/2c/t4g1pzkn49dg5tm902g3m5kc0000gn/T/AppTranslocation/691CA0A7-9BAE-48ED-8935-2E42C33723F5/d/OpenSCAD.app/Contents/libraries/python', 
'/private/var/folders/2c/t4g1pzkn49dg5tm902g3m5kc0000gn/T/AppTranslocation/691CA0A7-9BAE-48ED-8935-2E42C33723F5/d/OpenSCAD.app/Contents/Frameworks/python3.12', 
'/Users/garblesnarky/Documents/OpenSCAD/libraries', 
'/Users/garblesnarky/Dropbox/src/pyscad',
'/usr/local/lib/python312.zip',
'/usr/local/lib/python3.12',
'/usr/local/lib/python3.12/lib-dynload',
'/Users/garblesnarky/venv/_src_pyscad/lib/python3.13/site-packages', 
'/Users/garblesnarky/venv/_src_pyscad/lib/python3.13/site-packages']

Not sure if relevant, but separate from openscad, in a terminal: which python3 prints /opt/homebrew/bin/python3, python3 --version prints Python 3.13.1.

I also noticed that the "python-engine" feature checkbox shown at https://pythonscad.org/tutorial/site/index.html is missing from my preferences dialog, I wonder if that screenshot is outdated?


r/OpenPythonSCAD • • Oct 15 '24

Possible to identify if a .py program is running on OpenPythonSCAD?

2 Upvotes

It occurred to me that in re-writing the program in Python it would be useful to be able to run it in both "normal" Python (say to make a DXF), and in OpenPythonSCAD.


r/OpenPythonSCAD • • Jan 19 '25

Updated gdpdxf.py to make a more interesting shape

Thumbnail
forum.makerforums.info
3 Upvotes

r/OpenPythonSCAD • • Dec 13 '24

JupyterCAD Python API --- anything to consider?

Thumbnail jupytercad.readthedocs.io
2 Upvotes

r/OpenPythonSCAD • • Jan 31 '25

New 01-25 version posted

Thumbnail pythonscad.org
3 Upvotes

r/OpenPythonSCAD • • Nov 16 '24

It might be the start of a long story

3 Upvotes

Today got first success importing a STEP file into OpenSCAD

I look forward to test more advanced STEP features soon


r/OpenPythonSCAD • • Dec 09 '24

Trouble running on Kubuntu 24.04: QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled

3 Upvotes

Hi. I have an nvidia card, and the drivers are set up for it. When I try to launch from the command line, I get the error below. I'm trying to fix it, but I haven't had much luck.

openscad
Could not initialize localization.
Error reading examples.json: examples.json: cannot open file
Error reading examples.json: examples.json: cannot open file
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
qt.qpa.backingstore: composeAndFlush: QOpenGLContext creation failed
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
qt.qpa.backingstore: composeAndFlush: makeCurrent() failed
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
qt.qpa.backingstore: composeAndFlush: makeCurrent() failed
... repeats

glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Memory info (GL_NVX_gpu_memory_info):
    Dedicated video memory: 4096 MB
    Total available memory: 4096 MB
    Currently available dedicated video memory: 3046 MB
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: NVIDIA T400 4GB/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 550.120
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.6.0 NVIDIA 550.120
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)

OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 550.120
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

r/OpenPythonSCAD • • Dec 08 '24

Programming styles in OpenPythonSCAD

Thumbnail old.reddit.com
2 Upvotes