discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

simple BOSL question

A
adrianv
Tue, Jan 5, 2021 6:25 PM

The problem is that difference() the function returns a region, which is a
list of paths, instead of just a single path, which is a list of points.  It
does this because a difference might contain holes, or disconnected pieces.
If you are sure that your result is a single path you can just extract the
first path on the list, e.g. with difference(...)[0] to get the first path
entry.  That fixes your code below.

You can also debug things like this using the echo command.  If you do
"echo(Semi());" you'll see that there are extra brackets--though I'll grant
that you need to be looking closely.  Output with echo can be overwhelming
if you generate a lot of points, but you can scale back your point count for
debugging purposes when you don't understand what's going wrong.

Lastly, implementation of boolean operations like difference on paths is a
major technical challenge to implement in OpenSCAD and those operations are
more likely to both run slowly and to possibly fail in unusual cases.  I'd
suggesting using them as the method of last resort.  If you have another
way to generate your object it's probably better to choose that alternative.
In this case, you can make a semicircle using arc(), so that is better.
(But maybe you are working towards something more complex?)  You can also
just cut points out of the point list by using select().

jon_bondy wrote

I tried to write a function that returns a list-of-points, but I get
this error

ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
or have length less than 3", in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366

TRACE: called by 'skin' in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353

TRACE: called by 'skin' in file Skin Test.scad, line 14

with this code:

include <BOSL2/std.scad>
include <BOSL2/skin.scad>

od = 101.75;
id = od - 2 * 3.2;
th = 3;

function Semi() =
    difference(
        circle(d = id - 3*th),
        // cut out just over 1/2
        move([-990, -500], square(1000)));

skin(
    [square([2,.2], center=true), Semi()], z=[0,3],
    slices=40,sampling="length",method="reindex");


OpenSCAD mailing list

Discuss@.openscad

The problem is that difference() the function returns a region, which is a list of paths, instead of just a single path, which is a list of points. It does this because a difference might contain holes, or disconnected pieces. If you are sure that your result is a single path you can just extract the first path on the list, e.g. with difference(...)[0] to get the first path entry. That fixes your code below. You can also debug things like this using the echo command. If you do "echo(Semi());" you'll see that there are extra brackets--though I'll grant that you need to be looking closely. Output with echo can be overwhelming if you generate a lot of points, but you can scale back your point count for debugging purposes when you don't understand what's going wrong. Lastly, implementation of boolean operations like difference on paths is a major technical challenge to implement in OpenSCAD and those operations are more likely to both run slowly and to possibly fail in unusual cases. I'd suggesting using them as the method of last resort. If you have another way to generate your object it's probably better to choose that alternative. In this case, you can make a semicircle using arc(), so that is better. (But maybe you are working towards something more complex?) You can also just cut points out of the point list by using select(). jon_bondy wrote > I tried to write a function that returns a list-of-points, but I get > this error > > ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths > or have length less than 3", in file > C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366 > > TRACE: called by 'skin' in file > C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353 > > TRACE: called by 'skin' in file Skin Test.scad, line 14 > > > > > with this code: > > > include &lt;BOSL2/std.scad&gt; > include &lt;BOSL2/skin.scad&gt; > > od = 101.75; > id = od - 2 * 3.2; > th = 3; > > function Semi() = >     difference( >         circle(d = id - 3*th), >         // cut out just over 1/2 >         move([-990, -500], square(1000))); > > skin( >     [square([2,.2], center=true), Semi()], z=[0,3], >     slices=40,sampling="length",method="reindex"); > > > _______________________________________________ > OpenSCAD mailing list > Discuss@.openscad > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Sent from: http://forum.openscad.org/
RD
Revar Desmera
Tue, Jan 5, 2021 6:54 PM

This does suggest that we make skin() accept regions with exactly one path.

-Revar

On Jan 5, 2021, at 10:25 AM, adrianv avm4@cornell.edu wrote:

