Scripting help - PathCns - Dan 's attempt in Jscript.... 2005-06-02 - By Bernard Lebel
Back
> No takers? > > > Dan Yargici wrote: > >> [...] >> >> Anyway, if some of the more seasoned scripting types could cast a >> beady eye over this I'd really appreciate it. I did some things I'm >> just not sure about. First off, I iterate through the collection >> retuned by the duplicate command instead of enumerating it. Now I >> remember reading here many times that enumerating is faster, but it >> just seemed unecessary in this instance, am I right? > The thing is that is does not cost more to enumerate, as you pointed out. So why not using it?
The reason is that if you want to do things the proper way, you may put this little operation into a function. Then you will be able to easily reuse that function in other scripts. Now if those other scripts are performance sensitive, you'll just be glad you used the fastest loop code. Also, sooner or later, you or someone using your oringal script may come up with some design ideas, that will make your script do a lot more things. So any performance gain whatosever is welcomed, well, most of the time!
>> Also, I'm checking for whether the user pressed OK or Cancel by just >> checking if a return value exists. Is this a no no? It's seems >> fairly fool-proof to me. >> >> This is also what I do, and am very happy that way. I use the technique shown by Michael Isner in Experience XSI 4, that is, a try/catch statement, that I put in a function. Then if the function returned nothing, the script stops and print a message telling why ("cancelled by user").
// Call function var nValue = askUser();
// Test return value if( nValue == null ) { logmessage( "cancelled by user.", siError ); } else { logmessage( nValue ); // do something... }
function askUser() { var oProp = activesceneroot.addproperty( "CustomProperty", false, "TellMe" ); var oParam = oProp.addparameter3( "Value", siInt2, 1, 0, 4, true, false ); try { // Here's the important thing: the raise error being true, // if the user cancels, the script will go to the catch statement inspectobj( oProp, "", "TellMe", siModal, true ); nValue = oParam.value; deleteobj( oProp ); return( nValue ); } catch(a) { deleteobj( oProp ); return( null ); } }
The try/catch statement definitely is not the most elegant way to do things, but since a ppg in siModal mode is an operation that rarely is necessay more than a few times during script execution, I think its cost is reasonnable.
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|