Skip to content

Instantly share code, notes, and snippets.

@tokejepsen
Created May 10, 2019 09:34
Show Gist options
  • Save tokejepsen/cdffb00a88f4e69e553a38eeaa808504 to your computer and use it in GitHub Desktop.
Save tokejepsen/cdffb00a88f4e69e553a38eeaa808504 to your computer and use it in GitHub Desktop.
mGear Post Script FFD Import
import os
import pymel.core
basename = os.path.basename(pymel.core.sceneName())
filename = os.path.splitext(basename)[0]
directory = os.path.dirname(pymel.core.sceneName())
# Find *.ffd folder starting with same name as current file
json_files = []
maya_files = []
for folder in os.listdir(directory):
if folder == (filename + ".ffd"):
path = os.path.join(directory, folder)
for f in os.listdir(path):
file_path = os.path.join(path, f)
if f.endswith(".json"):
json_files.append(file_path)
if f.endswith(".mb") or f.endswith(".ma"):
maya_files.append(file_path)
# Import all maya files.
for maya_file in maya_files:
nodes = pymel.core.importFile(maya_file, returnNewNodes=True)
# Connect mesh to ffd.
mesh_name = os.path.splitext(os.path.basename(maya_file))[0]
for lattice in pymel.core.ls(nodes, type="lattice"):
pymel.core.lattice(lattice, e=True, geometry=mesh_name)
# Import deformer weights.
for json_file in json_files:
ffd_name = os.path.splitext(os.path.basename(json_file))[0]
if not pymel.core.objExists(ffd_name):
raise ValueError(
"Missing \"{0}\" for ffd from \"{1}\"".format(
ffd_name, json_file
)
)
pymel.core.deformerWeights(
os.path.basename(json_file),
path=os.path.dirname(json_file),
im=True,
deformer=pymel.core.PyNode(ffd_name),
method="index"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment