Notifications
Clear all

[Closed] How do you cancel an export?

Is it possible to have a callback script run preExport, and then if the script should fail, or if a certain event results allow the script to cancel the Export?

so to clarify…using callbacks.addScript “Export_Script()#preExport

if Export_Script() returns “cancel” can i then Cancel the Export?

Or as soon as you click the Export in max, there’s no way to stop it from Exporting?

4 Replies

One method (maybe the only method) is to use dialogMonitorOps to check when the dialog opens, and uiAccessor to close it if your script determines that it should be aborted

quick test script…


-- change this variable to set whether the file export dialog should be closed
doExport = false

callbacks.removescripts id:#exportTest
fn closeExportDialog = (
	local _hwnd = dialogMonitorOps.getWindowHandle()
	local _title = UIAccessor.getWindowText _hwnd
	if (_title == "Select File to Export") then (
		UIAccessor.closeDialog _hwnd
		dialogMonitorOps.unregisterNotification id:#closeExportDialog
		dialogMonitorOps.enabled = false
		false
	)
	else ( true )
)

fn exportTest = (
	if (not doExport) then (
		dialogMonitorOps.enabled = true
		dialogMonitorOps.registerNotification closeExportDialog id:#closeExportDialog
	)
)

callbacks.addScript #preExport "exportTest()" id:#exportTest

Awesome man…thanks for you help

alternatively you could use fileExport and export the file manually, but I’m presuming you’re using the callback for a reason Good luck!