How to use expressions as in OpenScad

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
g0erwt
Posts: 11
Joined: Mon Jul 19, 2021 3:45 pm
Contact:

How to use expressions as in OpenScad

Post by g0erwt »

hello,
I'm completely new to FreeCAD but have some basic experience with OpenScad. What I appreciate in OpenScad is the use of mathematical expressions.
What I'm looking for is a tutorial in FreeCAD how these OpenSCAD-features work in FreeCAD.
I uploaded a model, made in OpenSCAD, and looked at the output in FreeCAD. A puzzle I couldn't solve. None of the expression I used were reffered.
B.t.w. I also worked with other packages, but prefer the logic and stability of a mathematical description in favor of GUI's. The reason is that I can still type text but have problems handling de cursor.

Update: 2021-07-21, 12:15
I'm reffering to the original OpenSCAD software, not the FreeCAD OpenSCAD-Workbench.
In the original OpenSCAD I can use mathematical expression. I'm familar with that. I see no direct equivalent of that in FreeCAD/OpenSCAD-Workbench.
Last edited by g0erwt on Wed Jul 21, 2021 10:16 am, edited 1 time in total.
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: How to use expressions as in OpenScad

Post by keithsloan52 »

g0erwt wrote: Tue Jul 20, 2021 4:02 pm hello,
I'm completely new to FreeCAD but have some basic experience with OpenScad. What I appreciate in OpenScad is the use of mathematical expressions.
What I'm looking for is a tutorial in FreeCAD how these OpenSCAD-features work in FreeCAD.
I uploaded a model, made in OpenSCAD, and looked at the output in FreeCAD. A puzzle I couldn't solve. None of the expression I used were reffered.
Are you referring to the OpenSCAD workbench?

At the core of the workbench is a CSG importer. If you loaded your OpenSCAD scad file into FreeCAD, under the covers the Workbench will have used the command line version of OpenSCAD to take your model and create a CSG file. The importer is then run to convert the the CSG requests into equivalent FreeCAD BREP Parts. CSG requests are things like create a Cube/Cone/Sphere etc. By the time OpenSCAD has converted your SCAD file to CSG all the main language constructs will have been stripped out to create a CSG file which is barebones creation of Graphics Objects.
B.t.w. I also worked with other packages, but prefer the logic and stability of a mathematical description in favor of GUI's. The reason is that I can still type text but have problems handling de cursor.
If you want to create FreeCAD models by programming then you use Python which incidentally has more programming facilities than OpenSCAD scripting.
Last edited by keithsloan52 on Tue Jul 20, 2021 9:23 pm, edited 1 time in total.
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: How to use expressions as in OpenScad

Post by keithsloan52 »

Cekuhnen wrote: Tue Jul 20, 2021 8:26 pm I have no knowledge of OpenScad but maybe ping mathcodeprint

he has many freecad openscad experience

https://www.youtube.com/watch?v=1IcWB_vd5HI
Not a good reference IMHO. He made video but it was not good advice because he did not have a good understanding of the workbench he was making changes to the SCAD source which were TOTALLY unnecessary. That is one of the weakness of the web it throws up armchair experts who don't really know what they are doing.
User avatar
Cekuhnen
Posts: 443
Joined: Sat Jul 10, 2021 11:37 pm

Re: How to use expressions as in OpenScad

Post by Cekuhnen »

Yup no problem

Maybe the mods should remove my post then
MacOS Big Sur / Win 10

Designer | Faculty
Wayne State University
Interior - Industrial Design
chrisb
Veteran
Posts: 54273
Joined: Tue Mar 17, 2015 9:14 am

Re: How to use expressions as in OpenScad

Post by chrisb »

Removed.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Cekuhnen
Posts: 443
Joined: Sat Jul 10, 2021 11:37 pm

Re: How to use expressions as in OpenScad

Post by Cekuhnen »

chrisb wrote: Wed Jul 21, 2021 12:50 amRemoved.
great - if you want just remove my other two posts too - I cannot find the ability to do this as a user.
MacOS Big Sur / Win 10

Designer | Faculty
Wayne State University
Interior - Industrial Design
User avatar
g0erwt
Posts: 11
Joined: Mon Jul 19, 2021 3:45 pm
Contact:

