Notifications
Clear all

[Closed] Optomizing Scripts

Hi All,

I’m very new to 3ds Max and Maxscript and have been trying to tackle some scripting. I have been working on a UI Toolbar Button that once you’ve selected the tops (roofs) of a polygon (building), it will detach that selection and rename it the same as the original polygon, but with “R_” as a prefix. The MacroScript is below.

There is a slight delay with this script and I was wondering what techniques could be applied to optomize the script. Thanks in advance.

macroScript Detach_Name category:“CH”
(
s = getCurrentSelection()
b = for obj in s collect obj.name
$.modifiers[#Edit_Poly].ButtonOp #DetachFace
select $obj*
obj.name = “R_”+b[1]
)

2 Replies

I don’t think there are any particular issues with script per say, but you might like to try it with undo off and maybe disable redrew until the end of the script.

Both topics are covered in the docs

Shane

 $.modifiers[#Edit_Poly].DetachtoObject ("R_"+$.name)

That’s the only line of code you need.

There were some problems before such as the fact it would rename every object in the scene that started with obj. If you had for instance a “objective plane” somewhere in the scene it would have become R_Objective Plane”

Also you can assume that the $ is going to return only one node because it assumes you’re in a sub object mode which can only be done on a single object.

You could throw in a try(code)catch(print “something went wrong”) just be sure it’s being run on a valid object. And of course there are lots of error checking routines you could add such as checking to ensure you actually do have an editpoly modifier… that you actually have something selected etc etc… but all of those will slow it down.