Skip to content

Can't add special variables like "$fn" from python code #104

Description

@tatic0

Hello,

I can' t find a way to pass the value of special variables [1][2] directly from the python script, I have to re-edit the scad file manually.

I'd like to have to possibility to pass "$fn=360", for example.

[1] http://www.openscad.org/cheatsheet/
[2] https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#.24fa.2C_.24fs_and_.24fn

Activity

etjones commented on Feb 19, 2019

@etjones
Contributor

This is definitely a hole in the documentation! The most common case is, as you say, $fn. For that, you can specify a segments argument for any function (sphere(), cylinder(), etc.) that would take $fn. You can also check out the pattern in the solidpython_template example where you speficy SEGMENTS at the top of your SolidPython file, and add that as a header to the rendered SCAD code. This lets you control the segments for the entire model in one place. I've found this the easiest way to work for quick renders (SEGMENTS = 12) which I can increase for really smooth curves once I'm ready to render out (SEGMENTS = 120).

I'll open an issue specifically to document OpenSCAD special variables and how to deal with them.

nickc92 commented on Feb 19, 2019

@nickc92
Collaborator

etjones commented on Feb 19, 2019

@etjones
Contributor

You're correct that there's not a programmatic way to set $fn globally. Maybe there should be?

Here's the pattern I use (and it's in the solidpython_template example ) to specify $fn globally:

SEGMENTS = 12
a = assembly() # some SolidPython object
scad_render_to_file(a, file_header='$fn = %s;' % SEGMENTS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions