RE: get object name from scripted op

Date : Thu, 1 Feb 2007 14:29:15 -0500
To : <XSI(at)Softimage.COM>
From : "Mathieu Leclaire" <mleclair(at)hybride.com>
Subject : RE: get object name from scripted op
Well, I just wanted to create a SCOP constraint with an on/off switch and saving the offset between 2 objects when clicked back to on. I wanted to get the name so I could use GetObject to extract the custom parameter and a userdatablob that are in the object. From there I can verify if it's on or off, and if it's just turned back on, I would check the offset between the 2 objects and save that offset to the userdatablob. Might as well show it to you:
 

function SCOPconstraintExample_Update( ctx, out, InKine)

{

    var >

    var oBool = Dictionary.GetObject( oName+ ".OnOffCns.OnOff" );//custom parameter on/off switch

    var oTurnOn = Dictionary.GetObject(oName+".TurnOn");//userdatablob used to check if the on/off switch just changed

    if (oBool.value) {

        var oXdecal = Dictionary.GetObject(oName+".decalageX");//userdatablob to save the offset in X

        var oYdecal = Dictionary.GetObject(oName+".decalageY");//userdatablob to save the offset in Y

        var oZdecal = Dictionary.GetObject(oName+".decalageZ");//userdatablob to save the offset in Z

        if (oTurnOn.value == 0) {

            oTurnOn.value = 1;

            var out.value.posy.value, out.value.posz.value);

            var InKine.value.posy.value, InKine.value.posz.value);

            var diff = XSIMath.CreateVector3();

            diff.Sub(oNull1pos, oNull2pos);

            oXdecal.Value = diff.x;

            oYdecal.Value = diff.y;

            oZdecal.Value = diff.z;

        } else {

            var v1 = XSIMath.CreateVector3(InKine.value.posx.value, InKine.value.posy.value, InKine.value.posz.value);

            var v2 = XSIMath.CreateVector3(oXdecal.value, oYdecal.value, oZdecal.value);

            v1.Add(v1, v2);

            out.value.posx.value = v1.x;

            out.value.posy.value = v1.y;

            out.value.posz.value = v1.z;

        }

    }

    else

    {

        if (oTurnOn.value != 0) oTurnOn.value = 0;

    }

}

I would personally do it in C++. I haven't played with SCOP for a long time now. But that is just an example I was showing a new TD here that's starting out with SCOP. He don't know any C++ so I wanted to show him how he could pull off such a task with SCOPs. I'm sure it's ugly and there must be a cleaner way to do it... I just put that together in a few minutes to show him an example but I might as well show him the best way to do it. So let's please hear your suggestions on how to make this more clean. I'm currious to see how you guys would have done it.

 

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf Of Luc-Eric Rousseau
Sent: Wednesday, January 31, 2007 5:57 PM
To: XSI(at)Softimage.COM
Subject: RE: get object name from scripted op

Well the rules are that you don't have the right to traverse the graph inside from inside an Update function of an operator.  When the graph is traversed, each node needs to be evaluated and that's done by evaluating operators. 
So if an operator goes and traverses the graph, that means the evaluation order is non-determinstic and we can get into situation where the scene do not refresh properly, especially if A is dependant on B and B is asking for A.  It's possible that accessing the 3dobject is 'safe' since the parameters are not technically dependant on the kinestate.
 
IMHO it might be safer to take the string from the value of output and trim it to get what you need.  just by curiosity, what are you going to do with the name of object?
-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf Of Serguei Kalentchouk
Posted At: Wednesday, January 31, 2007 5:38 PM
Posted To: xsi
Conversation: get object name from scripted op
Subject: RE: get object name from scripted op

The problem you might run into is that if you draw a value from an object that is not defined as an input then in some cases if that object is changed the SCOP might not mark is a dirty and hence no update will take place.

 

However even though it is ?evil? I still find myself doing same thing in many cases.

I think there needs to be a method or property in the scop that gives you the target object the operator is on.

 


From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of Mathieu Leclaire
Sent: January 31, 2007 5:27 PM
To: XSI(at)Softimage.COM
Subject: RE: get object name from scripted op

 

Well, it all seems to work fine... why is it so evil? What can I expect to go wrong? And if it ain't the right way then please show me the right one!

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf Of Luc-Eric Rousseau
Sent: Wednesday, January 31, 2007 4:58 PM
To: XSI(at)Softimage.COM
Subject: RE: get object name from scripted op

It's evil though. You shouldn't be doing a GetValue in an operator on an object that you are not connected to as input.

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf Of Mathieu Leclaire
Posted At: Wednesday, January 31, 2007 4:52 PM
Posted To: xsi
Conversation: get object name from scripted op
Subject: RE: get object name from scripted op

Oh right... why didn't I think of that!? Yeah, I don't use scops much anymore myself but in this case it's much quicker to do it that way. Thanks!

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf Of Graham D Clark
Sent: Wednesday, January 31, 2007 4:37 PM
To: XSI(at)Softimage.COM
Subject: Re: get object name from scripted op

(its been a while I don't use scops too much now.)

I recall you can use dictionary,getobject and traverse up.

On 1/31/07, Mathieu Leclaire <mleclair(at)hybride.com> wrote:

Heu, this might sound weird but how can I get, from within the scripted operator, the name of the object on which the scripted operator is applied? Lets say for example the output of the scripted op is " null.kine.local", well, I want to extract the string "null". If I do a  LogMessage(out.value);  it will log me "null.kine.local". So I though I would try getting it using  out.value.parent.parent   but it gives me an error message. I must be missing something obvious but I can't seem to find it. Anyone has a suggestion? Thanks.

Mathieu Leclaire
R&D Programmer
Hybride Technologies


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.