PDA

View Full Version : Optomizing Scripts


sailorsd
07-24-2008, 03:18 AM
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*
for obj in $ do obj.name = "R_"+b[1]
)

RustyKnight
07-24-2008, 10:37 PM
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

thatoneguy
07-26-2008, 03:18 AM
$.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.

CGTalk Moderation
07-26-2008, 03:18 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.