ScriptSpot

Forum topic · General Scripting

Loop more fast...

By Michele71 · 2015-02-02

Description

Hello everyone :)

I have write a little script which allows me to detach and make an object the faces of a poly. The main part of Whole script is a string recovery from 3dsMaxScript:


obj = selection[1]
for p = polyop.getNumFaces obj to 1 by -1 do (polyop.detachFaces obj #{p} asNode:true)

Ok, the script works well, but...

If I start the script and I 500/800 faces, it is fast, but if I have more of 1000 faces, max crash or freezes... Do you know a way to make it more stable and faster the code above? I tried, but no appreciable result ...

Thank for any reply

Michele

Comments (7)

Michele71 · 2015-02-03

Thanks miauu and barigazy :)

Today I'll try both codes but they are certainly better than the original! it's always nice to discover new forms of programming. A good start to continue my studying :)

Thanks again

miauu · 2015-02-03

Branko provided a good example to see the differences between the FOR and the WHILE loop. :) They do the same, but with different speed.

Michele71 · 2015-02-03

It's true! I have always asked how to use FOR or WHILE loop :D

barigazy · 2015-02-03

Yup. It's fester because I use predefined variables.
But it's not memory efficient solution as Kostadin method.
Do you see why? .... I tell you anyway :)
This cause memory leaking

number-=1

.

miauu · 2015-02-02

On object with 1250 polygons this:


(
	obj = selection[1]
	objFaceCnt = polyop.getNumFaces obj
	poDetachFaces = polyop.detachFaces
	for p = objFaceCnt to 1 by -1 do (poDetachFaces obj #{p} asNode:true)
)

tooks less than 3 sec.

barigazy · 2015-02-02

I tested this on Sphere with 64 segs
#1 miauu code


(
    gc() ; t1 = timestamp() ; m1 = heapfree
    obj = selection[1]
    objFaceCnt = polyop.getNumFaces obj
    poDetachFaces = polyop.detachFaces
    for p = objFaceCnt to 1 by -1 do (poDetachFaces obj #{p} asNode:true)
    format "time:% memory:%\n" ((timestamp()- t1 as float)/1000) (m1-heapfree)
)

#2 my code


(
    gc() ; t1 = timestamp() ; m1 = heapfree
    node = selection[1]
    number = node.faces.count+1
    detachFaces = polyop.detachFaces
    while (number-=1) != 1 do (detachFaces node #{number} asNode:on)
    format "time:% memory:%\n" ((timestamp()- t1 as float)/1000) (m1-heapfree)
)

#1 -> time:5.472 memory:545648L

#2 -> time:4.752 memory:640712L

Michele71 · 2015-02-03

I tried the two loops on my notebook (not performing) with a Sphere with 64 segs:

#1 -> time:19.456 memory:86400L
#2 -> time:16.68 memory:107384L

Original string: time:16.624 memory:109400L

Seems be fast as the example of barigazy... Is possible? You can do a test ??