The problem is that difference() the function returns a region, which is a
list of paths, instead of just a single path, which is a list of points.  It
does this because a difference might contain holes, or disconnected pieces.
If you are sure that your result is a single path you can just extract the
first path on the list, e.g. with difference(...)[0] to get the first path
entry.  That fixes your code below.

You can also debug things like this using the echo command.  If you do
"echo(Semi());" you'll see that there are extra brackets--though I'll grant
that you need to be looking closely.  Output with echo can be overwhelming
if you generate a lot of points, but you can scale back your point count for
debugging purposes when you don't understand what's going wrong.

Lastly, implementation of boolean operations like difference on paths is a
major technical challenge to implement in OpenSCAD and those operations are
more likely to both run slowly and to possibly fail in unusual cases.  I'd
suggesting using them as the method of last resort.  If you have another
way to generate your object it's probably better to choose that alternative.
In this case, you can make a semicircle using arc(), so that is better.
(But maybe you are working towards something more complex?)  You can also
just cut points out of the point list by using select().

jon_bondy wrote

I tried to write a function that returns a list-of-points, but I get
this error

ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
or have length less than 3", in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366

TRACE: called by 'skin' in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353

TRACE: called by 'skin' in file Skin Test.scad, line 14

with this code:

include <BOSL2/std.scad>
include <BOSL2/skin.scad>

od = 101.75;
id = od - 2 * 3.2;
th = 3;

function Semi() =
difference(
circle(d = id - 3*th),
// cut out just over 1/2
move([-990, -500], square(1000)));

skin(
[square([2,.2], center=true), Semi()], z=[0,3],
slices=40,sampling="length",method="reindex");


OpenSCAD mailing list

Discuss@.openscad

This does suggest that we make `skin()` accept regions with exactly one path. -Revar > On Jan 5, 2021, at 10:25 AM, adrianv <avm4@cornell.edu> wrote: > > The problem is that difference() the function returns a region, which is a > list of paths, instead of just a single path, which is a list of points. It > does this because a difference might contain holes, or disconnected pieces. > If you are sure that your result is a single path you can just extract the > first path on the list, e.g. with difference(...)[0] to get the first path > entry. That fixes your code below. > > You can also debug things like this using the echo command. If you do > "echo(Semi());" you'll see that there are extra brackets--though I'll grant > that you need to be looking closely. Output with echo can be overwhelming > if you generate a lot of points, but you can scale back your point count for > debugging purposes when you don't understand what's going wrong. > > Lastly, implementation of boolean operations like difference on paths is a > major technical challenge to implement in OpenSCAD and those operations are > more likely to both run slowly and to possibly fail in unusual cases. I'd > suggesting using them as the method of last resort. If you have another > way to generate your object it's probably better to choose that alternative. > In this case, you can make a semicircle using arc(), so that is better. > (But maybe you are working towards something more complex?) You can also > just cut points out of the point list by using select(). > > > jon_bondy wrote >> I tried to write a function that returns a list-of-points, but I get >> this error >> >> ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths >> or have length less than 3", in file >> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366 >> >> TRACE: called by 'skin' in file >> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353 >> >> TRACE: called by 'skin' in file Skin Test.scad, line 14 >> >> >> >> >> with this code: >> >> >> include &lt;BOSL2/std.scad&gt; >> include &lt;BOSL2/skin.scad&gt; >> >> od = 101.75; >> id = od - 2 * 3.2; >> th = 3; >> >> function Semi() = >> difference( >> circle(d = id - 3*th), >> // cut out just over 1/2 >> move([-990, -500], square(1000))); >> >> skin( >> [square([2,.2], center=true), Semi()], z=[0,3], >> slices=40,sampling="length",method="reindex"); >> >> >> _______________________________________________ >> OpenSCAD mailing list > >> Discuss@.openscad > >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
A
adrianv
Tue, Jan 5, 2021 7:18 PM

If you want to go there then presumably all functions that take a path should
also take regions with exactly one path.

RevarBat wrote

This does suggest that we make skin() accept regions with exactly one
path.

-Revar

On Jan 5, 2021, at 10:25 AM, adrianv <

avm4@

> wrote:

