Horganovski
03-14-2008, 11:55 PM
Hey Folks,
A while ago I got some help here to make a script that will swap the coordinates and rotations of two selected objects. I adapted this a little so that after selecting two objects and running the script it will swap their Y+Z+H and mirror their X+P+B values.
This has proved to be very useful for setting up walkcycles for characters as I demonstrate here - http://www.graphite9.com/Walkcycle_Buddy.mov
Now I would like to adapt this script a little so that instead of position and rotation values, it can access some or all of the UserData sliders on each selected object and swap their values instead. I have been digging through the SDK and trying various combinations of GetData and SetData but really am not sure I am accessing the right parameters as nothing has worked so far. I realise I should probably start with something easier, but I would really appreciate any advice on how to access and manipulate the UserData sliders.
I enclose the previous script which I mentioned above by way of example and in case anyone finds it useful.
//Returns the next object in the list to "op"
next_object(op)
{
if (!op) return NULL;
if (op->GetDown()) return op->GetDown();
while (!op->GetNext() && op->GetUp()) op = op->GetUp();
return op->GetNext();
}
//Returns the first selected object it finds
next_selected(op)
{
while (op)
{
if (op->GetBit(BIT_ACTIVE)) return op;
op = next_object(op);
}
return NULL;
}
main(doc, op)
{
//Find two selected objects in the document
var first_object = next_selected(doc->GetFirstObject()),
second_object = next_selected(next_object(first_object));
if (!first_object || !second_object) return FALSE;
//Get the objects rotations
var first_rot = first_object->GetRotation();
var second_rot = second_object->GetRotation();
//Get the objects positions
var first_pos = first_object->GetPosition();
var second_pos = second_object->GetPosition();
//Swap the Z's and Y's around and Mirror the X's
var tempx = first_pos.x*-1;
var tempz = first_pos.z;
var tempy = first_pos.y;
first_pos.z = second_pos.z;
second_pos.z = tempz;
first_pos.y = second_pos.y;
second_pos.y = tempy;
first_pos.x = second_pos.x*-1;
second_pos.x = tempx;
//Swap the Rotations around - Heading and Banking are Mirrored
var temphead = first_rot.x*-1;
var temppitch = first_rot.y;
var tempbank = first_rot.z*-1;
first_rot.x = second_rot.x*-1;
second_rot.x = temphead;
first_rot.y = second_rot.y;
second_rot.y = temppitch;
first_rot.z = second_rot.z*-1;
second_rot.z = tempbank;
//Set the objects new positions
first_object->SetPosition(first_pos);
second_object->SetPosition(second_pos);
//Set the objects new rotations
first_object->SetRotation(first_rot);
second_object->SetRotation(second_rot);
return TRUE;
}
Cheers,
Brian
A while ago I got some help here to make a script that will swap the coordinates and rotations of two selected objects. I adapted this a little so that after selecting two objects and running the script it will swap their Y+Z+H and mirror their X+P+B values.
This has proved to be very useful for setting up walkcycles for characters as I demonstrate here - http://www.graphite9.com/Walkcycle_Buddy.mov
Now I would like to adapt this script a little so that instead of position and rotation values, it can access some or all of the UserData sliders on each selected object and swap their values instead. I have been digging through the SDK and trying various combinations of GetData and SetData but really am not sure I am accessing the right parameters as nothing has worked so far. I realise I should probably start with something easier, but I would really appreciate any advice on how to access and manipulate the UserData sliders.
I enclose the previous script which I mentioned above by way of example and in case anyone finds it useful.
//Returns the next object in the list to "op"
next_object(op)
{
if (!op) return NULL;
if (op->GetDown()) return op->GetDown();
while (!op->GetNext() && op->GetUp()) op = op->GetUp();
return op->GetNext();
}
//Returns the first selected object it finds
next_selected(op)
{
while (op)
{
if (op->GetBit(BIT_ACTIVE)) return op;
op = next_object(op);
}
return NULL;
}
main(doc, op)
{
//Find two selected objects in the document
var first_object = next_selected(doc->GetFirstObject()),
second_object = next_selected(next_object(first_object));
if (!first_object || !second_object) return FALSE;
//Get the objects rotations
var first_rot = first_object->GetRotation();
var second_rot = second_object->GetRotation();
//Get the objects positions
var first_pos = first_object->GetPosition();
var second_pos = second_object->GetPosition();
//Swap the Z's and Y's around and Mirror the X's
var tempx = first_pos.x*-1;
var tempz = first_pos.z;
var tempy = first_pos.y;
first_pos.z = second_pos.z;
second_pos.z = tempz;
first_pos.y = second_pos.y;
second_pos.y = tempy;
first_pos.x = second_pos.x*-1;
second_pos.x = tempx;
//Swap the Rotations around - Heading and Banking are Mirrored
var temphead = first_rot.x*-1;
var temppitch = first_rot.y;
var tempbank = first_rot.z*-1;
first_rot.x = second_rot.x*-1;
second_rot.x = temphead;
first_rot.y = second_rot.y;
second_rot.y = temppitch;
first_rot.z = second_rot.z*-1;
second_rot.z = tempbank;
//Set the objects new positions
first_object->SetPosition(first_pos);
second_object->SetPosition(second_pos);
//Set the objects new rotations
first_object->SetRotation(first_rot);
second_object->SetRotation(second_rot);
return TRUE;
}
Cheers,
Brian
