You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.4 KiB
Python
112 lines
4.4 KiB
Python
import os
|
|
import sys
|
|
from pymxs import runtime as rt
|
|
|
|
def log(msg):
|
|
"""Função para imprimir no Listener (F11) com prefixo identificável"""
|
|
print(f"[VR4Life Install Log] {msg}")
|
|
|
|
def install_plugin():
|
|
rt.clearListener()
|
|
log("=== INICIANDO FASE DE CONFIGURAÇÃO DE INTERFACE (UNIVERSAL) ===")
|
|
|
|
# 1. Configuração de Caminhos Locais
|
|
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)
|
|
log(f"Path Python atualizado: {plugin_dir}")
|
|
|
|
run_script = os.path.join(plugin_dir, "run_vr4life.py").replace("\\", "/")
|
|
log(f"Caminho do script de execução detectado: {run_script}")
|
|
|
|
# Definições do Produto
|
|
product_name = "1-VR4Life"
|
|
category = "Immerse Games"
|
|
macro_name = "VR4Life_Launcher"
|
|
|
|
# 2. Registro do MacroScript (Obrigatório para o comando existir no sistema)
|
|
log(f"Registando MacroScript '{macro_name}'...")
|
|
macro_code = f'''
|
|
macroScript {macro_name}
|
|
category:"{category}"
|
|
buttonText:"{product_name}"
|
|
tooltip:"Abrir {product_name}"
|
|
(
|
|
on execute do ( python.ExecuteFile @"{run_script}" )
|
|
)
|
|
'''
|
|
try:
|
|
rt.execute(macro_code)
|
|
log("MacroScript registado com sucesso.")
|
|
except Exception as e:
|
|
log(f"ERRO ao registar MacroScript: {str(e)}")
|
|
|
|
# 3. Lógica de Menu para 3ds Max 2025/2026 (CUI Content Manager)
|
|
try:
|
|
log("Tentando configurar via CUI Content Manager (3ds Max 2025+)...")
|
|
cui_mgr = rt.cui.getContentManager()
|
|
main_menu_bar = cui_mgr.mainMenuBar
|
|
|
|
# Verificar e remover duplicados para evitar menus 'fantasmas'
|
|
existing_item = None
|
|
for i in range(main_menu_bar.numItems):
|
|
item = main_menu_bar.getItem(i)
|
|
if item.displayText == product_name:
|
|
existing_item = item
|
|
log("Menu já existente detectado. Removendo para reinstalação limpa...")
|
|
break
|
|
|
|
if existing_item:
|
|
main_menu_bar.removeItem(existing_item)
|
|
log("Menu antigo removido da barra CUI.")
|
|
|
|
# Criação do Menu Moderno
|
|
log(f"Criando novo menu '{product_name}'...")
|
|
new_menu = cui_mgr.createCustomMenu(product_name)
|
|
new_menu.addActionItem(macro_name, category)
|
|
|
|
# Insere na posição 1 (logo após o 'File')
|
|
main_menu_bar.addItem(new_menu, 1)
|
|
log(f"Menu '{product_name}' adicionado à barra principal.")
|
|
|
|
# Forçar o 3ds Max a redesenhar a barra de menus (Crucial para o 2026)
|
|
log("Solicitando atualização forçada da barra de menus...")
|
|
rt.execute("cui.getContentManager().updateMainMenuBar()")
|
|
log("Comando 'updateMainMenuBar' enviado.")
|
|
|
|
except AttributeError:
|
|
# 4. Lógica Legada (3ds Max 2024 e anteriores)
|
|
log("CUI Manager não disponível. Usando modo legado 'menuMan'...")
|
|
try:
|
|
main_menu = rt.menuMan.getMainMenuBar()
|
|
existing_menu = rt.menuMan.findMenu(product_name)
|
|
|
|
if existing_menu:
|
|
rt.menuMan.unRegisterMenu(existing_menu)
|
|
log("Menu legado antigo removido.")
|
|
|
|
new_menu = rt.menuMan.createMenu(product_name)
|
|
menu_item = rt.menuMan.createActionItem(macro_name, category)
|
|
new_menu.addItem(menu_item, -1)
|
|
|
|
sub_menu_item = rt.menuMan.createSubMenuItem(product_name, new_menu)
|
|
main_menu.addItem(sub_menu_item, 1)
|
|
rt.menuMan.updateMenuBar()
|
|
log("Menu legado criado e atualizado com sucesso.")
|
|
except Exception as e:
|
|
log(f"ERRO na criação de menu legado: {str(e)}")
|
|
|
|
# 5. Inicialização pós-instalação
|
|
if os.path.exists(run_script):
|
|
log("Abrindo interface VR4Life para teste imediato...")
|
|
rt.python.ExecuteFile(run_script)
|
|
else:
|
|
log(f"AVISO: Arquivo de execução não encontrado em: {run_script}")
|
|
|
|
log("=== PROCESSO DE INSTALAÇÃO FINALIZADO ===")
|
|
rt.messageBox(f"Instalação do '{product_name}' concluída!\nSe o menu não aparecer imediatamente, verifique o Listener (F11).", title=product_name)
|
|
|
|
if __name__ == "__main__":
|
|
install_plugin() |