Hi developers,
With the arrival of free functions in CadQuery(https://github.com/CadQuery/cadquery), I believe it's the perfect time to bridge the OpenSCAD and CadQuery communities.
I've tried manually translating a simple OpenSCAD script into CadQuery, and it is quite straightforward. To benefit both communities, I'm thinking about automatically translating OpenSCAD scripts into CadQuery scripts.
To perform the translation, we need to parse the OpenSCAD script. Since the OpenSCAD source code already handles parsing, we can utilize the parsed AST for our translation.
To expedite and professionalize the process, I am seeking opinions and suggestions.
OpenSCAD Scripting Code:
/The OpenSCAD code begin*******/
module Flange_01() {
difference() {
cylinder(10, 100, 100, $fn = 30);
r = 80;
for (i = [0:90:359]) {
translate([r * cos(i), r * sin(i), -1])
cylinder(12, 10, 10, $fn = 30);
translate([0, 0, -1])
cylinder(12, 50, 50, $fn = 50);
}
}
}
Flange_01();
/The OpenSCAD code end*********/
Manually Translated CadQuery Scripting Code:
###########The CadQuery code begin###########
from cadquery.func import *
from cadquery.vis import show
import math
r1 = 100
part1 = cylinder(2 * r1, 10)
r2 = 80
theta_values = [0, math.pi / 2, math.pi, 3 * math.pi / 2]
for theta in theta_values:
part2 = cylinder(2 * 10, 12).moved(x = r2 * math.cos(theta), y = r2 * math.sin(theta))
part1 -= part2
part2 = cylinder(2 * 50, 12).moved(x = 0, y = 0)
part1 -= part2
show(part1)
###########The CadQuery code end#############
Best regards,
Youbao
Translating OpenSCAD code into another language is not difficult and you do
not even need a parser for that.
Just "output" the parsed OpenSCAD AST Tree into another language.
I did so already and adding yet another language maybe requires adding a
common "plug-in" layer.
merging to the cadquery community has already started, just watch
https://www.reddit.com/r/OpenPythonSCAD/comments/1hs4hmy/using_cadquery_features_in_your_design/
On Sat, Feb 8, 2025 at 1:25 PM 张友宝 via Discuss discuss@lists.openscad.org
wrote:
Hi developers,
With the arrival of free functions in CadQuery(
https://github.com/CadQuery/cadquery), I believe it's the perfect time to
bridge the OpenSCAD and CadQuery communities.
I've tried manually translating a simple OpenSCAD script into CadQuery,
and it is quite straightforward. To benefit both communities, I'm thinking
about automatically translating OpenSCAD scripts into CadQuery scripts.
To perform the translation, we need to parse the OpenSCAD script. Since
the OpenSCAD source code already handles parsing, we can utilize the parsed
AST for our translation.
To expedite and professionalize the process, I am seeking opinions and
suggestions.
OpenSCAD Scripting Code:
/The OpenSCAD code begin*******/
module Flange_01() {
difference() {
cylinder(10, 100, 100, $fn = 30);
r = 80;
for (i = [0:90:359]) {
translate([r * cos(i), r * sin(i), -1])
cylinder(12, 10, 10, $fn = 30);
translate([0, 0, -1])
cylinder(12, 50, 50, $fn = 50);
}
}
}
Flange_01();
/The OpenSCAD code end*********/
Manually Translated CadQuery Scripting Code:
###########The CadQuery code begin###########
from cadquery.func import *
from cadquery.vis import show
import math
r1 = 100
part1 = cylinder(2 * r1, 10)
r2 = 80
theta_values = [0, math.pi / 2, math.pi, 3 * math.pi / 2]
for theta in theta_values:
part2 = cylinder(2 * 10, 12).moved(x = r2 * math.cos(theta), y = r2 *
math.sin(theta))
part1 -= part2
part2 = cylinder(2 * 50, 12).moved(x = 0, y = 0)
part1 -= part2
show(part1)
###########The CadQuery code end#############
Best regards,
Youbao
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
The last time that I attempted to install and run CADquery failed (due to,
I think, changes in numpy). Has this been fixed?
On Sat, Feb 8, 2025 at 6:44 AM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:
Translating OpenSCAD code into another language is not difficult and you
do not even need a parser for that.
Just "output" the parsed OpenSCAD AST Tree into another language.
I did so already and adding yet another language maybe requires adding a
common "plug-in" layer.
merging to the cadquery community has already started, just watch
https://www.reddit.com/r/OpenPythonSCAD/comments/1hs4hmy/using_cadquery_features_in_your_design/
On Sat, Feb 8, 2025 at 1:25 PM 张友宝 via Discuss discuss@lists.openscad.org
wrote:
Hi developers,
With the arrival of free functions in CadQuery(
https://github.com/CadQuery/cadquery), I believe it's the perfect time
to bridge the OpenSCAD and CadQuery communities.
I've tried manually translating a simple OpenSCAD script into CadQuery,
and it is quite straightforward. To benefit both communities, I'm thinking
about automatically translating OpenSCAD scripts into CadQuery scripts.
To perform the translation, we need to parse the OpenSCAD script. Since
the OpenSCAD source code already handles parsing, we can utilize the parsed
AST for our translation.
To expedite and professionalize the process, I am seeking opinions and
suggestions.
OpenSCAD Scripting Code:
/The OpenSCAD code begin*******/
module Flange_01() {
difference() {
cylinder(10, 100, 100, $fn = 30);
r = 80;
for (i = [0:90:359]) {
translate([r * cos(i), r * sin(i), -1])
cylinder(12, 10, 10, $fn = 30);
translate([0, 0, -1])
cylinder(12, 50, 50, $fn = 50);
}
}
}
Flange_01();
/The OpenSCAD code end*********/
Manually Translated CadQuery Scripting Code:
###########The CadQuery code begin###########
from cadquery.func import *
from cadquery.vis import show
import math
r1 = 100
part1 = cylinder(2 * r1, 10)
r2 = 80
theta_values = [0, math.pi / 2, math.pi, 3 * math.pi / 2]
for theta in theta_values:
part2 = cylinder(2 * 10, 12).moved(x = r2 * math.cos(theta), y = r2 *
math.sin(theta))
part1 -= part2
part2 = cylinder(2 * 50, 12).moved(x = 0, y = 0)
part1 -= part2
show(part1)
###########The CadQuery code end#############
Best regards,
Youbao
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
In the few experiments I made with cadquery, some months ago, I had a
problem with some of the results that boolean operations gave, due to
the fact, afaik, that in openscad code is converted to triangle
meshes, whereas in cadquery it is a mathematical surface, which can have
discontinuities. (A sphere is represented on screen as a circle with a
curved line).
I'm not sure that a simple translation will be enough, since if I
differenced a sphere from a cylinder, say, in openscad I saw a good
representation, but in cadquery, depending on the rotation of the sphere
I did not.
I can't find my test cadquery code, but here is an openscad script that
may show the problem, if you want to translate that...
$fn=200;
difference(){
cylinder(h=10,d=100);
translate([0,0,255])
sphere(d=500);
}
Iirc that the equivalent in cadquery required the sphere to be rotated
such that its 'line' was not in the cylinder.
I also could not find an active forum, although there were a few posters
on reddit.
On 08/02/2025 09:47, 张友宝 via Discuss wrote:
Hi developers,
With the arrival of free functions in
CadQuery(https://github.com/CadQuery/cadquery), I believe it's the
perfect time to bridge the OpenSCAD and CadQuery communities.
I've tried manually translating a simple OpenSCAD script into
CadQuery, and it is quite straightforward. To benefit both
communities, I'm thinking about automatically translating OpenSCAD
scripts into CadQuery scripts.
To perform the translation, we need to parse the OpenSCAD script.
Since the OpenSCAD source code already handles parsing, we can utilize
the parsed AST for our translation.
To expedite and professionalize the process, I am seeking opinions and
suggestions.
OpenSCAD Scripting Code:
/The OpenSCAD code begin*******/
module Flange_01() {
difference() {
cylinder(10, 100, 100, $fn = 30);
r = 80;
for (i = [0:90:359]) {
translate([r * cos(i), r * sin(i), -1])
cylinder(12, 10, 10, $fn = 30);
translate([0, 0, -1])
cylinder(12, 50, 50, $fn = 50);
}
}
}
Flange_01();
/The OpenSCAD code end*********/
Manually Translated CadQuery Scripting Code:
###########The CadQuery code begin###########
from cadquery.func import *
from cadquery.vis import show
import math
r1 = 100
part1 = cylinder(2 * r1, 10)
r2 = 80
theta_values = [0, math.pi / 2, math.pi, 3 * math.pi / 2]
for theta in theta_values:
part2 = cylinder(2 * 10, 12).moved(x = r2 * math.cos(theta), y =
r2 * math.sin(theta))
part1 -= part2
part2 = cylinder(2 * 50, 12).moved(x = 0, y = 0)
part1 -= part2
show(part1)
###########The CadQuery code end#############
Best regards,
Youbao
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
Dear Raymond,
Here is my translation:
###########CadQuery code begin###############
from cadquery.func import *
from cadquery.vis import show
import math
part1 = cylinder(2 * 50, 10)
part2 = sphere(500).moved(Location(0, 0, 255))
result_part = part1 - part2
result_part.exportStep("result_part.step")
show(result_part)
###########CadQuery code end#################
The following is the CadQuery code output.
The original OpenSCAD code is here:
/OpenSCAD code begin*******/
$fn=200;
difference(){
cylinder(h=10,d=100);
translate([0,0,255])
sphere(d=500);
}
/OpenSCAD code end*******/
Best regards,
Youbao
-----Original Messages-----
From:"Raymond West via Discuss" discuss@lists.openscad.org
Sent Time:2025-02-08 22:17:53 (Saturday)
To: "张友宝 via Discuss" discuss@lists.openscad.org
Cc: "Raymond West" raywest@raywest.com
Subject: [OpenSCAD] Re: About Automatically Translating OpenSCAD Scripting Code into CadQuery Scripting Code (Python Code)
In the few experiments I made with cadquery, some months ago, I had a problem with some of the results that boolean operations gave, due to the fact, afaik, that in openscad code is converted to triangle meshes, whereas in cadquery it is a mathematical surface, which can have discontinuities. (A sphere is represented on screen as a circle with a curved line).
I'm not sure that a simple translation will be enough, since if I differenced a sphere from a cylinder, say, in openscad I saw a good representation, but in cadquery, depending on the rotation of the sphere I did not.
I can't find my test cadquery code, but here is an openscad script that may show the problem, if you want to translate that...
$fn=200;
difference(){
cylinder(h=10,d=100);
translate([0,0,255])
sphere(d=500);
}
Iirc that the equivalent in cadquery required the sphere to be rotated such that its 'line' was not in the cylinder.
I also could not find an active forum, although there were a few posters on reddit.
On 08/02/2025 09:47, 张友宝 via Discuss wrote:
Hi developers,
With the arrival of free functions in CadQuery(https://github.com/CadQuery/cadquery), I believe it's the perfect time to bridge the OpenSCAD and CadQuery communities.
I've tried manually translating a simple OpenSCAD script into CadQuery, and it is quite straightforward. To benefit both communities, I'm thinking about automatically translating OpenSCAD scripts into CadQuery scripts.
To perform the translation, we need to parse the OpenSCAD script. Since the OpenSCAD source code already handles parsing, we can utilize the parsed AST for our translation.
To expedite and professionalize the process, I am seeking opinions and suggestions.
OpenSCAD Scripting Code:
/The OpenSCAD code begin*******/
module Flange_01() {
difference() {
cylinder(10, 100, 100, $fn = 30);
r = 80;
for (i = [0:90:359]) {
translate([r * cos(i), r * sin(i), -1])
cylinder(12, 10, 10, $fn = 30);
translate([0, 0, -1])
cylinder(12, 50, 50, $fn = 50);
}
}
}
Flange_01();
/The OpenSCAD code end*********/
Manually Translated CadQuery Scripting Code:
###########The CadQuery code begin###########
from cadquery.func import *
from cadquery.vis import show
import math
r1 = 100
part1 = cylinder(2 * r1, 10)
r2 = 80
theta_values = [0, math.pi / 2, math.pi, 3 * math.pi / 2]
for theta in theta_values:
part2 = cylinder(2 * 10, 12).moved(x = r2 * math.cos(theta), y = r2 * math.sin(theta))
part1 -= part2
part2 = cylinder(2 * 50, 12).moved(x = 0, y = 0)
part1 -= part2
show(part1)
###########The CadQuery code end#############
Best regards,
Youbao
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Dear Leonard,
I guess the broken has already fixed. I am the the latest stable version (V2.5.2) of CadQuery with Anaconda distribution. It looks like:
*****Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32 *****
Best regards,
Youbao
-----Original Messages-----
From:"Leonard Martin Struttmann via Discuss" discuss@lists.openscad.org
Sent Time:2025-02-08 21:50:10 (Saturday)
To: "OpenSCAD general discussion Mailing-list" discuss@lists.openscad.org
Cc: "Leonard Martin Struttmann" lenstruttmann@gmail.com
Subject: [OpenSCAD] Re: About Automatically Translating OpenSCAD Scripting Code into CadQuery Scripting Code (Python Code)
The last time that I attempted to install and run CADquery failed (due to, I think, changes in numpy). Has this been fixed?
On Sat, Feb 8, 2025 at 6:44 AM Guenther Sohler via Discuss discuss@lists.openscad.org wrote:
Translating OpenSCAD code into another language is not difficult and you do not even need a parser for that.
Just "output" the parsed OpenSCAD AST Tree into another language.
I did so already and adding yet another language maybe requires adding a common "plug-in" layer.
merging to the cadquery community has already started, just watch
https://www.reddit.com/r/OpenPythonSCAD/comments/1hs4hmy/using_cadquery_features_in_your_design/
On Sat, Feb 8, 2025 at 1:25 PM 张友宝 via Discuss discuss@lists.openscad.org wrote:
Hi developers,
With the arrival of free functions in CadQuery(https://github.com/CadQuery/cadquery), I believe it's the perfect time to bridge the OpenSCAD and CadQuery communities.
I've tried manually translating a simple OpenSCAD script into CadQuery, and it is quite straightforward. To benefit both communities, I'm thinking about automatically translating OpenSCAD scripts into CadQuery scripts.
To perform the translation, we need to parse the OpenSCAD script. Since the OpenSCAD source code already handles parsing, we can utilize the parsed AST for our translation.
To expedite and professionalize the process, I am seeking opinions and suggestions.
OpenSCAD Scripting Code:
/The OpenSCAD code begin*******/
module Flange_01() {
difference() {
cylinder(10, 100, 100, $fn = 30);
r = 80;
for (i = [0:90:359]) {
translate([r * cos(i), r * sin(i), -1])
cylinder(12, 10, 10, $fn = 30);
translate([0, 0, -1])
cylinder(12, 50, 50, $fn = 50);
}
}
}
Flange_01();
/The OpenSCAD code end*********/
Manually Translated CadQuery Scripting Code:
###########The CadQuery code begin###########
from cadquery.func import *
from cadquery.vis import show
import math
r1 = 100
part1 = cylinder(2 * r1, 10)
r2 = 80
theta_values = [0, math.pi / 2, math.pi, 3 * math.pi / 2]
for theta in theta_values:
part2 = cylinder(2 * 10, 12).moved(x = r2 * math.cos(theta), y = r2 * math.sin(theta))
part1 -= part2
part2 = cylinder(2 * 50, 12).moved(x = 0, y = 0)
part1 -= part2
show(part1)
###########The CadQuery code end#############
Best regards,
Youbao
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
What is the big deal about CadQuery? What does it offer that OpenSCAD
lacks?
Jon
--
This email has been checked for viruses by AVG antivirus software.
www.avg.com
Dear gsohler,
Could you please explain the following response in a little bit detail? I am very interesting it.
Translating OpenSCAD code into another language is not difficult and you do not even need a parser for that.
Just "output" the parsed OpenSCAD AST Tree into another language.
I did so already and adding yet another language maybe requires adding a common "plug-in" layer.
Best regards,
Youbao
-----Original Messages-----
From:"Guenther Sohler via Discuss" discuss@lists.openscad.org
Sent Time:2025-02-08 20:44:29 (Saturday)
To: "OpenSCAD general discussion Mailing-list" discuss@lists.openscad.org
Cc: "Guenther Sohler" guenther.sohler@gmail.com
Subject: [OpenSCAD] Re: About Automatically Translating OpenSCAD Scripting Code into CadQuery Scripting Code (Python Code)
Translating OpenSCAD code into another language is not difficult and you do not even need a parser for that.
Just "output" the parsed OpenSCAD AST Tree into another language.
I did so already and adding yet another language maybe requires adding a common "plug-in" layer.
merging to the cadquery community has already started, just watch
https://www.reddit.com/r/OpenPythonSCAD/comments/1hs4hmy/using_cadquery_features_in_your_design/
On Sat, Feb 8, 2025 at 1:25 PM 张友宝 via Discuss discuss@lists.openscad.org wrote:
Hi developers,
With the arrival of free functions in CadQuery(https://github.com/CadQuery/cadquery), I believe it's the perfect time to bridge the OpenSCAD and CadQuery communities.
I've tried manually translating a simple OpenSCAD script into CadQuery, and it is quite straightforward. To benefit both communities, I'm thinking about automatically translating OpenSCAD scripts into CadQuery scripts.
To perform the translation, we need to parse the OpenSCAD script. Since the OpenSCAD source code already handles parsing, we can utilize the parsed AST for our translation.
To expedite and professionalize the process, I am seeking opinions and suggestions.
OpenSCAD Scripting Code:
/The OpenSCAD code begin*******/
module Flange_01() {
difference() {
cylinder(10, 100, 100, $fn = 30);
r = 80;
for (i = [0:90:359]) {
translate([r * cos(i), r * sin(i), -1])
cylinder(12, 10, 10, $fn = 30);
translate([0, 0, -1])
cylinder(12, 50, 50, $fn = 50);
}
}
}
Flange_01();
/The OpenSCAD code end*********/
Manually Translated CadQuery Scripting Code:
###########The CadQuery code begin###########
from cadquery.func import *
from cadquery.vis import show
import math
r1 = 100
part1 = cylinder(2 * r1, 10)
r2 = 80
theta_values = [0, math.pi / 2, math.pi, 3 * math.pi / 2]
for theta in theta_values:
part2 = cylinder(2 * 10, 12).moved(x = r2 * math.cos(theta), y = r2 * math.sin(theta))
part1 -= part2
part2 = cylinder(2 * 50, 12).moved(x = 0, y = 0)
part1 -= part2
show(part1)
###########The CadQuery code end#############
Best regards,
Youbao
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
My guess is that its chief appeal lies in being Python-based as opposed to
having to learn the functional-style OpenSCAD language.
On Sat, Feb 8, 2025 at 9:45 AM Jon Bondy via Discuss <
discuss@lists.openscad.org> wrote:
What is the big deal about CadQuery? What does it offer that OpenSCAD
lacks?
Jon
--
This email has been checked for viruses by AVG antivirus software.
www.avg.com
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
When I was looking into using CadQuery I was interested in using it to
convert STEP files. However, since I could not get it to run, I moved to
using PrusaSlicer.
On Sat, Feb 8, 2025 at 10:47 AM Father Horton via Discuss <
discuss@lists.openscad.org> wrote:
My guess is that its chief appeal lies in being Python-based as opposed to
having to learn the functional-style OpenSCAD language.
On Sat, Feb 8, 2025 at 9:45 AM Jon Bondy via Discuss <
discuss@lists.openscad.org> wrote:
What is the big deal about CadQuery? What does it offer that OpenSCAD
lacks?
Jon
--
This email has been checked for viruses by AVG antivirus software.
www.avg.com
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org