Skip to content

Instantly share code, notes, and snippets.

@paulwinex
Last active October 11, 2022 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulwinex/d2f8eaabdc9ee40c2b07eb7f06f14a18 to your computer and use it in GitHub Desktop.
Save paulwinex/d2f8eaabdc9ee40c2b07eb7f06f14a18 to your computer and use it in GitHub Desktop.
from pymel.core import *
from pathlib import Path
import shutil
def get_files_from_selected_nodes():
files = []
nodes = selected(type='file') + selected(type='aiImage')
for node in nodes:
if node.hasAttr('fileTextureName'):
path = Path(node.fileTextureName.get())
elif node.hasAttr('filename'):
path = Path(node.filename.get())
else:
print('Wrong nodetype', node)
continue
if path.exists():
files.append(path)
else:
warning(f'File not exists: {path}')
return list(set(files))
def copy_files(file_list, target_dir):
target_dir = Path(target_dir)
target_dir.mkdir(exist_ok=True, parents=True)
print(f'Copy Files to {target_dir}:')
for file in file_list:
print(file)
shutil.copy2(file, target_dir)
def copy_textures():
files = get_files_from_selected_nodes()
if files:
target_dir = fileDialog2(dialogStyle=2, fileMode=2)
if target_dir:
copy_files(files,target_dir[0])
confirmDialog(title='Complete', message=f'Copied files: {len(files)}', button=['OK'], dismissString='OK' )
else:
PopupError('No files to copy')
copy_textures()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment