build 2d array from string

Discussions about SOFTIMAGEs© Interactive Creative Environment©
clankill3r
Posts: 131
Joined: 21 Oct 2012, 13:36

build 2d array from string

Post by clankill3r » 31 Oct 2012, 12:42

i want a 2d array with intergers.

for example:
[12][32][43][24]
[54][54][26][78]
[35]75][34][31]
[87][64][43][11]

I use a string formatted like 12,32,56,23;23,45,45,12;76...etc
The numbers are rotations, for a grid of boxes i want to set the rotation for each box.
I also have other numbers for a new frame but first i want to tackle the problem of reading getting one frame done.

I watched like every screenshot and video on stephen blairs blog but 2d arrays never come up.
This is what i got so far.
Image
Here you can see the array and the boxes.
Image

Now how can i split up the array i have in a 2d array?

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: build 2d array from string

Post by xsisupport » 31 Oct 2012, 15:05

I don't know whether 2D arrays are the best approach, but here's one way to build a 2d array from a string.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

clankill3r
Posts: 131
Joined: 21 Oct 2012, 13:36

Re: build 2d array from string

Post by clankill3r » 31 Oct 2012, 17:38

yeah i think i go for jus one long array, will make things a lot easier.

Anyway, one more
How can a string like: 1 2 3 4; 5 6 7 8; 9 10 11 12
be formed into one array?
Image

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 22:38
Location: St. Thomas, Ontario

Re: build 2d array from string

Post by Daniel Brassard » 31 Oct 2012, 20:30

Several ways, based on how you define your string delimiter. I prefer a comma separated string (CSV) which is more convenient and can feed into the array more easily using a string to array node, no need to split the string then.

As an example, see how I did it with the cube in the first post here:

viewtopic.php?f=41&t=1467
$ifndef "Softimage"
set "Softimage" "true"
$endif

iamVFX
Posts: 697
Joined: 24 Sep 2010, 16:28

Re: build 2d array from string

Post by iamVFX » 01 Nov 2012, 08:54

Daniel Brassard wrote:I prefer a comma separated string (CSV) which is more convenient and can feed into the array more easily using a string to array node
Just to note: String to Array node can cause crashes in SI 2012

clankill3r
Posts: 131
Joined: 21 Oct 2012, 13:36

Re: build 2d array from string

Post by clankill3r » 01 Nov 2012, 11:53

noted.

nice topic daniel.

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 22:38
Location: St. Thomas, Ontario

Re: build 2d array from string

Post by Daniel Brassard » 01 Nov 2012, 12:06

And examples of the modulo trick topic here:

viewtopic.php?f=41&t=1842
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: build 2d array from string

Post by xsisupport » 01 Nov 2012, 12:37

Daniel Brassard wrote:And examples of the modulo trick topic here:

viewtopic.php?f=41&t=1842
I'm not sure why you need modulo ?
If it is a flattened array, then the array index = row*width + column, no?
http://xsisupport.files.wordpress.com/2 ... darray.png
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 22:38
Location: St. Thomas, Ontario

Re: build 2d array from string

Post by Daniel Brassard » 01 Nov 2012, 16:06

I'm not sure why you need modulo ?
General knowledge at this point as he asked for a screen of the modulo trick. Maybe totally unrelated to the problem/issue now.
$ifndef "Softimage"
set "Softimage" "true"
$endif