Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Featured Threads
  inspiration alert!!!
(36 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies) Members Gallery
(516 replies)
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

MXS - Why is my script taking forever to complete?
show user profile  jpedleham
I have a script that i based off of one on scriptspot. All i did was add in progress bars so the scene didnt become unresponsive and took out a few functions that i didnt need. It seems to slow down considerably on the 'removing links' section. Is it just because theres probably alot of Linkcomposites in my scene?
Its a revit building into max.


objs = selection
arr = objs.count

objnum = 1

progressStart "Removing blocks"
for i in objs do

--transform unique
i.transform.controller = prs()
--unlink block children

if classof i.parent == LinkComposite do i.parent = undefined
objnum = objnum + 1
if not (progressUpdate(100.*objnum/arr)) then exit

--delete blocks
progressStart "Removing Links"
objnum = 1
for i in objs where (classof i == LinkComposite) do (delete i
objnum = objnum + 1
if not (progressUpdate(100.*objnum/arr)) then exit)

messageBox "Clean complete!"

read 333 times
5/10/2016 2:25:08 PM (last edit: 5/10/2016 2:29:14 PM)
show user profile  Garp
Deleting an object's parent sets its .parent property to undefined.
Unless in some cases either the parent or the child is selected but not both, you can remove the code that sets the objects' parents to undefined and get the same result. It should save some time.

A small computation optimization you can do (though not sure it would be significant in mxs) is define a variable prog_scl = 100.0/arr at the beginning and then use progressUpdate(prog_scl * objnum). Floating point division is about one order of magnitude slower than multiplication.

Finally, a small error: objnum should be initialized to 0, not 1. As it is, if you loop through 10 objects, objnum has value 11 in the last iteration (and the progress bar is set to 110%).

read 323 times
5/10/2016 4:22:23 PM (last edit: 5/10/2016 4:31:43 PM)
show user profile  jpedleham
Thanks garp ill give it a try.

read 289 times
5/11/2016 9:39:43 AM (last edit: 5/11/2016 9:39:43 AM)
show user profile  Garp
Try this.

The logic is a tad different but it could be significantly faster.

read 278 times
5/12/2016 12:08:59 AM (last edit: 5/12/2016 11:14:32 AM)
#Maxforums IRC
Open chat window