2D array

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

2D array

Maurin Donneaud
Bonjour !

How can I parse a 2D array ?
Something like that !?

:-(

/////////////////////////////////////////////////////////////////
for(i = [0 : 3]) // rows
{
        for(j = [0 : 3]) // columns
        {
          a[ i, j];
        }
}

a = [
        [0,1,1,0],
        [1,0,0,1],
        [1,1,1,1],
        [1,0,0,1]
        ];


Regards,

Maurn


Reply | Threaded
Open this post in threaded view
|

Re: 2D array

Alan Cox
On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

> Bonjour !
>
> How can I parse a 2D array ?
> Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan


Reply | Threaded
Open this post in threaded view
|

Re: 2D array

clothbot
You're thinking too hard.  The matrix is already in vector-of-vector form so the following works:

for(i = [0 : 3]) // rows
{
echo(str("row:",i));
for(j = [0 : 3]) // columns
{
echo(a[i][j]);
}
}

a = [
[0,1,1,0],
[1,0,0,1],
[1,1,1,1],
[1,0,0,1]
];

cube();


On 2012-06-05, at 3:02 PM, Alan Cox wrote:

On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

Bonjour !

How can I parse a 2D array ?
Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/



Reply | Threaded
Open this post in threaded view
|

Re: 2D array

clothbot
…or to allow for variable-length rows, do something like the following:

for(i = [0 : len(a)-1]) // rows
{
echo(str("row:",i));
for(j = [0 : len(a[i])-1]) // columns
{
echo(a[i][j]);
}
}

a = [
[0,1,1,0],
[1,0,0,1],
[1,1,1,1],
[1,0,0,1]
];

cube();


On 2012-06-05, at 3:09 PM, Andrew Plumb wrote:

You're thinking too hard.  The matrix is already in vector-of-vector form so the following works:

for(i = [0 : 3]) // rows
{
echo(str("row:",i));
for(j = [0 : 3]) // columns
{
echo(a[i][j]);
}
}

a = [
[0,1,1,0],
[1,0,0,1],
[1,1,1,1],
[1,0,0,1]
];

cube();


On 2012-06-05, at 3:02 PM, Alan Cox wrote:

On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

Bonjour !

How can I parse a 2D array ?
Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/



Reply | Threaded
Open this post in threaded view
|

Re: 2D array

nophead
In reply to this post by Alan Cox
a[i][j] as the array is actually a list of lists.

On 5 June 2012 20:02, Alan Cox <[hidden email]> wrote:
On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

> Bonjour !
>
> How can I parse a 2D array ?
> Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: 2D array

Peter Falke
Hi Guys,
 
len() is an undocumented command of OpenSCAD in the openscad wiki (I just checked.)
Are there any other such commands around?
 
Gruß,
 
TakeItAndRun

2012/6/5 nop head <[hidden email]>
a[i][j] as the array is actually a list of lists.


On 5 June 2012 20:02, Alan Cox <[hidden email]> wrote:
On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

> Bonjour !
>
> How can I parse a 2D array ?
> Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

Reply | Threaded
Open this post in threaded view
|

Re: 2D array

kintel
Administrator
On Jun 6, 2012, at 18:35 , Peter Falke wrote:

> len() is an undocumented command of OpenSCAD in the openscad wiki (I just checked.)
> Are there any other such commands around?

len() was added in OpenSCAD 2011.12.
The wiki documentation isn't always up to date as it's community managed.

For an overview over actual changes in recent versions, please consult the release notes:

https://github.com/openscad/openscad/blob/master/RELEASE_NOTES

 -Marius


Reply | Threaded
Open this post in threaded view
|

Re: 2D array

Peter Falke
In reply to this post by nophead
Hi nop head, hi Alan
 
I was very impressed with what you(nophead) did with openscad and python for your mendel90.
Unfortunately I never got it to compile on my computer (a netbook running windows 7 starter. I got python installed and tryed the following, but never got past the syntax error: see attachment.).
 
When I model complex assemblies ,I now let scad print the part list via echo() directly when it compiles.
 
I would hope that things will go the other way around, Alan, and openscad will in the future provide a print to file command for part lists. Like:
 
export_txt(file="partlist.txt","Nut M3     :",number_nut_m3);
 
What I also really would like to see is an export option for stl's directly out of scad. I could then output a separate stl for every part of my assembly, but also had the option to assemble a number of parts together for a print plate as well, without going through other programs that then the next guy would have to install/learn as well.
 
Like:
export_stl(file="cubus.stl",my_module_cubus(l=5));
 
 
Gruß,
 
TakeItAndRun
 


 
2012/6/5 nop head <[hidden email]>
a[i][j] as the array is actually a list of lists.


On 5 June 2012 20:02, Alan Cox <[hidden email]> wrote:
On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

> Bonjour !
>
> How can I parse a 2D array ?
> Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!


Error runing make_machine.txt (972 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: 2D array

nophead


On 6 June 2012 18:27, Peter Falke <[hidden email]> wrote:
Hi nop head, hi Alan
 
I was very impressed with what you(nophead) did with openscad and python for your mendel90.
Unfortunately I never got it to compile on my computer (a netbook running windows 7 starter. I got python installed and tryed the following, but never got past the syntax error: see attachment.).

It looks like you did "make_machine [mendel]" instead of simply "make_machine mendel". The [mendel|sturdy|] notation was intended so show you had to pass one of the list.

 
When I model complex assemblies ,I now let scad print the part list via echo() directly when it compiles.
 
I would hope that things will go the other way around, Alan, and openscad will in the future provide a print to file command for part lists. Like:
 
export_txt(file="partlist.txt","Nut M3     :",number_nut_m3);
 
What I also really would like to see is an export option for stl's directly out of scad. I could then output a separate stl for every part of my assembly, but also had the option to assemble a number of parts together for a print plate as well, without going through other programs that then the next guy would have to install/learn as well.
 
Like:
export_stl(file="cubus.stl",my_module_cubus(l=5));
 
 
Gruß,
 
TakeItAndRun
 


 
2012/6/5 nop head <[hidden email]>
a[i][j] as the array is actually a list of lists.


On 5 June 2012 20:02, Alan Cox <[hidden email]> wrote:
On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

> Bonjour !
>
> How can I parse a 2D array ?
> Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: 2D array

Peter Falke
Hi all, hi nop head, hi Marius,
 
Nop head, I tried also
>>> make_machine mendel  
with the same result:  
SyntaxError: invalid syntax.


Marius, thanks for the link to the release notes. I'm using OpenSCAD on windows. There is no direct link to the release notes from the OpenSCAD .exe .
 
I added len() to the OpenSCAD wiki:
Somebody please have a look and check it for spelling and syntax. Thanks. 
 
The wiki helped me a lot to learn the basics of using openscad.
After reading the reales_notes i noted that the manual is badly out of dead.
( .. dead? Hm, bad  pun. out of date!)
Someone interested to put some work in here, together?
 
Bye,
 
TakeItAndRun
 
 
 
2012/6/6 nop head <[hidden email]>


On 6 June 2012 18:27, Peter Falke <[hidden email]> wrote:
Hi nop head, hi Alan
 
I was very impressed with what you(nophead) did with openscad and python for your mendel90.
Unfortunately I never got it to compile on my computer (a netbook running windows 7 starter. I got python installed and tryed the following, but never got past the syntax error: see attachment.).

It looks like you did "make_machine [mendel]" instead of simply "make_machine mendel". The [mendel|sturdy|] notation was intended so show you had to pass one of the list.

 
When I model complex assemblies ,I now let scad print the part list via echo() directly when it compiles.
 
I would hope that things will go the other way around, Alan, and openscad will in the future provide a print to file command for part lists. Like:
 
export_txt(file="partlist.txt","Nut M3     :",number_nut_m3);
 
What I also really would like to see is an export option for stl's directly out of scad. I could then output a separate stl for every part of my assembly, but also had the option to assemble a number of parts together for a print plate as well, without going through other programs that then the next guy would have to install/learn as well.
 
Like:
export_stl(file="cubus.stl",my_module_cubus(l=5));
 
 
Gruß,
 
TakeItAndRun
 


 
2012/6/5 nop head <[hidden email]>
a[i][j] as the array is actually a list of lists.


On 5 June 2012 20:02, Alan Cox <[hidden email]> wrote:
On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

> Bonjour !
>
> How can I parse a 2D array ?
> Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

Reply | Threaded
Open this post in threaded view
|

Re: 2D array

nophead


On 11 June 2012 14:03, Peter Falke <[hidden email]> wrote:
Hi all, hi nop head, hi Marius,
 
Nop head, I tried also
>>> make_machine mendel  
with the same result:  
SyntaxError: invalid syntax.

Looks like you are typing the command line to the Python interpreter instead of the command interpreter / shell. The Python interpreter only understands Python statements. 

"make_machine mendel" typed at a command prompt should run make_machine.py passing "mendel" as a parameter.
 


Marius, thanks for the link to the release notes. I'm using OpenSCAD on windows. There is no direct link to the release notes from the OpenSCAD .exe .
 
I added len() to the OpenSCAD wiki:
Somebody please have a look and check it for spelling and syntax. Thanks. 
 
The wiki helped me a lot to learn the basics of using openscad.
After reading the reales_notes i noted that the manual is badly out of dead.
( .. dead? Hm, bad  pun. out of date!)
Someone interested to put some work in here, together?
 
Bye,
 
TakeItAndRun
 
 
 
2012/6/6 nop head <[hidden email]>


On 6 June 2012 18:27, Peter Falke <[hidden email]> wrote:
Hi nop head, hi Alan
 
I was very impressed with what you(nophead) did with openscad and python for your mendel90.
Unfortunately I never got it to compile on my computer (a netbook running windows 7 starter. I got python installed and tryed the following, but never got past the syntax error: see attachment.).

It looks like you did "make_machine [mendel]" instead of simply "make_machine mendel". The [mendel|sturdy|] notation was intended so show you had to pass one of the list.

 
When I model complex assemblies ,I now let scad print the part list via echo() directly when it compiles.
 
I would hope that things will go the other way around, Alan, and openscad will in the future provide a print to file command for part lists. Like:
 
export_txt(file="partlist.txt","Nut M3     :",number_nut_m3);
 
What I also really would like to see is an export option for stl's directly out of scad. I could then output a separate stl for every part of my assembly, but also had the option to assemble a number of parts together for a print plate as well, without going through other programs that then the next guy would have to install/learn as well.
 
Like:
export_stl(file="cubus.stl",my_module_cubus(l=5));
 
 
Gruß,
 
TakeItAndRun
 


 
2012/6/5 nop head <[hidden email]>
a[i][j] as the array is actually a list of lists.


On 5 June 2012 20:02, Alan Cox <[hidden email]> wrote:
On Tue, 5 Jun 2012 20:48:38 +0200
Maurin Donneaud <[hidden email]> wrote:

> Bonjour !
>
> How can I parse a 2D array ?
> Something like that !?


a[i * 4 + j]


I'm increasingly finding the trick is to write programs in real languages
that output OpenSCAD files though. There are fundamental things missing
like class heirarchies, function pointers, structures and various kinds
of iteration.

Quite possibly those not being in OpenSCAD but generating OpenSCAD is the
right thing anyway.

Alan

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




--
[hidden email]

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad