Exemple #1
0
def gear_prefPoseLibProp_OnInit():



    #Layout____________________________________

    layout = PPG.PPGLayout
    layout.Clear()

    layout.AddTab("Main")
    layout.AddGroup("PoseLib preferences")

    layout.AddItem( "global_Repo", "Global repo path", c.siControlFolder)
    layout.AddItem("list_Size", "List size in pixels", c.siControlNumber )
    layout.AddItem( "control_groups_list", "Control Group List", c.siControlString)
    if xsi.Preferences.Categories("gear_prefPoseLib"):
        PPG.global_Repo.Value = xsi.GetValue("preferences.gear_prefPoseLib.global_Repo")
        PPG.list_Size.Value = xsi.GetValue("preferences.gear_prefPoseLib.list_Size")
        PPG.control_groups_list.Value = xsi.GetValue("preferences.gear_prefPoseLib.control_groups_list")
    else:
        PPG.global_Repo.Value = "Select global repo path"
        PPG.list_Size.Value = 500
        PPG.control_groups_list.Value = '''"controlers_01_grp","controlers_facial_grp", "controlers_slider_grp"'''

    layout.EndGroup()

    layout.AddSpacer()

    item = layout.AddButton("setPreferences", "Set Preferences")
    item.SetAttribute(c.siUICX, 530)
    item.SetAttribute(c.siUICY, 40)

    PPG.Refresh()
Exemple #2
0
def setKey(controlers=xsi.Selection):

    if not controlers.Count:
        uit.msgBox("Nothing selected", c.siMsgExclamation,
                   "Key Selection Failed")
        return False

    keyable_params = getKeyableParameters(controlers)
    if not keyable_params.Count:
        uit.msgBox("There is no keyable parameter on selection",
                   c.siMsgExclamation, "Key Selection Failed")
        return False

    # Save Key
    playcontrol = xsi.GetValue("PlayControl")

    # Some Keyable display parameters (id) can be in the list, we need to remove them
    # or some parameters with expression on them
    itemsToRemove = XSIFactory.CreateObject("XSI.Collection")
    for param in keyable_params:
        if not param.Animatable or param.isAnimated(c.siExpressionSource):
            itemsToRemove.Add(param)

    if itemsToRemove.Count:
        keyable_params.RemoveItems(itemsToRemove)

    xsi.SaveKey(keyable_params, playcontrol.Parameters("Key").Value)

    return True
Exemple #3
0
    def __init__(self):

        playcontrol = xsi.GetValue("PlayControl")

        self.current = playcontrol.Parameters("Current")
        self.globalIn = playcontrol.Parameters("GlobalIn")
        self.localIn = playcontrol.Parameters("In")
        self.globalOut = playcontrol.Parameters("GlobalOut")
        self.localOut = playcontrol.Parameters("Out")
        self.key = playcontrol.Parameters("Key")
Exemple #4
0
def gear_poseLib_Execute():

    if xsi.ActiveSceneRoot.Properties("gear_poseLibManager"):
        xsi.DeleteObj(xsi.ActiveSceneRoot.Properties("gear_poseLibManager"))

    prop = xsi.ActiveSceneRoot.AddProperty("gear_poseLibManager", False, "gear_poseLibManager")

    if xsi.Preferences.Categories("gear_prefPoseLib"):
        listSize = xsi.GetValue("preferences.gear_prefPoseLib.list_Size")
    else:
        listSize = 500

    ds.inspect(prop, 300, 365 + listSize)
Exemple #5
0
def getFirstAndLastKey(controlers):

    playcontrol = xsi.GetValue("PlayControl")
    currentFrame = playcontrol.Parameters("Current").Value

    keyableParams = controlers.FindObjectsByMarkingAndCapabilities(None, 2048)
    firstKey = xsi.FirstKey(keyableParams)
    lastKey = xsi.LastKey(keyableParams)

    playcontrol.Parameters("Current").Value = currentFrame

    if lastKey < firstKey:
        return False

    return (firstKey, lastKey)
