henrique 2 months ago
parent 0af058f092
commit c6be47e675

@ -3,87 +3,76 @@ import sys
from pymxs import runtime as rt
def log(msg):
"""Log detalhado no Listener (F11)"""
print(f"[VR4Life Install Log] {msg}")
def install_plugin():
rt.clearListener()
log("=== CONFIGURANDO MENU VR4Life (INSTALAÇÃO NO FINAL) ===")
log("=== INICIANDO INSTALAÇÃO BLINDADA (VR4Life) ===")
# 1. Configuração de Caminhos
# 1. FORÇAR O REGISTRO DA PASTA NO PYTHON (Resolve Imagem 3)
user_scripts_dir = rt.getDir(rt.name("userScripts"))
plugin_dir = os.path.join(user_scripts_dir, "VR4Life_Plugin").replace("\\", "/")
if plugin_dir not in sys.path:
sys.path.append(plugin_dir)
engine_script = os.path.join(plugin_dir, "run_vr4life.py").replace("\\", "/")
update_script = os.path.join(plugin_dir, "vr4life_updater.py").replace("\\", "/")
sys.path.insert(0, plugin_dir) # Insere no topo para ter prioridade
log(f"Pasta registrada no Python: {plugin_dir}")
run_script = os.path.join(plugin_dir, "run_vr4life.py").replace("\\", "/")
product_name = "VR4Life"
category = "Immerse Games"
macro_name = "VR4Life_Launcher"
# 2. Registro das Macros
log("Registrando Macros no sistema...")
rt.execute(f'''
macroScript VR4Life_Open category:"{category}" buttonText:"VR4Life Engine"
( on execute do ( python.ExecuteFile @"{engine_script}" ) )
''')
rt.execute(f'''
macroScript VR4Life_Update category:"{category}" buttonText:"Atualizar Plugin"
( on execute do ( python.ExecuteFile @"{update_script}" ) )
''')
# 2. REGISTRO DA MACRO
macro_code = f'''
macroScript {macro_name}
category:"{category}"
buttonText:"{product_name}"
( on execute do ( python.ExecuteFile @"{run_script}" ) )
'''
rt.execute(macro_code)
# 3. Lógica de Menu para 3ds Max 2025/2026 (CUI)
# 3. LÓGICA DE MENU COM ESCUDO ANTI-ERRO (Resolve Imagens 2, 4, 5)
try:
log("Gerenciando interface via CUI Manager (2025+)...")
# Tenta o modo moderno do 2026 primeiro
cui_mgr = rt.cui.getContentManager()
main_menu_bar = cui_mgr.mainMenuBar
# Limpeza de versões anteriores
# Limpa qualquer resquício para evitar o "vai e vem"
for i in range(main_menu_bar.numItems - 1, -1, -1):
item = main_menu_bar.getItem(i)
if item.displayText == product_name or item.displayText == "1-VR4Life":
if item.displayText in [product_name, "1-VR4Life"]:
main_menu_bar.removeItem(item)
log(f"Limpando menu antigo: {item.displayText}")
# Criação do Menu
log("Criando menu moderno...")
new_menu = cui_mgr.createCustomMenu(product_name)
new_menu.addActionItem("VR4Life_Open", category)
new_menu.addActionItem("VR4Life_Update", category)
# addItem sem o segundo parâmetro ou com -1 coloca no FINAL da lista
main_menu_bar.addItem(new_menu, -1)
new_menu.addActionItem(macro_name, category)
main_menu_bar.addItem(new_menu, -1) # Adiciona no final como solicitado
rt.execute("cui.getContentManager().updateMainMenuBar()")
log("Menu VR4Life adicionado ao final da barra principal.")
except AttributeError:
# 4. Lógica Legada (2024 e anteriores)
log("Usando menuMan (Modo Legado)...")
main_menu = rt.menuMan.getMainMenuBar()
existing_menu = rt.menuMan.findMenu(product_name)
if existing_menu: rt.menuMan.unRegisterMenu(existing_menu)
new_menu = rt.menuMan.createMenu(product_name)
new_menu.addItem(rt.menuMan.createActionItem("VR4Life_Open", category), -1)
new_menu.addItem(rt.menuMan.createActionItem("VR4Life_Update", category), -1)
sub_menu_item = rt.menuMan.createSubMenuItem(product_name, new_menu)
# No menuMan, -1 também adiciona ao final
main_menu.addItem(sub_menu_item, -1)
rt.menuMan.updateMenuBar()
log("Menu legado adicionado ao final.")
except Exception as e:
# Se falhar (versões antigas), tenta o menuMan de forma segura
log("Tentando modo legado com segurança...")
try:
# Usamos hasattr para evitar que o script 'estoure' o erro de atributo
if hasattr(rt, "menuMan"):
main_menu = rt.menuMan.getMainMenuBar()
existing = rt.menuMan.findMenu(product_name)
if existing: rt.menuMan.unRegisterMenu(existing)
new_menu = rt.menuMan.createMenu(product_name)
new_menu.addItem(rt.menuMan.createActionItem(macro_name, category), -1)
sub_item = rt.menuMan.createSubMenuItem(product_name, new_menu)
main_menu.addItem(sub_item, -1)
rt.menuMan.updateMenuBar()
except:
log("Aviso: Não foi possível criar o menu superior, use o 'Customize User Interface'.")
# 5. Execução Automática
if os.path.exists(engine_script):
log("Executando interface do plugin...")
rt.python.ExecuteFile(engine_script)
# 4. EXECUÇÃO FINAL
if os.path.exists(run_script):
log("Executando motor...")
rt.python.ExecuteFile(run_script)
log("=== PROCESSO FINALIZADO COM LOGS ATIVOS ===")
rt.messageBox(f"Instalação do '{product_name}' concluída no final do menu!", title=product_name)
log("=== INSTALAÇÃO CONCLUÍDA ===")
if __name__ == "__main__":
install_plugin()
Loading…
Cancel
Save