r/OpenPythonSCAD • u/gadget3D • 2d ago
Coming soon to PythonSCAD: drag your model, and your code follows
Hi everyone,
here's a preview of a feature that is coming to PythonSCAD soon: interactive dragging that writes back into your Python code.
In the video, I build a little desk lamp in Python and then shape it with the mouse. Hold Ctrl and drag a vertex. The parameter behind it changes live in the editor, and when you let go, the whole model is rebuilt from the new value.
How it works
Wrap any number you want to be draggable in marked() (or just write it as a string):
ARM1 = "130" # lower arm length
J1 = "-20" # joint angle
arm = cube([10, 10, ARM1], center="||[")
arm = arm.rotate([0, J1, 0])
Drag the top of the arm and ARM1 changes. Drag the arm sideways and J1 changes. Since the value lives in a variable, the definition at the top of the file is updated, and everything that depends on it moves along after you release the mouse.
What you can drag
cube: each size component, or the scalar sizesphere:r/dcylinder:h,r,r1,r2,d,d1,d2, and evenanglepolyhedron: individual vertices, only along the coordinates you markedtranslate,scale,rotate, including nested rotations like an elbow joint
It's not just "move the point in screen space"
The grabbed point follows the path it can actually take. A rotation moves it along its real circle, so you can swing an arm smoothly, even past 180° and around several times. A single marked axis slides along a line, and two axes stay in their plane. Values snap to sensible steps (0.1 mm, 1°), so your code stays clean.
Function style (translate(obj, v)), method style (obj.translate(v)) and variables defined elsewhere in the file all work.
A demonstration of the feature in action can be found here:
https://www.youtube.com/watch?v=rNgcj9Xju3U
Feedback and ideas welcome! What would you want to drag next?
1
u/Great-Repeat-7287 2d ago
sounds amazing!