Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / ForLoop multidimensional
  RSS 2.0 ATOM  

ForLoop multidimensional
Rate this thread
 
60693
 
Permlink of this thread  
avatar
  • Total Posts: 114
  • Joined: 18 June 2009 01:05 AM

I’m trying to write a rather more than simple for loop here.....

My frame range for example is (-50 1220)
Im wanting a function that does this ( for every 100 frames print “the batch number and the frame number”
the batch number corresponds to groups of 100 frames. The first 100 frames would be 1. The second group of 100 frames would be batch number 2. 

examples: (batch# + “_” + frame#)
1_50
1_51
1_52
1_....

2_151
2_152
2_153
2_....



Max 4 - 2012
Nvidia Quadro FX 3500
Duel Intel(R) Xeon(R) CPU X5355 2.66GHz, 8Gb Ram, DX9.0c.
Windows 7 64bit Operating System

Replies: 0
avatar

Kinda have something going here but not completely there yet.

loops = (ceil (150/100.0)) as integer
 
for =1 to loops do (
 for 
1 to 100 do (
 print (
as string"_" as string)
 ) 
)


Max 4 - 2012
Nvidia Quadro FX 3500
Duel Intel(R) Xeon(R) CPU X5355 2.66GHz, 8Gb Ram, DX9.0c.
Windows 7 64bit Operating System

Replies: 0
avatar
  • amarhys
  • Posted: 05 October 2011 08:24 PM

local firstFrame 50
local lastFrame  
1220
local blockSize  
100

local loops 
= (ceil ((lastFrame-firstFrame+1)/blockSize)) as integer
local currentFrame
;

for 
1 to loops do (
  for 
0 to (blockSize-1) do (
    
currentFrame = (+ (i-1)*blockSize firstFrame)
    if (
currentFrame <= lastFramethen (
       print (
as string "_" currentFrame as string)
    )
  ) 
)

Hope it will help.
-amarhys



Max 2011, Win7-Pro 64.
NVidia GeForce GTX 460
Core i7 950 3.06Ghz, 24Gb Ram.

Replies: 0
avatar
  • Anubis
  • Posted: 06 October 2011 04:38 AM

Hey John,

You ask same question at ScriptSpot and I reply there,
but just in case will post my solution here too.

(
    
local sFrame = -50eFrame 1220
    local seqSize 
100itrNum 0
    local seqNum 
1prefix "1_"
    
local frmCount eFrame sFrame 1
    local strArray 
#()
    
strArray[frmCount] null
    
    
for sFrame to eFrame do (
        
itrNum += 1
        strArray[itrNum] 
prefix as string
        
if mod itrNum seqSize == do (
            
seqNum += 1
            prefix 
seqNum as string "_"
        
)
    )
    
    print 
strArray
)

Hardly ever you need just to print strings,
so I store them to array for future use.

If hide/exclude print command,
the runtime is about 16 ms.

Cheers!



Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 0
avatar
  • lo_
  • Posted: 06 October 2011 04:52 AM

count 0
batch 
"1"
for = -50 to 1220 do 
(
 
count+=
 
print (batch "_" as string)
 if 
count == 100 do
 (
 
count 0
 batch 
= (batch as integer 1) as string
 
)
)

why so complicated?



VFB+ : An enhanced 3dsmax frame buffer (free)

Replies: 0
avatar
  • Anubis
  • Posted: 06 October 2011 05:02 AM

lo_ 06 October 2011 04:52 AM

why so complicated?

if you mean that mod() compared to zero’ing counter complicate the code?… then might be… not checked ;)



Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 2
/img/forum/dark/default_avatar.png

sorry, I wasn’t talking about your code specifically, just saw a couple of pretty chunky blocks of code :)
But to be competitive, mine is 5ms without the ‘print’ :P

Author: lo_

Replied: 06 October 2011 05:05 AM  
/img/forum/dark/default_avatar.png

Ok ;)
Maybe my Max is not so sensitive for benchmark because if the runtime is below 15 ms it returns 0 ms. So, if I hide print part (in your code), I get 0, but if at least supply “str = (batch + “_” + i as string)” inside the loop, I end with the same runtime (16 ms), but yep, I catch your idea, using mod() is an extra calculation, and w/o it logicaly s’d be a bit more faster.

Author: Anubis

Replied: 06 October 2011 06:13 AM  
avatar
  • Anubis
  • Posted: 06 October 2011 06:44 AM

Ok, I made 2 function, 1st based on your idea and 2nd on mine.

fn buildStrins range size delimiter:"_" = (
    
local sFrm int(range.start), eFrm int(range.end)
    
local queNum 1prefix "1" delimiter
    local nCount 
0sCount 0result #()
    
result[eFrm sFrm 1] null
    
for sFrm to eFrm do (
        
nCount += 1sCount += 1
        result[sCount] 
prefix as string
        
if nCount == size do (
            
nCount 0queNum += 1
            prefix 
queNum as string delimiter
        
)
    )
    
result -- returns array
)
test1 buildStrins animationRange 20
test2 
buildStrins (interval -50 1220100

fn buildStrins2 range size delimiter
:"_" = (
    
local sFrm int(range.start), eFrm int(range.end)
    
local queNum 1prefix "1" delimiter
    local itrNum 
0result #()
    
result[eFrm sFrm 1] null
    
for sFrm to eFrm do (
        
itrNum += 1
        result[itrNum] 
prefix as string
        
if mod itrNum size == do (
            
queNum += 1
            prefix 
queNum as string delimiter
        
)
    )
    
result -- returns array
)
test1 buildStrins2 animationRange 20
test2 
buildStrins2 (interval -50 1220100

But as I get values 0 or 15 ms for both, I test them with more large range:

(
 
GC()
 
T1 timeStamp()
 
buildStrins (interval -5000 5000100
 format 
"F1: %\n" (timeStamp() - T1)
 
GC()
 
T2 timeStamp()
 
buildStrins2 (interval -5000 5000100
 format 
"F2: %\n" (timeStamp() - T2)
)

And the result is interesting…
In sequential run 4/5 of the tests they show equal speed,
but in 1/5 of the cases second function showns as 15% better.
Strange?… :)



Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 0
avatar
  • lo_
  • Posted: 06 October 2011 06:51 AM

well, it’s such a negligible time anyways that I don’t see how it could possibly matter in any implementation unless we’re talking about numbers in the millions, which is not likely.



VFB+ : An enhanced 3dsmax frame buffer (free)

Replies: 1
/img/forum/dark/default_avatar.png

Yep, you’re right. I just was a bit curious after saw your code. At first look I like it, and the next test surprise me :)

Author: Anubis

Replied: 06 October 2011 10:56 AM  
avatar

Yeah this is essentially so I can loop through various controls of a morph target which has a limit of 100 but the animation could be over 100 frames so there posed the problem. I’m taking into consideration the code examples you’ve posted and things are working great. I’ll post what I have here when I’m complete to get your thoughts on things. I appreciate all the help and quick responses guys.
Thank you very much.



Max 4 - 2012
Nvidia Quadro FX 3500
Duel Intel(R) Xeon(R) CPU X5355 2.66GHz, 8Gb Ram, DX9.0c.
Windows 7 64bit Operating System

Replies: 0