Using notebooklm to learn pythonscad

16 views
Skip to first unread message

Matthieu Hendriks

unread,
Jun 24, 2025, 12:50:36 AMJun 24
to PythonSCAD

I've been experiementing with notebooklm for learning pythonscad. I think the results are amazing:. Here is  what I did:

go to notebooklm.google.com


Create a new space/topic

Added the following  resources:

  1. https://pythonscad.org/tutorial/site/index.html

  2. https://groups.google.com/g/pythonscad

  3. https://raw.githubusercontent.com/pythonscad/pythonscad/refs/heads/master/libraries/python/openscad.pyi

  4. openscadhelper5.pdf I would have liked to use the url but that did not work, so I got the helpfile converted it to pdf and uploaded it.

  5. pythonscad.org

Than start ask questions:

Give an example for a hull with creating 4 cylinders in a for loop

Answer

Here is the PythonSCAD code to create four cylinders in a for loop and then compute their convex hull:

# Import all OpenSCAD functions into the current namespace 
# This is necessary in PythonSCAD for functions like cylinder, translate, and hull to be available. [3, 4] 

from openscad import * 
# Create an empty Python list to store our cylinder objects. 
# This list will hold each individually translated cylinder before the hull operation. 

cylinders_to_hull = [] 
# This is standard Python list usage, not directly from the provided sources, but implied by PythonSCAD's nature. 
 # Use a standard Python 'for' loop to iterate four times. 
# In PythonSCAD, you can use standard Python control flow statements like 'for' loops [2]. 

for i in range(4): 
 # Create a cylinder with a height (h) of 10 units and a radius (r) of 2 units. # The 'cylinder' function is available in PythonSCAD with parameters like 'h' and 'r'. [7, 8] 
 
current_cylinder = cylinder(h=10, r=2) 
 # Translate (move) the cylinder along the X-axis. 
 # The 'translate' function moves child elements along a specified vector. [9, 10] 
 # By multiplying 'i' by 10, each cylinder is placed 10 units further along the X-axis (0, 10, 20, 30). 

 translated_cylinder = translate(current_cylinder, [i * 10, 0, 0]) 
 # Add the translated cylinder object to our list. 

 cylinders_to_hull.append(translated_cylinder) 
 # Create the convex hull around all the cylinder objects stored in the list. 
# The 'hull' function takes multiple objects (here, provided as a list) and wraps them in a convex shape. [1, 5] 

final_hulled_shape = hull(cylinders_to_hull) 
# Display the final hulled shape. 
# In PythonSCAD, you must explicitly use the 'show()' function to render the object. [3, 4, 11] 

show(final_hulled_shape)

Explanation of the Code:

from openscad import *: This line is crucial for PythonSCAD scripts, as it makes all the OpenSCAD functions (like cube, cylinder, translate, hull, show) available for use in your Python code34.

cylinders_to_hull = []: We initialize an empty Python list. This list will accumulate each individual cylinder object generated within the loop before they are passed to the hull() function.

for i in range(4):: This is a standard Python for loop, which will execute the code block four times, with i taking values 0, 1, 2, and 3. PythonSCAD leverages Python's native language features, including its loops2.

current_cylinder = cylinder(h=10, r=2): Inside the loop, a cylinder is created. The cylinder() function in PythonSCAD allows you to specify its height (h) and radius (r)78.

translated_cylinder = translate(current_cylinder, [i 10, 0, 0]): The translate() function moves an object by a given vector910. By using i 10, each cylinder is placed at a distinct x-coordinate (0, 10, 20, 30), ensuring they are separated enough for the hull to clearly form around them.

cylinders_to_hull.append(translated_cylinder): Each uniquely positioned cylinder is added to the cylinders_to_hull list.

final_hulled_shape = hull(cylinders_to_hull): After the loop finishes, the hull() function is called, taking the list of four cylinder objects. It then calculates the convex hull that encloses all of them15.

show(final_hulled_shape): Finally, the show() function is used to display the resulting 3D model in the OpenSCAD viewer3....

This script will generate a single 3D model that represents the combined convex hull of the four distinct cylinders, appearing as a smooth, enclosed shape that touches the outermost points of all the cylinders.

Raymond West

unread,
Jun 24, 2025, 6:48:59 AMJun 24
to Matthieu Hendriks, PythonSCAD

Looks interesting.

Currently, the other  llm's do not seem able to differentiate between true information and bad. If you only feed an llm accurate info, then the results should be better. (In your example, the explanation has a few typo's, I wonder if they are in the documentation you supplied.)

--
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/2562e502-1fec-4ceb-952a-005cb460cf97n%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raymond West

unread,
Jun 24, 2025, 4:14:36 PMJun 24
to Matthieu Hendriks, PythonSCAD

I've tried notebooklm, (thanks for the info, Maththieu) but it is crippled wrt serious development, since it does not remember conversations I can't train it and let others use it, or even me a day later. It has the advantage that you can give it the documents to work with. For my simple test, I had to give it the correct 'translate' syntax, for example, since it used the syntax in https://raw.githubusercontent.com/pythonscad/pythonscad/refs/heads/master/libraries/python/openscad.pyi   and it did not understand the meaning of v:list[float]

and I had to remind it that it seemed inebriated in the exuberance of its own verbosity - but nowhere near as bad as the stupid Microsoft AI - Copilot...

I think if it were provided with a selection of good example scripts, then it would be useful, but then that is the same for other ai's, and for them you can generally go back to previous conversations. Still, early days.

Maybe, in a year or two, things will be different, but it depends which of the many Ai's will be king.

W W

unread,
Jun 24, 2025, 8:57:57 PMJun 24
to PythonSCAD
Brilliant idea on using openscad.pyi as a source. There's also the cc implementations (cpp functions invocable in python) such as https://raw.githubusercontent.com/pythonscad/pythonscad/refs/heads/master/src/python/pyopenscad.cc you can add as a source.

Despite being noisy, LLMs can still give you inspiration in finding potential built-in functions you can leverage. It's not entirely useless.

Note that inaccuracies will be fundamental to how transformers/LLMs work. It does not replace any understanding, and you will still need to verify any results.


-W

Guenther Sohler

unread,
Jun 25, 2025, 2:19:33 AMJun 25
to W W, PythonSCAD
pyopenscad.cc just provides the infrastructure.

you actually want to reference


There  the function names are mentioned and coded.



Reply all
Reply to author
Forward
0 new messages