[Fixed]bind a script to a keyboard shortcut

General discussion about 3D DCC and other topics
User avatar
zossowosso
Posts: 81
Joined: 05 Sep 2009, 04:18

[Fixed]bind a script to a keyboard shortcut

Post by zossowosso » 28 Sep 2010, 21:42

Hi all

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;
}
    
Last edited by zossowosso on 28 Sep 2010, 22:56, edited 1 time in total.
'ERROR : 2011 - Unable to write well in English [CLSID\{F123FC55-ABD9-4D7F-9CDD-7F9D61E71FFE}] : %SUMATRAPATH%\ English.dll not found'

grahamef
Posts: 281
Joined: 23 Jun 2009, 19:01

Re: bind a script to a keyboard shortcut

Post by grahamef » 28 Sep 2010, 22:14

Choose File > Keyboard Mapping

If you haven't created a custom keymap yet then you need to click New. This is because the factory keymaps are read-only.

After that, select Custom Script Commands in the Group box. Find your command in the Command list, and drag it onto a key in the diagram below while pressing Shift, Ctrl, and/or Alt as desired.

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: bind a script to a keyboard shortcut

Post by xsisupport » 28 Sep 2010, 22:23

// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
zossowosso
Posts: 81
Joined: 05 Sep 2009, 04:18

Re: bind a script to a keyboard shortcut

Post by zossowosso » 28 Sep 2010, 22:31

thanks grahamef

it`s ok I forget to creat a new shelf

it seems that this script does not work as they should I have no errors in the scrip Editor ?
MoveCtr2Vertices("cube.pnt[2,6]", null);
'ERROR : 2011 - Unable to write well in English [CLSID\{F123FC55-ABD9-4D7F-9CDD-7F9D61E71FFE}] : %SUMATRAPATH%\ English.dll not found'

User avatar
zossowosso
Posts: 81
Joined: 05 Sep 2009, 04:18

Re: bind a script to a keyboard shortcut

Post by zossowosso » 28 Sep 2010, 22:43



thanks mr blair we poste at the same time

ok now it`s full working, with a video that can not be clearer ;)

this scrip help me to be more accurate to place the biped rig into a characters (EX: Hand, fingers)

see you


Crédit to this script: ;)
'ERROR : 2011 - Unable to write well in English [CLSID\{F123FC55-ABD9-4D7F-9CDD-7F9D61E71FFE}] : %SUMATRAPATH%\ English.dll not found'