Exemple #6
0
def synCretor(posePath, imageName,  poseName, userName, oDate, originalModel):
    if xsi.Preferences.Categories("gear_prefPoseLib"):
        controlGoups = xsi.GetValue("preferences.gear_prefPoseLib.control_groups_list")
    else:
        controlGoups =  '''"controlers_01_grp", "controlers_facial_grp", "controlers_slider_grp"'''

    filePath = SEP.join(posePath.split(SEP)[:-1])
    posePath = "/".join(posePath.split(SEP)) # we need to use "/" for html compatibility
    synCode = '''
<html>
<body version="2">
<script language="Python">
##########################################################
# Globals
##########################################################
import xml.etree.cElementTree as xml
from win32com.client import constants as c
xsi = Application
lm = xsi.LogMessage
##########################################################
# Functions
##########################################################
def applyPose(pose, oSel=False, onlySel = False, percent = False):
    tree = xml.parse(pose)
    Log = True
    if onlySel:
        if oSel:
            for control in oSel:
                collection = XSIFactory.CreateActiveXObject( "XSI.Collection" )
                collection.AddItems( control )
                oKeyable = collection.FindObjectsByMarkingAndCapabilities( None, c.siKeyable )
                node =tree.find(control.Name)
                if node != None:
                    Log = False
                    if percent:
                        for oParam in oKeyable:
                            if oParam.ScriptName in ["rotx", "roty", "rotz", "posx", "posy", "posz", "sclx", "scly", "sclz"]:
                                oParamTag = ".".join(oParam.FullName.split(".")[2:])
                                oElem = node.find(oParamTag)
                                currVal = oParam.GetValue2()
                                val =  float(oElem.get("Value"))
                                if currVal >= 0 or currVal <= 0:
                                    valDif = currVal - val
                                    increment = valDif * (percent / 100.0)
                                    newVal = currVal + (increment * -1)
                                    if val < 0 and currVal > val:
                                        oParam.PutValue2(None,  newVal)
                                    elif val > 0 and currVal < val:
                                        oParam.PutValue2(None,  newVal)
                                    else:
                                        oParam.PutValue2(None,  newVal)
                    else:
                        for oParam in oKeyable:
                            oParamTag = ".".join(oParam.FullName.split(".")[2:])
                            oElem = node.find(oParamTag)
                            val =  oElem.get("Value")
                            oParam.PutValue2(None,  val)
            if Log:
                lm("No values for the selected objects found in the pose", 4)
        else:
            lm("Please Select something before apply only to selection", 4)
    else:
        eRoot = tree.getroot()
        oModelName = str(eRoot).split("'")[1].split("_")[0]
        oRoot = Application.ActiveSceneRoot
        oModel = False
        if oSel and oSel.Count:
            if oSel(0).Type == "#model":
                oModel = oSel(0)
            else:
                oModel = oSel(0).Model
        else:
            # Guess Model from models in the scene
            for iModel in oRoot.FindChildren2():
                if iModel.Type == "#model" and iModel.Name.split("_")[0] == oModelName and iModel.Groups:
                    oModel = iModel
        if oModel:
            for iGroup in oModel.Groups:
                if iGroup.Name in [''' + controlGoups + ''']:
                    for control in iGroup.Members:
                        collection = XSIFactory.CreateActiveXObject( "XSI.Collection" )
                        collection.AddItems( control )
                        oKeyable = collection.FindObjectsByMarkingAndCapabilities( None, c.siKeyable )
                        node =tree.find(control.Name)
                        if node != None:
                            if percent:
                                for oParam in oKeyable:
                                    if oParam.ScriptName in ["rotx", "roty", "rotz", "posx", "posy", "posz", "sclx", "scly", "sclz"]:
                                        oParamTag = ".".join(oParam.FullName.split(".")[2:])
                                        oElem = node.find(oParamTag)
                                        currVal = oParam.GetValue2()
                                        val =  float(oElem.get("Value"))
                                        if currVal >= 0 or currVal <= 0:
                                            valDif = currVal - val
                                            increment = valDif * (percent / 100.0)
                                            newVal = currVal + (increment * -1)
                                            if val < 0 and currVal > val:
                                                oParam.PutValue2(None,  newVal)
                                            elif val > 0 and currVal < val:
                                                oParam.PutValue2(None,  newVal)
                                            else:
                                                oParam.PutValue2(None,  newVal)
                            else:
                                for oParam in oKeyable:
                                    oParamTag = ".".join(oParam.FullName.split(".")[2:])
                                    oElem = node.find(oParamTag)
                                    val =  oElem.get("Value")
                                    oParam.PutValue2(None,  val)
        else:
            lm("Nothing selected found. And guess model functionality didn't match any model suitable for: " + oModelName , 4)
##########################################################
# Logic
##########################################################
def pose(in_obj, in_mousebutton, in_keymodifier):
    oSel = xsi.Selection
    perc = Application.GetValue(in_obj +  ".percentage")
    pose ="'''+ posePath + '''"
    #Apply complete pose
    if in_mousebutton == 0 and in_keymodifier == 0:
        applyPose(pose, oSel, False, False)
    #Apply complete pose in percentage
    if in_mousebutton == 0 and in_keymodifier == 4:
        applyPose(pose, oSel, False, perc)
    #Apply pose to selection
    if in_mousebutton == 1 and in_keymodifier == 0:
        applyPose(pose, oSel, True, False)
    #Apply pose to selection in percentage
    if in_mousebutton == 1 and in_keymodifier == 4:
        applyPose(pose, oSel, True, perc)
    #Show pose info
    if in_mousebutton == 0 and in_keymodifier == 2:
        Message = """
        Pose Name = '''+ poseName + '''
        File Path = '''+ filePath + '''
        Original Model = '''+ originalModel + '''
        Date = '''+ oDate + '''
        User = '''+ userName + '''
        """
        XSIUIToolkit.MsgBox( Message, 64, "Pose information" )
</SCRIPT>
<map name="SynopticMap">
<area shape="rect" coords="0,0,75,75" title='''+ poseName + ''' NOHREF onClick="pose">
</map>
<img src='''+ imageName + ''' usemap="#SynopticMap">
</body>
</html>
'''
    f = open( os.path.join(filePath, poseName + ".htm"), 'w')
    f.write(synCode)
