Skip to content
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

Access $preview variable #195

Open
occivink opened this issue Feb 19, 2022 · 8 comments
Open

Access $preview variable #195

occivink opened this issue Feb 19, 2022 · 8 comments

Comments

@occivink
Copy link

Hi,

I would like to access the OpenScad $preview variable (introduced in version 2019.05), so that I can use a lower number of segments during preview. I looked around in the SolidPython code, but as far as I can tell it is not exposed in any way.

Thanks in advance

@jeff-dh
Copy link
Contributor

jeff-dh commented Feb 19, 2022

It is not supported atm.

And the support is not trivial because the value of the $preview variable is unknown at python (SolidPython) runtime (because all the $openScadVariables are only evaluated in OpenSCAD render time, which is after the solid python runtime).

But, we spend some thoughts on how some kind of support for these features could look like.

You could have a look at #178, #181, #180, #183. Those issues point towards the direction on how it could "somehow" be possible to use the $preview variable. I guess it'll all fall back to the scad_inline idea from #178.

@jeff-dh
Copy link
Contributor

jeff-dh commented Feb 19, 2022

Another hint:

There's technically no way to get to something like:

if some_new_feature("$preview"):
    #blablub
else:
   #foobar

The path that could have success would be something like:

sphere(....,segments = scad_inline("$preview ? 8 : 64"))

(which might(!) work more or less out of the box if you grab scad_inline from #178)

@etjones
Copy link
Contributor

etjones commented Feb 19, 2022 via email

@jeff-dh
Copy link
Contributor

jeff-dh commented Feb 19, 2022 via email

@jeff-dh
Copy link
Contributor

jeff-dh commented Feb 19, 2022

from solid import *

class ConstantOpenSCADObject(IncludedOpenSCADObject):
    def __init__(self, code):
        self._get_include_path = lambda x : ''
        super().__init__("not reander able", {}, "blablub")
        self.include_string = ''
        self.code = " " + code + " "

    def _render(self, render_holes=42):
        return self.code
 
def scad_inline(code):
    return ConstantOpenSCADObject(code)

s = sphere(10, segments = scad_inline("$preview ? 4 : 16"))

scad_render_to_file(s)

This works (but scad_inline is really a hack).

@jeff-dh
Copy link
Contributor

jeff-dh commented Feb 19, 2022 via email

@occivink
Copy link
Author

Thanks for the clarifications. I now see that it is indeed tricky to solve properly due to the late (i.e. after compiling to openscad) evaluation of $preview. I would be happy with the proposed scad_inline solution.

@jeff-dh
Copy link
Contributor

jeff-dh commented Feb 20, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants