someone could explain to me
how bind a script to a keyboard shortcut
beaucause i try this script and on toolbar it wont work
the author suggests The best idea is probably to bind it to a keyboard shortcut
thank
Code: Select all
/*===========================================================
* CG_PutToCenterPlugin
*
* Cyril GIBAUD 2009
* Email cyril_gib@hotmail.com
* URL www.studionham.com
* Version 1.0
Concept :
This very simple plugin will match the position of a null on any selection, points, edges or polygons. It's quite useful for modeling or rigging purposes,
to place guide pivots on a mesh, or find the center of mesh parts that are merged...
Usage :
The best idea is probably to bind it to a keyboard shortcut, as I do with "Ctrl+B". Then select some subcomponents and launch the command, it will ask you
to pick an object to be matched but you can just right click and it will create a null on the center.
Known Bugs and limitations :
-
Possible Updates :
I'm still thinking about adding the rotation, based on normal and + Y up...But for my personnal usage it'll not be usefull so I'll let it as simple as that for the moment.
==============================================================*/
function XSILoadPlugin( in_reg )
{
in_reg.Author = "Cyril Gibaud";
in_reg.Name = "CG_PutToCenterPlugin";
in_reg.Email = "";
in_reg.URL = "";
in_reg.Major = 1;
in_reg.Minor = 0;
in_reg.RegisterCommand("CG_PutToCenter","CG_PutToCenter");
return true;
}
function XSIUnloadPlugin( in_reg )
{
var strPluginName;
strPluginName = in_reg.Name;
Application.LogMessage(strPluginName + " has been unloaded.",siVerbose);
return true;
}
function CG_PutToCenter_Init( in_ctxt )
{
var oCmd;
oCmd = in_ctxt.Source;
oCmd.Description = "";
oCmd.ReturnValue = true;
return true;
}
function AddPoint(inDic, inIndex, PointPos)
{
if (inDic.Exists(inIndex) == false)
{
inDic.Add(inIndex,PointPos);
}
}
function CG_PutToCenter_Execute( )
{
Application.LogMessage("CG_PutToCenter_Execute called",siVerbose);
var oSel = Getvalue("SelectionList");
var inPoints = new Array();
var PointsDic = new ActiveXObject( "Scripting.Dictionary");
if(oSel.Count > 0)
{
oEnum = new Enumerator(oSel) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
var oCurItem = oEnum.item();
var oMatchObj = PickObj();
switch(oCurItem .Type)
{
case "pntSubComponent":
var LocalTrans = oCurItem.SubComponent.Parent3DObject.Kinematics.Local.Transform;
var PntComponents = oCurItem.SubComponent.ComponentCollection;
for ( var i = 0 ; i < PntComponents.Count ; i++)
{
var GlobPos = XSIMath.MapObjectPositionToWorldSpace(LocalTrans, PntComponents(i).Position);
inPoints.push(GlobPos);
}
PutRoot(inPoints, oMatchObj);
break;
case "edgeSubComponent":
var LocalTrans = oCurItem.SubComponent.Parent3DObject.Kinematics.Local.Transform;
var EdgeComponents = oCurItem.SubComponent.ComponentCollection;
for ( var i = 0 ; i < EdgeComponents.Count ; i++)
{
var CurPoint = EdgeComponents(i).Points(0);
var GlobPos = XSIMath.MapObjectPositionToWorldSpace(LocalTrans, CurPoint.Position);
AddPoint(PointsDic, CurPoint.Index, GlobPos);
CurPoint = EdgeComponents(i).Points(1);
GlobPos = XSIMath.MapObjectPositionToWorldSpace(LocalTrans, CurPoint.Position);
AddPoint(PointsDic, CurPoint.Index, GlobPos);
}
inPoints = (new VBArray(PointsDic.Items())).toArray();
PutRoot(inPoints, oMatchObj);
break;
case "polySubComponent":
var LocalTrans = oCurItem.SubComponent.Parent3DObject.Kinematics.Local.Transform;
var PolyComponents = oCurItem.SubComponent.ComponentCollection;
for ( var i = 0 ; i < PolyComponents.Count ; i++)
{
var CurPolyPoints = PolyComponents(i).Points;
for ( var j = 0 ; j < CurPolyPoints.Count ; j++)
{
var CurPoint = CurPolyPoints(j);
var GlobPos = XSIMath.MapObjectPositionToWorldSpace(LocalTrans, CurPoint.Position);
AddPoint(PointsDic, CurPoint.Index, GlobPos);
}
}
inPoints = (new VBArray(PointsDic.Items())).toArray();
PutRoot(inPoints, oMatchObj);
break;
default:
inPoints.push(oCurItem.Kinematics.Global.Transform.Translation);
PutRoot(inPoints, oMatchObj);
break;
}
}
}
else
{
logmessage("Nothing selected !!", siError);
}
return true;
}
function PutRoot(inPoints, inRoot)
{
var ObjCount = inPoints.length;
var X = 0;
var Y = 0;
var Z = 0;
for ( var i = 0 ; i < ObjCount ; i++)
{
X += inPoints[i].X;
Y += inPoints[i].Y;
Z += inPoints[i].Z;
}
var MeanVec = XSIMath.CreateVector3( X/ObjCount, Y/ObjCount, Z/ObjCount ) ;
if(inRoot == null)
{
inRoot = ActiveSceneRoot.AddNull("Root_0");
}
var CurTrans = inRoot.Kinematics.Global.Transform;
CurTrans.Translation = MeanVec;
inRoot.Kinematics.Global.Transform = CurTrans;
}
function PickObj()
{
var Rslt = PickElement(siGenericObjectFilter, "Please pick the object to match", "Create new object");
var element = Rslt.Value( "PickedElement" );
var button = Rslt.Value( "ButtonPressed" );
if(button != 0)
{
return element;
}
return null;
}