-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_dictionay_edit.py
More file actions
206 lines (167 loc) · 6.01 KB
/
file_dictionay_edit.py
File metadata and controls
206 lines (167 loc) · 6.01 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# -*- coding: utf-8 -*-
"""
@FileName : duplicate_delete_rename.py
@DateTime : 2023/10/24 15:39:36
@Author : Tian Chao
@Contact : tianchao0533@163.com
@Software : Maya 2023.3
@PythonVersion : python 3.9.7
@Description :
"""
import unreal
new_dir = "/Game/MyNewDirectory"
def directoryExist():
"""判断目录是否存在"""
# 判断是否存在,把他打印出来
print(unreal.EditorAssetLibrary.does_directory_exist(new_dir))
# 再判断另一个
print(unreal.EditorAssetLibrary.does_directory_exist(new_dir + "Duplicated"))
def createDirectory():
"""创建目录"""
return unreal.EditorAssetLibrary.make_directory(new_dir)
def duplicateDirectory():
"""复制目录"""
return unreal.EditorAssetLibrary.duplicate_directory(
# 原来目录的名字
new_dir,
# 新目录的名字
new_dir + "Duplicated",
)
def deleteDirectory():
"""删除目录"""
return unreal.EditorAssetLibrary.delete_directory(new_dir + "Duplicated")
def renameDirectory():
"""重命名目录"""
return unreal.EditorAssetLibrary.rename_directory(new_dir, new_dir + "Renamed")
def assetExist(path):
"""文件是否存在"""
print(unreal.EditorAssetLibrary.does_asset_exist(path + "Duplicated"))
def duplicateAsset(path):
"""复制文件"""
return unreal.EditorAssetLibrary.duplicate_asset(
# 原始资源
path,
# 复制的名字
path + "Duplicated",
)
def deleteAsset(path):
"""删除文件"""
return unreal.EditorAssetLibrary.delete_asset(path + "Duplicated")
def duplicateAssetDialog(path, show_dialog=True):
"""复制文件的时候出现对话框
Args:
path (str): 路径
show_dialog (bool, optional): 是否出现对话框. Defaults to True.
Returns:
_type_: _description_
"""
# 分解路径
# 原本/Game/Texture/MyTexture
# 分解成['/Game/Texture','MyTexture']
splitted_path = path.rsplit("/", 1)
# /Game/Texture
asset_path = splitted_path[0]
# MyTextureDuplicated
asset_name = splitted_path[1] + "Duplicated"
# 带对话框
if show_dialog:
return unreal.AssetToolsHelpers.get_asset_tools().duplicate_asset_with_dialog(
# 名字是被复制出的名字
asset_name=asset_name,
# 包的路径
package_path=asset_path,
# 原始资源
original_object=unreal.load_asset(original_asset),
)
else:
return unreal.AssetToolsHelpers.get_asset_tools().duplicate_asset(
asset_name=asset_name,
package_path=asset_path,
original_object=unreal.load_asset(original_asset),
)
def renameAsset(path):
"""重命名文件"""
# 原始文件重命名
unreal.EditorAssetLibrary.rename_asset(path, path + "Renamed")
# 复制一个出来,重命名
unreal.EditorAssetLibrary.rename_asset(
path + "Duplicated", path + "Duplicated" + "Rebaned"
)
def renameAssetDialog(path, show_dialog=True):
"""带对话框重命名文件"""
splitted_path = path.rsplit("/", 1)
asset_path = splitted_path[0]
asset_name = splitted_path[1]
rename_data0 = unreal.AssetRenameData(
asset=unreal.load_asset(path + "Renamed"),
new_package_path=asset_path,
new_name=asset_name,
)
splitted_path = (path + "Duplicated").rsplit("/", 1)
asset_path = splitted_path[0]
asset_name = splitted_path[1]
rename_data1 = unreal.AssetRenameData(
asset=unreal.load_asset(path + "Duplicated" + "Renamed"),
new_package_path=asset_path,
new_name=asset_name,
)
if show_dialog:
return unreal.AssetToolsHelpers.get_asset_tools().rename_assets_with_dialog(
assets_and_names=[rename_data0, rename_data1]
)
else:
return unreal.AssetToolsHelpers.get_asset_tools().rename_assets(
assets_and_names=[rename_data0, rename_data1]
)
# path:路径
# force_save:强制保存
def saveAsset(path="", force_save=True):
"""文件保存"""
# https://docs.unrealengine.com/4.26/en-US/PythonAPI/class/EditorAssetLibrary.html?highlight=editorassetlibrary#unreal.EditorAssetLibrary.save_asset
return unreal.EditorAssetLibrary.save_asset(
asset_to_save=path, only_if_is_dirty=True
)
# resursive: 目录下面的目录要不要保存
def saveDirectory(path="", force_save=True, resursive=True):
"""目录保存"""
return unreal.EditorAssetLibrary.save_directory(
directory_path=path, only_if_is_dirty=True, recursive=resursive
)
def getPackageFromPath(path):
"""获得包"""
return unreal.load_package(path)
def getAllDirtyPackages():
"""获得所有脏包"""
# 先创建一个空的列表
packages = []
# 从读取和保存的工具包里遍历出所有脏的内容包
for x in unreal.EditorLoadingAndSavingUtils.get_dirty_content_packages():
# 存入packages列表里
packages.append(x)
# 从读取和保存的工具包里遍历出所有脏的关卡包
for x in unreal.EditorLoadingAndSavingUtils.get_dirty_map_packages():
# 存入packages列表里
packages.append(x)
# 返回packages
return packages
# show_dialog:显示对话框
def saveAllDirtyPackages(show_dialog=False):
"""保存所有脏包"""
if show_dialog:
return unreal.EditorLoadingAndSavingUtils.save_dirty_packages_with_dialog(
save_map_packages=True, save_content_packages=True
)
else:
return unreal.EditorLoadingAndSavingUtils.save_dirty_packages(
save_map_packages=True, save_content_packages=True
)
def savePackages(packages=[], show_dialog=False):
"""保存包"""
if show_dialog:
return unreal.EditorLoadingAndSavingUtils.save_dirty_packages_with_dialog(
packages_to_save=packages, only_dirty=False
)
else:
return unreal.EditorLoadingAndSavingUtils.save_dirty_packages(
packages_to_save=packages, only_dirty=False
)