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()
pickerNodes[0].read_data_from_file()
# The objects this command returns are DataNode() class objects, which you can use with the commands below:

# OR... HOW TO CREATE A NEW PICKER NODE:

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

# Creates the PICKER_DATAS node in the scene
newPicker.create()

# 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__)
pickerNode.rename('CHOOSE_A_PICKER_NAME')

# 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:
newPicker.get_file_path()

# 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:

3 Likes

That worked! Thank you so much!