-
Notifications
You must be signed in to change notification settings - Fork 182
Calls to OpenSCAD code imported into SolidPython can only be used as CSG objects #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yep, that's definitely not right. I think this is a recent regression. Should be a quick fix. |
Nope, not a regression. There's actually nothing in the code to use imported OpenSCAD code as parameters to functions (e.g. multmatrix( translation([xyz])(c) rather than members of the body of an OpenSCAD block, like union()(translation([x,y,z])). But... that's an artificial limitation. Working on a fix |
@etjones any news? Or maybe some a dev branch to play around with? =) |
I took a shot at it and... removing one semicolon is hard.
Getting rid of |
This suggestion will work for a single OpenSCAD object, like n-e-g's original prompt. But if the argument to So, removing the semicolon from a single object works. Using the original example: c = cube([20, 20, 30])
t = translation(x=10, y=20, z=30)
d = multmatrix(t)(c)
print(scad_render(d)) would yield:
Despite some unclear indentation, this would work. But if the transform we pass to multmatrix is more complex: c = cube([20, 20, 30])
t = translate([1,2,3])(rotate(a=[90,45,0])(translation(x=10, y=20, z=30)))
d = multmatrix(t)(c)
print(scad_render(d)) yields arbitrarily complex OpenSCAD code in the args to multmatrix:
Assuming we could fix the indentation & internal semicolons, this still seems pretty convoluted to me. I'm inclined to close this as a wontfix, but maybe there are some reasons for this feature I haven't thought through all the way. Can you tell me why you'd find it useful to pass OpenSCAD objects as function arguments to others? |
@etjones, here is my usecase:
and get 2 perfectly spaced gears (or, similarly, places to put axes). My problem here is having ugly copypaste of Here this transforms to something like this:
, which doesn't work. |
I suspect this approach (module + some functions returning parameters of this module) may be widespread in existing OpenSCAD code as there is no way to get derived values (like "radius of a gear with X teeth and pitch of Y") without making such functions. And these functions will probably pretty often be used in transforms. offtopic: I solved this problem for now by partially porting the OpenSCAD gear code to python and exposing the values as additional attributes of the |
Thanks for that! I think that's a strong argument in favor of solving this bug. I'll take a look at this today. |
Hmm. In both the original issue example and in yours, we're calling OpenSCAD code to return non-solid values, a matrix and a number respectively. It absolutely makes sense that we'd want to be able to use those pre-made calculations without having to re-write them in Python. ...Aaaand, I'm not really sure how to make that work just yet. Currently a line like: pr = pitch_radius(**g1_params) + pitch_radius(**g1_params) yields this OpenSCAD:
since The assumption in SolidPython has always been that imported SCAD objects are CSG objects. This issue points out why that was a mistaken assumption. Hmm... |
@etjones My hack worked only for non-arithmetic case where gears were moved along different axes:
Doing proper expression handling feels like waaaay too much work (probably comparable to rewriting OpenSCAD to just use python directly :D) |
I've released a fix for this issue, now available via Pip in SolidPython v1.0.3. The fix doesn't resolve some of the deeper issues I described above of composite objects all specified in arguments to some other object, but for most uses of "This calculation was done in OpenSCAD and I want to use it in SolidPython", this should take care of things. Sorry for the long, long wait |
When function is imported, especially function that renders into array, generated code is incorrect.
Example:
import file transform.scad which contain function
use transform scad:
leads to the following output:
which is obviously incorrect
The text was updated successfully, but these errors were encountered: