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
Roy_043
Veteran
Posts: 8580
Joined: Thu Dec 27, 2018 12:28 pm

Re: How to use expressions as in OpenScad

Post by Roy_043 »

FreeCAD can read these expressions from an .scad file with the Std_Import command. But also directly with the OpenSCAD_AddOpenSCADElement command. But there will be no parametric link between the code and the created model. The "Refresh" button just deletes the existing model and creates a new one.

Note that OpenSCAD must be installed. And, depending on your OS, you may have to specify the correct path to the OpenSCAD executable in the preferences.
Edit > Preferences... > OpenSCAD > General OpenSCAD Settings > OpenSCAD executable

I have tested with the supplied code but I had to substitute basis with a numeric value. I assume it represents a variable.
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 12:39 pm 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.
You will find answers to your questions in OpenSCADUtils.py. it has the functions to manage temporary files, call the openscad executable etc
but I would not try mess with the files to find out what the CSG file looks like, the temp files get deleted after use to keep the system tide, you can create the CSG file in OpenSCAD with
OpenSCAD | File | Export CSG
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: How to use expressions as in OpenScad

Post by keithsloan52 »

You can type OpenSCAD statements into FreeCAD by using the Workbenches AddElements facility, you just have to cut/remove the cube statement.

I have tried to enhance this facility and there is a Pull request https://github.com/FreeCAD/FreeCAD/pull/4764 Just missed FreeCAD 0.19 but should be in 0.20. Apart from text edit window it also has a two line box for any error messages.

I subscribe a small amount to realthunders Patreon(wish more people did) and I already asked him if he could sync OpenSCAD with the upstream, like he just did for PATH, so hopefully people like me on a Mac without access to 0.20 can tryout it out shortly.
Last edited by keithsloan52 on Wed Jul 21, 2021 5:07 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 »

Roy_043 wrote: Wed Jul 21, 2021 3:42 pm
I have tested with the supplied code but I had to substitute basis with a numeric value. I assume it represents a variable.
@g0erwt
I also could not use the code as posted and made the change to use a Module

I did not end up with wirefame
Triangles.scad
(387 Bytes) Downloaded 8 times
File in OpenSCAD
9C34CC3E-BBF9-4A68-81DE-A77072089E0D.jpeg
9C34CC3E-BBF9-4A68-81DE-A77072089E0D.jpeg (35.14 KiB) Viewed 865 times
Same file in FreeCAD
F0BCB019-9086-4041-BBCB-0283306EDDED.jpeg
F0BCB019-9086-4041-BBCB-0283306EDDED.jpeg (55.88 KiB) Viewed 865 times
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: How to use expressions as in OpenScad

Post by keithsloan52 »

@g0erwt sent me a file he had problems with.

It looks like this in OpenSCAD
CC2F9997-73B5-4D95-9A99-11D20EA05FE4_4_5005_c.jpeg
CC2F9997-73B5-4D95-9A99-11D20EA05FE4_4_5005_c.jpeg (29.83 KiB) Viewed 843 times

And like this in FreeCAD
56977E5F-E921-4E1F-94FA-21C1B6EA9A82.jpeg
56977E5F-E921-4E1F-94FA-21C1B6EA9A82.jpeg (61.05 KiB) Viewed 843 times
Similar but the triangles in the bottom right are not right, will pm Chris @chennes to add to his list of things to look into.
Ruhig_Blut-reconstructie.scad
(6.09 KiB) Downloaded 10 times
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 Keith,
thank you your assistance and clarification also here on the forum.
I'm glad that you could manage to produce the first example correctly. But as you have seen something is weird with the complete model.
Thank you for the privat conversaton.
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How to use expressions as in OpenScad

Post by chennes »

Are we confident that the FreeCAD is actually wrong? There are multiple overlapping triangles in the OpenSCAD, I don't think there's anything we can do about the rendering of coplanar surfaces.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: How to use expressions as in OpenScad

Post by keithsloan52 »

chennes wrote: Wed Jul 21, 2021 7:56 pm Are we confident that the FreeCAD is actually wrong? There are multiple overlapping triangles in the OpenSCAD, I don't think there's anything we can do about the rendering of coplanar surfaces.
Well it is wrong in that it does not reproduce the same result. Might well be that there is nothing we can do about it as it is overlapping triangles,
other than suggest that it could be written without overlapping triangles. I note the rendering in OpenSCAD of the overlapping parts is not great.
Wonder what @g0erwt thinks? Maybe he could rewrite without overlaps as a test case.
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 »

@chennes in OpenSCAD I wrote the polygons for each piece of the puzzle. Using the clockwise point numbering method. The expression [color] is an essential part of the description for each polygon! In total there are 15 unique points. Then OpenSCAD generates the "pieces of the puzzle" according to the colours chosen. In addition to that output OpenSCAD shows additional lines within some pieces. I've interpreted those lines as indications that all pieces are built according to the triangular system.
In my opinion, these are not defined in OpenSCAD as additional triangles.

Apart from that: the FreeCAD's OpenSCAD-Workbench does NOT show the pieces at the right side of the puzzle at all. The colours there give completely wrong pieces of the puzzle.
Might be that FreeCAD's OpenSCAD-Workbench does not process the expression [color] the way it is intended?

Note:
The representation of the first picture is that of FreeCAD's OpenSCAD-Workbench.The second is that by the OpenSCAD programm. Not the otherway around.

@keithsloan52 I don't know why the figure in the original rendering by OpenSCAD does not give 'solid' panes with the full colour but some pieces with stripes;at the right side. It changes when you change the orientation. See new attachment. That is: comparing both figures in the same orientation would change that. But it does not give the correct pieces in the puzzle.
Actually the green piece has exactly the same form as the pink piece. I choose not to take the same colour because those pieces are adjacent. Otherwise is the rule: same form = same colour.
Real-OpenSCAD-Ruhig_Blut.png
Real-OpenSCAD-Ruhig_Blut.png (21.43 KiB) Viewed 765 times
Ruhig_Blut.jpg
Ruhig_Blut.jpg (44.54 KiB) Viewed 764 times
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How to use expressions as in OpenScad

Post by chennes »

g0erwt wrote: Thu Jul 22, 2021 5:47 am I don't know why the figure in the original rendering by OpenSCAD does not give 'solid' panes with the full colour but some pieces with stripes;
The stripes are an indication that you have overlapping triangles: OpenSCAD's renderer doesn't know what to draw with two coincident surfaces of different colors. This is probably due to a bug in your generation algorithm, but I have not had time to investigate further.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply