Script layout can normally execute the command, but the icon under the menu can not correctly execute the command, why, I am a beginner, please answer the master doubts!
Updated by Ilia on 22/05/2024:
Consolidated consequent messages in a single posting:
import os
import c4d
class ImportDialog(c4d.gui.GeDialog):
BUTTON_ID_BASE = 1000
def __init__(self):
self.files = [] # 初始化为空列表
def LoadFiles(self):
startup_path = c4d.storage.GeGetStartupWritePath()
project_dir = os.path.join(startup_path, 'library', 'scripts', 'spline load', 'projects')
if not os.path.exists(project_dir):
c4d.gui.MessageDialog('项目目录不存在。')
return False
self.files = [os.path.join(project_dir, f) for f in os.listdir(project_dir) if f.endswith('.c4d')]
return True
def CreateLayout(self):
self.SetTitle("Import C4D Projects")
if not self.LoadFiles():
return False # 如果加载文件失败,不创建布局
for index, file in enumerate(self.files, start=self.BUTTON_ID_BASE):
filename = os.path.splitext(os.path.basename(file))[0]
self.AddButton(index, c4d.BFH_CENTER, name=filename)
return True
global_dialog_instance = None
def main():
global global_dialog_instance
if global_dialog_instance is None:
global_dialog_instance = ImportDialog()
global_dialog_instance.Open(c4d.DLG_TYPE_ASYNC, defaultw=400, defaulth=50)
if __name__=="__main__":
main()