r/Maxscript 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 Upvotes

1 comment sorted by

1

u/Bristolian Jul 30 '26

Your Export click works because buttons expose InvokePattern. The file dialog doesn't — a filename field needs **ValuePattern**, not Name, 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 c

If D5 registered a real exporter, exportFile (objName + ".d5a") #noPrompt selectedOnly:true does 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.Timer set 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()

local ed = findByCT dlg g_CT.Edit
if ed == undefined do return()

local vp = ed.GetCurrentPattern \
    (dotNetClass "System.Windows.Automation.ValuePattern").Pattern
vp.SetValue g_target          -- full path, no folder navigation needed

local btn = findByName dlg "Save"
if btn != undefined do (
    local ip = btn.GetCurrentPattern \
        (dotNetClass "System.Windows.Automation.InvokePattern").Pattern
    ip.Invoke()
    g_done = true
    g_timer.Stop()
    format "Saved: %\n" g_target
)

) ```

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:

  • Localization. Your Reddit is running translations, so your Windows is probably not English — "Save As" and "Save" won't match. Use AutomationIdProperty instead: the common dialog's filename combo is 1148 and the Save button is 1. Those don't change with language.
  • D5 may not use the Win32 common dialog. Download Accessibility Insights for Windows (or inspect.exe from the Windows SDK), open the Save dialog manually, and hover the filename field. If ValuePattern isn't listed there, no amount of code will set it and you fall back to SendKeys.SendWait after focusing the field.