gsee

AM_CP py2.7

Nov 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1. #Copie/coller des transform de sa selection
  2.  
  3. import maya.cmds as mc
  4. import os
  5. import functools
  6.  
  7. #Copy les world position d'un transform
  8. def cpt_copy(_):
  9.     selection = mc.ls(selection=True)
  10.     mc.select(d=True)
  11.    
  12.     if len(selection) is not 1:
  13.         mc.error('select one transform')
  14.        
  15.     elif mc.nodeType(selection) != 'transform':
  16.         mc.error('select one transform')        
  17.        
  18.     else:
  19.         homedir = os.environ['HOME']
  20.         data_doc = homedir + "/data_cpt.txt"
  21.  
  22.         worldSpaceTransform = str(mc.xform(selection, worldSpace=True, matrix=True, query=True))
  23.  
  24.         with open(data_doc, "w") as dataFile:
  25.             dataFile.write(str(worldSpaceTransform))    
  26.  
  27. #Colle les world position d'un transform
  28. def cpt_paste(_):    
  29.     selection = mc.ls(selection=True)    
  30.      
  31.     if len(selection) is not 1:    
  32.         mc.error('select one transform')
  33.        
  34.     elif mc.nodeType(selection) != 'transform':
  35.         mc.error('select one transform')
  36.        
  37.     else:    
  38.         homedir = os.environ['HOME']
  39.         data_doc = homedir + "/data_cpt.txt"
  40.    
  41.         with open(data_doc, "r") as dataFile:            
  42.            
  43.             worldSpaceTransform = dataFile.read()
  44.                
  45.     worldSpaceTransform = worldSpaceTransform.replace('[', '').replace(']', '')
  46.     worldSpaceTransform = worldSpaceTransform.split(', ')
  47.  
  48.     wst_float = []    
  49.     wst_float = [float(i) for i in worldSpaceTransform]
  50.      
  51.     mc.xform(selection, worldSpace=True, matrix=wst_float)        
  52.        
  53. # Set window
  54. def close_callback(window, _):
  55.     print "Close!", window
  56.     mc.deleteUI(window, window=True)
  57.  
  58. if mc.window("copyPast_tool", query=True, exists=True):
  59.     mc.deleteUI("copyPast_tool", window=True)
  60.  
  61. window = mc.window("copyPast_tool", title="Copy Paste Tool", widthHeight=(20, 20))
  62. mc.columnLayout(adjustableColumn=True)
  63. mc.button(label='Copy', command=(cpt_copy))
  64. mc.button(label='Paste', command=(cpt_paste))
  65. mc.button(label="Close", command=functools.partial(close_callback, window))
  66. mc.setParent('..')
  67. mc.showWindow(window)
Advertisement
Add Comment
Please, Sign In to add comment