Exemple #7
0
def gear_poseLibManager_refreshList_OnClicked(Sync = False):
    repo = PPG.parRepo.Value
    user = PPG.parUser.Value
    model = PPG.parModel.Value

    currentProject = xsi.ActiveProject2.Path
    currentRepoPath = os.path.join(currentProject, "PoseLib")


    if xsi.Preferences.Categories("gear_prefPoseLib"):
        globlaRepoPath = xsi.GetValue("preferences.gear_prefPoseLib.global_Repo")
    else:
        globlaRepoPath = False

    oSel = xsi.Selection

    #Populating List
    if Sync:
        pose_items = Sync
    else:
        pose_items = []

        if repo in ["Current_DB", "Both"]:
                if user == "All":
                    oUserFolders = [d for d in os.listdir(currentRepoPath)]
                    for oFolder in oUserFolders:
                        oPoseFolders = [d for d in os.listdir(os.path.join(currentRepoPath, oFolder))]
                        if model == "All":
                            for iPose in oPoseFolders:
                                pose_items.append(oFolder+" : "+iPose)
                                pose_items.append(os.path.join(currentRepoPath, oFolder, iPose))
                        elif model == "Selected":
                            oModelCheck = []
                            for iSel in oSel:
                                if iSel.Type == "#model":
                                    oModelCheck.append(iSel.Name.split("_")[0])
                                else:
                                    oModelCheck.append(iSel.Model.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append(oFolder+" : "+iPose)
                                    pose_items.append(os.path.join(currentRepoPath, oFolder, iPose))
                        elif model == "In_Scene":
                            oRoot = xsi.ActiveSceneRoot
                            oModelCheck = []
                            for iModel in oRoot.FindChildren2():
                                if iModel.Type == "#model":
                                    oModelCheck.append(iModel.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append(oFolder+" : "+iPose)
                                    pose_items.append(os.path.join(currentRepoPath, oFolder, iPose))

                else:
                    if user == "Self":
                        userName = os.environ.get( "USERNAME" )
                    else:
                        userName = user
                    if os.path.isdir(os.path.join(currentRepoPath, userName)):
                        oPoseFolders = [d for d in os.listdir(os.path.join(currentRepoPath, userName))]
                        if model == "All":
                            for iPose in oPoseFolders:
                                pose_items.append(iPose)
                                pose_items.append(os.path.join(currentRepoPath, userName, iPose))
                        elif model == "Selected":
                            oModelCheck = []
                            for iSel in oSel:
                                if iSel.Type == "#model":
                                    oModelCheck.append(iSel.Name.split("_")[0])
                                else:
                                    oModelCheck.append(iSel.Model.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append(iPose)
                                    pose_items.append(os.path.join(currentRepoPath, userName, iPose))
                        elif model == "In_Scene":
                            oRoot = xsi.ActiveSceneRoot
                            oModelCheck = []
                            for iModel in oRoot.FindChildren2():
                                if iModel.Type == "#model":
                                    oModelCheck.append(iModel.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append(iPose)
                                    pose_items.append(os.path.join(currentRepoPath, userName, iPose))
                    else:
                         lm("No poses found for: " + userName, 4)


        if repo in ["Global", "Both"]:
            if globlaRepoPath :
                if user == "All":
                    oUserFolders = [d for d in os.listdir(globlaRepoPath)]
                    for oFolder in oUserFolders:
                        oPoseFolders = [d for d in os.listdir(os.path.join(globlaRepoPath, oFolder))]
                        if model == "All":
                            for iPose in oPoseFolders:
                                pose_items.append("Global: "+oFolder+" : "+iPose)
                                pose_items.append(os.path.join(globlaRepoPath, oFolder, iPose))
                        elif model == "Selected":
                            oModelCheck = []
                            for iSel in oSel:
                                if iSel.Type == "#model":
                                    oModelCheck.append(iSel.Name.split("_")[0])
                                else:
                                    oModelCheck.append(iSel.Model.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append("Global: "+oFolder+" : "+iPose)
                                    pose_items.append(os.path.join(globlaRepoPath, oFolder, iPose))
                        elif model == "In_Scene":
                            oRoot = xsi.ActiveSceneRoot
                            oModelCheck = []
                            for iModel in oRoot.FindChildren2():
                                if iModel.Type == "#model":
                                    oModelCheck.append(iModel.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append("Global: "+oFolder+" : "+iPose)
                                    pose_items.append(os.path.join(globlaRepoPath, oFolder, iPose))

                else:
                    if user == "Self":
                        userName = os.environ.get( "USERNAME" )
                    else:
                        userName = user
                    if os.path.isdir(os.path.join(globlaRepoPath, userName)):
                        oPoseFolders = [d for d in os.listdir(os.path.join(globlaRepoPath, userName))]
                        if model == "All":
                            for iPose in oPoseFolders:
                                pose_items.append("Global: "+iPose)
                                pose_items.append(os.path.join(globlaRepoPath, userName, iPose))
                        elif model == "Selected":
                            oModelCheck = []
                            for iSel in oSel:
                                if iSel.Type == "#model":
                                    oModelCheck.append(iSel.Name.split("_")[0])
                                else:
                                    oModelCheck.append(iSel.Model.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append("Global: "+iPose)
                                    pose_items.append(os.path.join(globlaRepoPath, userName, iPose))
                        elif model == "In_Scene":
                            oRoot = xsi.ActiveSceneRoot
                            oModelCheck = []
                            for iModel in oRoot.FindChildren2():
                                if iModel.Type == "#model":
                                    oModelCheck.append(iModel.Name.split("_")[0])
                            for iPose in oPoseFolders:
                                if iPose.split("_")[0] in oModelCheck:
                                    pose_items.append("Global: "+iPose)
                                    pose_items.append(os.path.join(globlaRepoPath, userName, iPose))
            else:
                lm("No poses found", 4)




    gear_poseLibManager_OnInit(repo , user, model, pose_items)
Exemple #8
0
def gear_poseLibManager_OnInit(repo = "Current_DB", user = "******", model = "All", pose_items = [] ):
    #retriving Preferences
    if xsi.Preferences.Categories("gear_prefPoseLib"):
        listSize = xsi.GetValue("preferences.gear_prefPoseLib.list_Size")
    else:
        listSize = 500

    # Dropbox menus populating
    repo_items = ["Current_DB", "Current_DB", "Global", "Global", "Both", "Both"]
    user_items = ["Self", "Self", "All", "All"]
    model_items = ["All", "All", "Selected", "Selected", "In_Scene", "In_Scene"]

    #Users List populating
    currentProject = xsi.ActiveProject2.Path
    currentRepoPath = os.path.join(currentProject, "PoseLib")
    #local
    if not os.path.isdir(currentRepoPath):
        os.makedirs(currentRepoPath)
    oUserFolders = [d for d in os.listdir(currentRepoPath)]
    for oFolder in oUserFolders:
        for x in range(2):
            user_items.append(oFolder)

    #global
    if xsi.Preferences.Categories("gear_prefPoseLib"):
        globlaRepoPath = xsi.GetValue("preferences.gear_prefPoseLib.global_Repo")
        oUserFolders = [d for d in os.listdir(globlaRepoPath)]
        for oFolder in oUserFolders:
            for x in range(2):
                user_items.append(oFolder)

    #Layout ------------------------------------------------------------------------------
    #-------------------------------------------------------------------------------------

    layout = PPG.PPGLayout
    layout.Clear()

    layout.AddTab("Main")
    layout.AddGroup("Search filters")
    layout.AddEnumControl("parRepo", repo_items, "Repository", c.siControlCombo)
    PPG.parRepo.Value = repo
    layout.AddEnumControl("parUser", user_items, "User", c.siControlCombo)
    PPG.parUser.Value = user
    layout.AddEnumControl("parModel", model_items, "Model", c.siControlCombo)
    PPG.parModel.Value = model
    layout.EndGroup()

    oButton = layout.AddButton("refreshList", "Refresh List")
    oButton.SetAttribute(c.siUICX, 280)
    oButton.SetAttribute(c.siUICY, 30)

    layout.AddGroup("Pose List")
    oListBox = layout.AddItem( "parPoseList", "", c.siControlListBox )
    oListBox.SetAttribute(c.siUINoLabel,True)
    oListBox.SetAttribute( c.siUICY, listSize )
    oListBox.SetAttribute( c.siUIMultiSelectionListBox, True )

    oListBox.UIItems = pose_items
    #PPG.pModelList.Value = defaultValue
    layout.EndGroup()

    oButton = layout.AddButton("createPoseSet", "Create Pose Set")
    oButton.SetAttribute(c.siUICX, 280)
    oButton.SetAttribute(c.siUICY, 40)
    layout.AddRow()
    oButton = layout.AddButton("removePose", "<< Remove")
    oButton.SetAttribute(c.siUICX, 115)
    oButton.SetAttribute(c.siUICY, 20)
    oButton = layout.AddButton("syncPose", "Sync")
    oButton.SetAttribute(c.siUICX, 50)
    oButton.SetAttribute(c.siUICY, 20)
    oButton = layout.AddButton("addPose", "Add >>")
    oButton.SetAttribute(c.siUICX, 115)
    oButton.SetAttribute(c.siUICY, 20)
    layout.EndRow()
    layout.AddGroup("Set Columns Number")
    tmpItem = layout.AddItem("parRowsNum", "Set columns Number", c.siControlNumber )
    tmpItem.SetAttribute(c.siUINoLabel,True)
    layout.EndGroup()

    layout.AddGroup("STORE")
    oButton = layout.AddButton("newPose", "New Pose")
    oButton.SetAttribute(c.siUICX, 270)
    oButton.SetAttribute(c.siUICY, 40)
    layout.AddRow()
    oButton = layout.AddButton("delPose", "Del")
    oButton.SetAttribute(c.siUICX, 40)
    oButton.SetAttribute(c.siUICY, 20)
    oButton = layout.AddButton("preferences", "Preferences")
    oButton.SetAttribute(c.siUICX, 230)
    oButton.SetAttribute(c.siUICY, 20)
    layout.EndRow()
    layout.EndGroup()

    PPG.Refresh()