Notifications
Clear all

[Closed] How to clone objects faster

hi
is there a way to decrease time for cloning objects. right now i m using maxOps.CloneNodes in a for loop which is very slow.


start = timeStamp()
with redraw off
(
k = (Rectangle length:50 width:50)
offs=60
for st=2 to 10860 do
(	
	maxOps.CloneNodes k cloneType:#instance newNodes:&new
	new[1].pos.x+=offs
	offs+=60
)
)
end = timeStamp()
format "Processing took % seconds\n" ((end - start) / 1000.0)

Processing took 31.979 seconds

if i do the same thing with SHIFT KEY cloning it finishes in couple of seconds.

image

If anyone know any other method for faster cloning ?
thnkx

3 Replies

~2.5 sec on my laptop

with redraw off
(
	disableRefMsgs()
	
	k = Rectangle length:50 width:50
	offset = [ 60, 0, 0 ]
	count = 10000

	for i = 1 to count do instance k pos:(offset * i)	

	enableRefMsgs()
)

if maxOps.CloneNodes is necessary , try reduce times of Clone , such as

start = timeStamp()
with redraw off
(

k = (Rectangle length:50 width:50)
sel=#(k)
offs=60
ct=10860
while sel.count < ct do
(	
	if sel.count > ct/2 then
(
 	tsel=#()
    for i = 1 to (ct - sel.count) do
      tsel[i]=sel[i]
	maxOps.CloneNodes tsel cloneType:#instance newNodes:&new offset:[60*sel.count,0,0]
)else
	maxOps.CloneNodes sel cloneType:#instance newNodes:&new offset:[60*sel.count,0,0]
sel += new
)
)
end = timeStamp()
format "Processing took % seconds\n" ((end - start) / 1000.0)

Thank you guys for replying, this is way faster as i needed to clone objects upto 100000 range. maxOps solution was helpful for me because i needed to name and also move returned nodes. Thanks.