The problem is that difference() the function returns a region, which is
a
list of paths, instead of just a single path, which is a list of points.
It
does this because a difference might contain holes, or disconnected
pieces.
If you are sure that your result is a single path you can just extract
the
first path on the list, e.g. with difference(...)[0] to get the first
path
entry.  That fixes your code below.

You can also debug things like this using the echo command.  If you do
"echo(Semi());" you'll see that there are extra brackets--though I'll
grant
that you need to be looking closely.  Output with echo can be
overwhelming
if you generate a lot of points, but you can scale back your point count
for
debugging purposes when you don't understand what's going wrong.

Lastly, implementation of boolean operations like difference on paths is
a
major technical challenge to implement in OpenSCAD and those operations
are
more likely to both run slowly and to possibly fail in unusual cases.
I'd
suggesting using them as the method of last resort.  If you have another
way to generate your object it's probably better to choose that
alternative.
In this case, you can make a semicircle using arc(), so that is better.
(But maybe you are working towards something more complex?)  You can also
just cut points out of the point list by using select().

jon_bondy wrote

I tried to write a function that returns a list-of-points, but I get
this error

ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
or have length less than 3", in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366

TRACE: called by 'skin' in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353

TRACE: called by 'skin' in file Skin Test.scad, line 14

with this code:

include <BOSL2/std.scad>
include <BOSL2/skin.scad>

od = 101.75;
id = od - 2 * 3.2;
th = 3;

function Semi() =
difference(
circle(d = id - 3*th),
// cut out just over 1/2
move([-990, -500], square(1000)));

skin(
[square([2,.2], center=true), Semi()], z=[0,3],
slices=40,sampling="length",method="reindex");


OpenSCAD mailing list

Discuss@.openscad

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list

Discuss@.openscad

Discuss@.openscad

If you want to go there then presumably all functions that take a path should also take regions with exactly one path. RevarBat wrote > This does suggest that we make `skin()` accept regions with exactly one > path. > > -Revar > > >> On Jan 5, 2021, at 10:25 AM, adrianv &lt; > avm4@ > &gt; wrote: >> >> The problem is that difference() the function returns a region, which is >> a >> list of paths, instead of just a single path, which is a list of points. >> It >> does this because a difference might contain holes, or disconnected >> pieces. >> If you are sure that your result is a single path you can just extract >> the >> first path on the list, e.g. with difference(...)[0] to get the first >> path >> entry. That fixes your code below. >> >> You can also debug things like this using the echo command. If you do >> "echo(Semi());" you'll see that there are extra brackets--though I'll >> grant >> that you need to be looking closely. Output with echo can be >> overwhelming >> if you generate a lot of points, but you can scale back your point count >> for >> debugging purposes when you don't understand what's going wrong. >> >> Lastly, implementation of boolean operations like difference on paths is >> a >> major technical challenge to implement in OpenSCAD and those operations >> are >> more likely to both run slowly and to possibly fail in unusual cases. >> I'd >> suggesting using them as the method of last resort. If you have another >> way to generate your object it's probably better to choose that >> alternative. >> In this case, you can make a semicircle using arc(), so that is better. >> (But maybe you are working towards something more complex?) You can also >> just cut points out of the point list by using select(). >> >> >> jon_bondy wrote >>> I tried to write a function that returns a list-of-points, but I get >>> this error >>> >>> ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths >>> or have length less than 3", in file >>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366 >>> >>> TRACE: called by 'skin' in file >>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353 >>> >>> TRACE: called by 'skin' in file Skin Test.scad, line 14 >>> >>> >>> >>> >>> with this code: >>> >>> >>> include &lt;BOSL2/std.scad&gt; >>> include &lt;BOSL2/skin.scad&gt; >>> >>> od = 101.75; >>> id = od - 2 * 3.2; >>> th = 3; >>> >>> function Semi() = >>> difference( >>> circle(d = id - 3*th), >>> // cut out just over 1/2 >>> move([-990, -500], square(1000))); >>> >>> skin( >>> [square([2,.2], center=true), Semi()], z=[0,3], >>> slices=40,sampling="length",method="reindex"); >>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >> >>> Discuss@.openscad >> >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> > Discuss@.openscad >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > Discuss@.openscad > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Sent from: http://forum.openscad.org/
J
jon
Tue, Jan 5, 2021 8:38 PM

