Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



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.

Thanks
Jack

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


)
progressEnd()
--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)



progressEnd()
windows.processPostedMessages()
messageBox "Clean complete!"
)

read 255 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 245 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 211 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 200 times
5/12/2016 12:08:59 AM (last edit: 5/12/2016 11:14:32 AM)
#Maxforums IRC
Open chat window


Support Maxforums.org