The reason you cannot use .length() to control the loop is because the
operators are stored in an enumerated object, not a collection. Enumerated
objects are traversed using .moveNext() while !oOpStack.AtEnd() is the
marker to check if there are any objects left as shown in Martin's code.
Using Selection(0) or Selection(1) in this case could be dangerous as each
time an operator is deleted from the stack, the remaining operators move up
one index in the list. What used to be item 2 now becomes item 1. What was
item 3 now becomes item 2, etc... If you try to delete an item by index
which doesn't exist, you'll likely raise an error. In extreme cases you can
induce a crash.
A better way to test for the operator is to check it's object class using
Application.ClassName() or it's class ID using .IsClassID() or .isObjectID()
(can't remember the JScript version vs. C++). Checking .Type will return a
string which may inadvertently contain a word that matches what you're
looking for but isn't actually of that type. Case in point being the
construction history markers which return unique strings such as 'modeling
marker', 'animation marker', etc when using .Type, but will return a
consistent value when checked using the class ID.
Another improvement would be to collect all the operators and put them into
a dialog where the user can pick and choose all the operators they want to
selectively delete rather than wipe the slate automatically. The dialog is
an extra step, but UI controls can be implemented using PPG events to filter
the operators by custom criteria to perform validation checks before
deleting to prevent disasters and reduce human error. Deleting an operator
often deletes it's dependencies too. Most users are not educated of those
dependency chains.
Matt
Date: Thu, 23 Jul 2015 19:35:09 +0100
From: pedro santos <[email protected]>
Subject: Re: How to clear operators from an object without applying?
To: Softimage Mailing List <[email protected]>
Hi Martin
Thanks again for coming up with a solution, this works great! I changed it
a bit to add a integer stack selection. I was actually surprised it ran the
function before it was defined unlike Python :) Problem is I don't know JS
:P So I tried to loop over "selection" with no avail. I noticed that if I
had several objects selected used selection(0) or selection(1) it did
something accordingly, but apparently I can not use .lenght to define a
loop duration: // ERROR : Object doesn't support this property or method -
[line 30]
I don't know how to loop it... Well, I cal set a fixed number like 999 in
for (var i = 0; i < selection.length; i++) { and just cope with the out of
range error :)
Thanks
Pedro
// JScript
function delOps(oObj){
var oOpColl = new ActiveXObject( "XSI.Collection" );
var oOpStack = new Enumerator( oObj.ActivePrimitive.ConstructionHistory );
for (;!oOpStack.atEnd();oOpStack.moveNext()){
if (oOpStack.item().name == stack){
var ModelingFlag = 1;
continue;
}
if (ModelingFlag == 1){
oOpColl.add (oOpStack.item());
}
}
if (oOpColl.Count>0) DeleteObj( oOpColl ) ;
}
var pickstack = 2;
var stack = ["Modeling", "Shape Modeling", "Animation", "Secondary Shape
Modeling"][pickstack];
//Loop Attempt #1
for (i in selection) {
delOps(i);
}
//Loop Attempt #1
for (var i = 0; i < selection.length; i++) { // Throws error that selection
doesn't support .length
delOps(selection(i));
}
On Thu, Jul 23, 2015 at 10:17 AM, Martin Yara <[email protected]> wrote:
Just delete them? Or you mean by script
I wrote something similar in JScript to freeze some operators under
certain stack. I just changed it to delete all operators below the
Modeling
Stack. It only works with 1 object, you'll need to add a loop.
// JScript
delOps(selection(0))
function delOps(oObj){
var oOpColl = new ActiveXObject( "XSI.Collection" );
var oOpStack = new Enumerator( oObj.ActivePrimitive.ConstructionHistory );
for (;!oOpStack.atEnd();oOpStack.moveNext()){
if (oOpStack.item().name == "Modeling"){
var ModelingFlag = 1;
continue;
}
if (ModelingFlag == 1){
oOpColl.add (oOpStack.item());
}
}
if (oOpColl.Count>0) DeleteObj( oOpColl ) ;
}
Martin
On Thu, Jul 23, 2015 at 5:47 PM, pedro santos <[email protected]> wrote:
*HiQuite a few times when I'm adding operators to multiple objects I
would also like to clear those objects of any operator. This is not
Freezing, as I do not want to apply those operators, but remove them.
More
over if the above is possible, is it also possible to remove operators
only
from the modeling stack? Alike one uses Freeze and Freeze modeling
differently?Thanks*
*Pedro*
--
*------------------------------[image:
http://i153.photobucket.com/albums/s202/animatics/probiner-sig.gif]Pedro
Alpiar?a dos Santos Animator 3DModeler Illustrator >>
http://probiner.x10.mx/ <http://probiner.x10.mx/>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://listproc.autodesk.com/pipermail/softimage/attachments/20150723/5d1d71ae/attachment.html
------------------------------
_______________________________________________
Softimage mailing list
[email protected]
http://listproc.autodesk.com/mailman/listinfo/softimage
End of Softimage Digest, Vol 80, Issue 53
*****************************************