Thank you very much!

Jon

On 1/5/2021 1:25 PM, adrianv wrote:

The problem is that difference() the function returns a region, which is a
list of paths, instead of just a single path, which is a list of points.  It
does this because a difference might contain holes, or disconnected pieces.
If you are sure that your result is a single path you can just extract the
first path on the list, e.g. with difference(...)[0] to get the first path
entry.  That fixes your code below.

You can also debug things like this using the echo command.  If you do
"echo(Semi());" you'll see that there are extra brackets--though I'll grant
that you need to be looking closely.  Output with echo can be overwhelming
if you generate a lot of points, but you can scale back your point count for
debugging purposes when you don't understand what's going wrong.

Lastly, implementation of boolean operations like difference on paths is a
major technical challenge to implement in OpenSCAD and those operations are
more likely to both run slowly and to possibly fail in unusual cases.  I'd
suggesting using them as the method of last resort.  If you have another
way to generate your object it's probably better to choose that alternative.
In this case, you can make a semicircle using arc(), so that is better.
(But maybe you are working towards something more complex?)  You can also
just cut points out of the point list by using select().

jon_bondy wrote

I tried to write a function that returns a list-of-points, but I get
this error

ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
or have length less than 3", in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366

TRACE: called by 'skin' in file
C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353

TRACE: called by 'skin' in file Skin Test.scad, line 14

with this code:

include <BOSL2/std.scad>
include <BOSL2/skin.scad>

od = 101.75;
id = od - 2 * 3.2;
th = 3;

function Semi() =
    difference(
        circle(d = id - 3*th),
        // cut out just over 1/2
        move([-990, -500], square(1000)));

skin(
    [square([2,.2], center=true), Semi()], z=[0,3],
    slices=40,sampling="length",method="reindex");


OpenSCAD mailing list
Discuss@.openscad
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Thank you very much! Jon On 1/5/2021 1:25 PM, adrianv wrote: > The problem is that difference() the function returns a region, which is a > list of paths, instead of just a single path, which is a list of points. It > does this because a difference might contain holes, or disconnected pieces. > If you are sure that your result is a single path you can just extract the > first path on the list, e.g. with difference(...)[0] to get the first path > entry. That fixes your code below. > > You can also debug things like this using the echo command. If you do > "echo(Semi());" you'll see that there are extra brackets--though I'll grant > that you need to be looking closely. Output with echo can be overwhelming > if you generate a lot of points, but you can scale back your point count for > debugging purposes when you don't understand what's going wrong. > > Lastly, implementation of boolean operations like difference on paths is a > major technical challenge to implement in OpenSCAD and those operations are > more likely to both run slowly and to possibly fail in unusual cases. I'd > suggesting using them as the method of last resort. If you have another > way to generate your object it's probably better to choose that alternative. > In this case, you can make a semicircle using arc(), so that is better. > (But maybe you are working towards something more complex?) You can also > just cut points out of the point list by using select(). > > > jon_bondy wrote >> I tried to write a function that returns a list-of-points, but I get >> this error >> >> ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths >> or have length less than 3", in file >> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366 >> >> TRACE: called by 'skin' in file >> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353 >> >> TRACE: called by 'skin' in file Skin Test.scad, line 14 >> >> >> >> >> with this code: >> >> >> include &lt;BOSL2/std.scad&gt; >> include &lt;BOSL2/skin.scad&gt; >> >> od = 101.75; >> id = od - 2 * 3.2; >> th = 3; >> >> function Semi() = >>     difference( >>         circle(d = id - 3*th), >>         // cut out just over 1/2 >>         move([-990, -500], square(1000))); >> >> skin( >>     [square([2,.2], center=true), Semi()], z=[0,3], >>     slices=40,sampling="length",method="reindex"); >> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@.openscad >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org