Home Website Youtube GitHub

Import Skin Pack

Little by little I am making progress, slowly but surely.
At the moment of importing the skinpack file it fails to load with the following code…

import os
import mgear.shifter.custom_step as cstp
from mgear.core import skin
import pymel.core as pm

class CustomShifterStep(cstp.customShifterMainStep):
    def __init__(self):
        self.name = "import_skinPack"

    def run(self, stepDict):
        """
        Run method.

        i.e: stepDict["mgearRun"].global_ctl gets the global_ctl from 
        shifter rig on post step
        i.e: stepDict["otherCustomStepName"].ctlMesh gets the ctlMesh 
        from a previous custom step called "otherCustomStepName"

        Arguments:
        stepDict (dict): Dictionary containing the objects from 
        the previous steps

        Returns:
        None: None
        """
        path = "\\".join(os.path.abspath(os.path.dirname(__file__)).split("\\")[:-2])
        skin.importSkinPack(os.path.join(path, "data", "skin", skin.gSkinPack()))

instead with this simple code it loads it perfectly into the skin.

import os
import mgear.shifter.custom_step as cstp
from mgear.core import skin
import pymel.core as pm

skinpath = os.path.abspath("C:/Users/darwi/Documents/Mgear/Rigging/build/data/skin/skin.gSkinPack")
skin.importSkinPack(skinpath)

The error code of the first script is as follows

= POST CUSTOM STEPS ==============================================
// EXEC: Executing custom step: scripts\post\gimmick_blended_joints.py // 
// SUCCEED: Custom Shifter Step Class: scripts\post\gimmick_blended_joints.py. Succeed!! // 
// EXEC: Executing custom step: scripts\post\import_skinPack.py // 
// Error: An exception of type AttributeError occurred.  // 
// Error: Traceback (most recent call last):
  File "C:\Users\darwi\Documents\maya\modules\scripts\mgear\shifter\guide.py", line 1253, in runStep
    cs.run(customStepDic)
  File "C:\Users\darwi\Documents\Mgear\Rigging\build\scripts\post\import_skinPack.py", line 27, in run
    skin.importSkinPack(os.path.join(path, "data", "skin", skin.gSkinPack()))
AttributeError: 'module' object has no attribute 'gSkinPack'

I would like to understand what is going on, just out of curiosity.

def __init__(self):
    self.name = “import_skinPack”.

Maybe it’s this part… but I don’t know for sure.
Greetings and thank you very much

I found the solution here in the forum! One obstacle less…
http://forum.mgear-framework.com/t/custom-step-post-script-error/2463/3

import os
import pymel.core as pm
import mgear.shifter.custom_step as cstp
from mgear.core import skin


class CustomShifterStep(cstp.customShifterMainStep):
    def __init__(self):
        self.name = "import_skinning"
        # This is set from "Rig Name" in the guide settings:
        self.charName = pm.PyNode('guide').rig_name.get()


    def run(self, stepDict):
        char = self.charName
        postpath = os.path.abspath(os.path.dirname(__file__))
        # Move UP in directories until we get to the base path of the rigging data
        basepath = os.path.abspath(os.path.join(postpath, '../..'))
        skinpath = os.path.abspath(os.path.join(basepath, 'data', 'skin', 'skin.gSkinPack'))
        
        if os.path.isfile(skinpath):
            skin.importSkinPack(skinpath)
        else:
            return False
        
        return

To answer what went wrong with your original script take a close look here:

                                                               |
                                                               V
skin.importSkinPack(os.path.join(path, "data", "skin", skin.gSkinPack()))

Specifically here, which is your problem:

skin.gSkinPack()

Putting () like that makes it try to run it as a Python function. But you want to load a string to a path to a file that is called “skin.gSkinPack”. What you did is try to call a function called gSkinPack() inside the skin module. And that doesn’t exist.

The skin.importSkinPack() function is being passed something in your two examples:

  1. os.path.join(path, "data", "skin", skin.gSkinPack())

  2. "C:/Users/darwi/Documents/Mgear/Rigging/build/data/skin/skin.gSkinPack"

And those two things are not the same. #1 should be os.path.join(path, "data", "skin", "skin.gSkinPack")

1 Like

Perfect, thank you very much for the answer.