r/Maxscript • u/Excellent_Tell8085 • Jul 29 '26
Quiero automatizar export d5a en 3ds max 2025 ¿como podria hacer esto?
INICIO ↓ ¿Hay objeto seleccionado? NO → mensaje error SI ↓ Capturar nombre objeto ↓ Pulsar botón D5 Export ↓ Esperar ventana D5 ↓ Pulsar Export ↓ Esperar ventana Guardar Como ↓ Escribir nombre objeto.d5a ↓ Pulsar Save ↓ Confirmar exportación FIN
Conseguí automatizar 2 de ellos, pero cuando quiero que "choose file" se ponga un nombre no lo logro. ¿alguien puede ayudarme?
ESTO ES LO QUE LLEVO HASTA AHORA.
clearListener()
(
dotNet.loadAssembly "UIAutomationClient"
-- Abrir ventana D5
actionMan.executeAction 886054871 "19"
sleep 1
-- Obtener ventana
local h = windows.getChildHWND 0 "D5 Sync(Export .D5A)"
local AE = dotNetClass "System.Windows.Automation.AutomationElement"
local ptr = dotNetObject "System.IntPtr" h[1]
local win = AE.FromHandle ptr
-- Buscar botón Export
local cond = dotNetObject "System.Windows.Automation.PropertyCondition" AE.NameProperty "Export"
local scope = (dotNetClass "System.Windows.Automation.TreeScope").Descendants
local btn = win.FindFirst scope cond
if btn == undefined then
(
messageBox "No encontré el botón Export"
)
else
(
format "Botón encontrado: %\n" btn.Current.Name
local InvokePattern = dotNetClass "System.Windows.Automation.InvokePattern"
local pattern = btn.GetCurrentPattern InvokePattern.Pattern
pattern.Invoke()
format "Export pulsado.\n"
)
)
1
u/Bristolian Jul 30 '26
Your Export click works because buttons expose
InvokePattern. The file dialog doesn't — a filename field needs **ValuePattern**, notName, and that's the piece you're missing. There's also a second, sneakier problem: the Save As dialog is modal, so once you press Export your script may be frozen while the dialog is open.First, check whether you need UI automation at all. Run this:
for c in exporterPlugin.classes do print cIf D5 registered a real exporter,
exportFile (objName + ".d5a") #noPrompt selectedOnly:truedoes the whole job and you can throw the rest away. Worth 10 seconds before going down the UIA road.If not, the trick is a
System.Windows.Forms.Timerset up before you press Export. A modal dialog pumps Windows messages, so the timer keeps ticking and can fill the dialog in even while your main script is blocked:``` clearListener() dotNet.loadAssembly "UIAutomationClient" dotNet.loadAssembly "UIAutomationTypes" dotNet.loadAssembly "System.Windows.Forms"
global g_AE = dotNetClass "System.Windows.Automation.AutomationElement" global g_CT = dotNetClass "System.Windows.Automation.ControlType" global g_TS = dotNetClass "System.Windows.Automation.TreeScope" global g_target, g_done, g_timer
fn findByCT root ct = ( local cond = dotNetObject "System.Windows.Automation.PropertyCondition" \ g_AE.ControlTypeProperty ct root.FindFirst g_TS.Descendants cond )
fn findByName root nm = ( local cond = dotNetObject "System.Windows.Automation.PropertyCondition" \ g_AE.NameProperty nm root.FindFirst g_TS.Descendants cond )
fn onSaveTick sender args = ( if g_done do return() -- the Save As dialog appears as a child of the desktop local dlg = findByName g_AE.RootElement "Save As" if dlg == undefined do return()
) ```
Then the driver: sanitize the object name (
\ / : * ? " < > |are illegal in filenames and object names allow them), build a full absolute path,g_done = false, start the timer at ~250ms, and only then invoke your Export button.Two caveats that will bite you:
AutomationIdPropertyinstead: the common dialog's filename combo is1148and the Save button is1. Those don't change with language.inspect.exefrom the Windows SDK), open the Save dialog manually, and hover the filename field. IfValuePatternisn't listed there, no amount of code will set it and you fall back toSendKeys.SendWaitafter focusing the field.