Home Website Youtube GitHub

Load .pkr File Using Python

I’m trying to add a picker file to a rig builder but can’t seem to figure out how to load the file. Does anyone know how to do this?

Thank you for your help!

I’m new to the Anim Picker. I do not know if there is a best way. I am almost certain there must be a more straight-forward way. But this might give you some hints.

Disclaimer: This is not a script meant to run from start to finish. It is a collection of the commands you can use to create a picker node, and read the data from a file. Use only the commands you need.

import pymel.core as pm
from mgear import anim_picker

# If you already have picker nodes in the scene, you can find them this way.
pickerNodes = anim_picker.picker_node.get_nodes()
# The objects this command returns are DataNode() class objects, which you can use with the commands below:


# Creates a picker data class, DataNode()
newPicker = anim_picker.picker_node.DataNode()

# Creates the PICKER_DATAS node in the scene

# Gets the NAME of the data and file path attribute from the node.
pickerFileAttrName = newPicker.__FILE_ATTR__
pickerDataAttrName = newPicker.__DATAS_ATTR__

# Finds the picker node in the scene
pickerNode = pm.PyNode(newPicker.__NODE__)

# Finds the data and file node attributes
pickerFileAttr = pickerNode.attr(pickerFileAttrName)
pickerDataAttr = pickerNode.attr(pickerDataAttrName)

# Set the file path on the node
yourDataPath = '/Users/chrislesage/production/mGear/tools/mgear_3.6.0/anim_picker_samples/biped_template.pkr'
newPicker._set_str_attr(newPicker.__FILE_ATTR__, value=yourDataPath)

# if your picker already has a filepath set in the attribute, you can query what the path is:

# Reads the data from the file attribute on the picker node
pickerDataFromFile = newPicker.read_data_from_file()

# Set the picker NODE DATA from the FILE DATA it reads
newPicker._set_str_attr(newPicker.__DATAS_ATTR__, value=pickerDataFromFile)

Hope that helps! If someone has a more official way, please do answer. :slight_smile:


That worked! Thank you so much!

1 Like

Thank you again Chris! I changed a little on my end, but it all works. Thank you!

1 Like

I wrote a little function for this, that could probably be a part of the picker itself.

This way you can simply run either of these in your custom step:
import_picker("/path/to/my/anim_piker.pkr, name=“bob_the_picker”)

from mgear.anim_picker import picker_node
from mgear.anim_picker.handlers import file_handlers

def import_picker(path, name=None):
    Import picker data from file.                                               
    pkr_data = file_handlers.read_data_file(path)
    pkr_data["source_file_path"] = path
    if name:
        data_node = picker_node.DataNode(name=name)
        data_node = picker_node.DataNode(name=name)

    return pm.PyNode(data_node.name)
1 Like