Re: How to use expressions as in OpenScad

Post by g0erwt »

chrisb wrote: Wed Jul 21, 2021 12:50 amRemoved.
hello chrisb,
I've no problem in finding the normal documentation, which is, in my opinion, excellent. So I've been reading and trying Sketching. But that's still based on the GUI, like the tutorial you mention. (Thanks for that anyway).

I want to use the pure mathematical descriptions, like this example:
{color()
polygon(points=[[0,0],[-basis,0],[-basis,basis*sqrt(3)]], paths=[[0,1,2]],convexity=10);
color("yellow")
polygon(points=[[-basis,basis*sqrt(3)],[-basis,basis*4/sqrt(3)],[0,basis*4/sqrt(3)]], paths=[[0,1,2]],convexity=10);
color("gray")
polygon(points=[[0,basis*4/sqrt(3)],[0,0],[-basis,basis*sqrt(3)]], paths=[[0,1,2]],convexity=10);}
This defines three planes (rectangular triangles) with three different colours.

As I try to interprete this model when loaded in FreeCAD-OpenScad/Workbench this is a "wireframe".
Though, somewhere I expect to find the documentation where that "wireframe" concept is presented.
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: How to use expressions as in OpenScad

Post by keithsloan52 »

g0erwt wrote: Wed Jul 21, 2021 10:35 am
chrisb wrote: Wed Jul 21, 2021 12:50 amRemoved.
hello chrisb,
I've no problem in finding the normal documentation, which is, in my opinion, excellent. So I've been reading and trying Sketching. But that's still based on the GUI, like the tutorial you mention. (Thanks for that anyway).

I want to use the pure mathematical descriptions, like this example:
{color()
polygon(points=[[0,0],[-basis,0],[-basis,basis*sqrt(3)]], paths=[[0,1,2]],convexity=10);
color("yellow")
polygon(points=[[-basis,basis*sqrt(3)],[-basis,basis*4/sqrt(3)],[0,basis*4/sqrt(3)]], paths=[[0,1,2]],convexity=10);
color("gray")
polygon(points=[[0,basis*4/sqrt(3)],[0,0],[-basis,basis*sqrt(3)]], paths=[[0,1,2]],convexity=10);}
This defines three planes (rectangular triangles) with three different colours.

As I try to interprete this model when loaded in FreeCAD-OpenScad/Workbench this is a "wireframe".
Though, somewhere I expect to find the documentation where that "wireframe" concept is presented.
OpenSCAD is documented here https://openscad.org

The workbench just does its best to try and convert what OpenSCAD produces to an equivalent model in FreeCAD.
I would suggest that concepts related to OpenSCAD scripts are OpenSCAD domain not FreeCAD's
User avatar
g0erwt
Posts: 11
Joined: Mon Jul 19, 2021 3:45 pm
Contact:

Re: How to use expressions as in OpenScad

Post by g0erwt »

hello keithsloan52,

yes, I use that OpenSCAD documentation. Also excellent.
To phrase my question differently:

In OpenSCAD I write pure mathematical expressions; like in the example. The OpenSCAD interpreter/compiler turns that into a model that will be displayed and makes a list of those expressions (with possible error messages).

I'm not discussing the way FreeCAD is converting those expressions into scripts.
I'm trying to find a module within FreeCAD where I can write the same mathematical expressions.

Where does FreeCAD store an OpenSCAD upload (original OpenSCAD file). Can I access that file?
User avatar
g0erwt
Posts: 11
Joined: Mon Jul 19, 2021 3:45 pm
Contact:

Re: How to use expressions as in OpenScad

Post by g0erwt »

Update 20210721, 14:30

I'm working with a MacBookAir (MacOS Catalina) and use the programm [Terminal] a lot.
Browsing the FreeCAD directories I find a lot of information about the OpenSCAD/Workbench. Such as all .py modules, including exportCSG.py, importCSG.py and OpenSCAD2Dgeom.py, OpenSCADCommands.py, OpenSCADFeatures.py, OpenSCADUtils.py and OpenSCAD_rc.py.

I'll have a look at these files. Maybe I'll find what I can use to answer my own questions and report back what the conclusion is.

Thanks so far everybody answering my posts.
Post Reply