-
Notifications
You must be signed in to change notification settings - Fork 1
/
install Snap Ground 中文版.py
99 lines (80 loc) · 3.18 KB
/
install Snap Ground 中文版.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Author : AWACS
# Time : 2020/08/15
import os
import shutil
try:
import maya.mel
import maya.cmds as cmds
isMaya = True
except ImportError:
isMaya = False
def onMayaDroppedPythonFile(*args, **kwargs):
pass
def MayaDropinstall():
"""Drag and drop this file into the scene executes the file."""
dic_script = {
"author_folder" : "AWACS",
"Contain_Folder" : "Snap_to_Ground",
"Script_folder" : "Snap_to_Ground",
"Script_module_import" : "Snap_Ground_CHS",
"Script_name" : "Snap_to_Ground",
"Script_Shelf_icon" : "icon.jpg" ,
"imageOverlayLabel":"",
"Script_annotation" :
" a drop to ground script tool ",
}
ContainPath = os.path.join(os.path.dirname(__file__), dic_script["Contain_Folder"])
if not os.path.exists(ContainPath):
raise IOError('Cannot find ' + ContainPath)
User_script_dir = cmds.internalVar(userScriptDir=1)
author_folder_dir = os.path.join( User_script_dir , dic_script['author_folder'])
try:
os.makedirs( author_folder_dir )
except:
# author_folder_dir Already exist
pass
# Script_folder_fullpath = os.path.join( author_folder_dir , dic_script["Script_folder"] )
Script_folder_fullpath = author_folder_dir +"/"+ dic_script["Script_folder"]
# print (Script_folder_fullpath)
# Script_folder_fullpath = os.path.normpath(Script_folder_fullpath)
# print (Script_folder_fullpath)
# print ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
# Script_folder_fullpath = os.path.normpath(Script_folder_fullpath)
# print (Script_folder_fullpath)
if os.path.isdir( Script_folder_fullpath ):
print ( str( Script_folder_fullpath ) + " is Already Exist " + " -------------reinstalling")
shutil.rmtree( Script_folder_fullpath )
else :
pass
#Create Script folder and copy Contains from contain Folder
shutil.copytree( ContainPath , Script_folder_fullpath )
print ('// install success')
if dic_script["Script_Shelf_icon"]:
iconPath = os.path.join(Script_folder_fullpath, dic_script["Script_Shelf_icon"])
iconPath = os.path.normpath(iconPath)
# module_name = "BlendShape_Transfer"
else:
iconPath = "commandButton.png"
command = '''import sys
script_path = "{path}"
if script_path not in sys.path:
sys.path.append(script_path)
import {module_name}
if sys.version_info.major > 2 :
from imp import reload
reload ({module_name})
'''.format(path=Script_folder_fullpath , module_name = dic_script["Script_module_import"] )
shelf = maya.mel.eval('$gShelfTopLevel=$gShelfTopLevel')
parent = cmds.tabLayout(shelf, query=True, selectTab=True)
cmds.shelfButton(
command=command,
annotation=dic_script["Script_annotation"] ,
sourceType='Python',
image=iconPath,
image1=iconPath,
imageOverlayLabel = dic_script["imageOverlayLabel"],
parent=parent
)
print("// {Script_name} has been added to current shelf".format( Script_name = dic_script["Script_name"]))
if isMaya:
MayaDropinstall()