Notifications
Clear all

[Closed] Script is executing out of order

Hey all,
I’m writing a script and am having a problem with it executing out of order.

Here is the code:


global is7zipInstalled
global updateLog
global exe7za = "7zip.exe"
global archiveFile = "test.zip"
global exportDirectory = "$scripts/"
global filesToArchive = ""
	
function is7zipInstalled = ( true )
function updateLog msg = ( print msg )

-- add a ( here
print "one"
	-- Ask the user if they want to manually add files to the archive, or automatically do it if they don't have 7zip installed ------------------------------------------------
	if (queryBox "Would you like to add files manually to the zip file before it's packed?" modal:true) or not(local isInstalled = is7zipInstalled()) then (
		if not(is7zipInstalled()) then (
			-- Let the user know that the script can't automatically add files to the achive
			messageBox ("7zip was not found on your system, you might be using an operating system that is non-windows, manually add the files.")
		)
		messageBox ("You will need to manually add all of the files in the /export/ directory
 to the zip file " + (filenameFromPath archiveFile) + " yourself.

1. Click on OK, and then drag the files in the \export\ directory to the opened .zip file.")
		
		ShellLaunch archiveFile ""
		ShellLaunch exportDirectory ""
		createDialog rlt_finishedAddingFiles 370 150 modal:true
	)
	
	print "two"
	-- Check for 7zip ------------------------------------------------------------------------------------------------------------------------------------------------------------------
	if is7zipInstalled() then (
		-- Automatically add all the files to the archive
		local exeToRun = "\"" + (symbolicPaths.expandFileName exe7za) + "\""
		local mainArchive = "\"" + (symbolicPaths.expandFileName archiveFile) + "\""
		local filesToArchive = "\"" + (symbolicPaths.expandFileName exportDirectory) + "*.*\""
		local commandToRun = exeToRun + " a -tzip " + mainArchive + " " + filesToArchive
		--format "commandToRun: [%]
" commandToRun
		
		if (DOSCommand ("\"" + commandToRun + "\"")) == 0 then (
			-- Completed successfully
			updateLog "7zip Successfully packed the Archive"
			print "should be the last thing"
		) else (
			-- Problem executing the DOSCommand
			-- Tell the user there was a problem packing the file, and to try it manually
			messageBox "There was a problem packing the files into the .vu3 file.

To ensure the project is rendered correctly, rename the .vu3 file to .zip and make sure all the files in the export directory are there." beep:true
			updateLog "7zip was not able to automatically add the files to the achive"
		)
	)
-- and a ) here for proper ordering...

I’ve read the help files plenty and if I encase it in ( ) parenthesis, it will execute in order, however this is only part of the code and it is already enclosed in parenthesis, how can I make this section execute in order? You can see in the listener window it doesn’t currently.

Thanks a ton everyone,
Colin

2 Replies

What exactly does not execute in order?
Keep in mind that ShellLaunch() launches an external thread and does not block the MAXScript thread, so if you are seeing problems related to the zip processing outside of the script, that might explain it. You will either have to use the DOSCommand() method instead (which will block the MAXScript thread until done), or use some form of file checking to make sure the ShellLaunch() calls have finished processing before you continue with the rest of the code. (for example, you could create a LOCK file, a BAT file for the processing and add a command to the BAT file to delete the LOCK when the ZIPping is done, then loop the MAXScript thread waiting for the LOCK file to disappear).

In my tests (since I don’t have your files/zipping utils), I got the prints to print in order and could not see the order issues you are reporting…

Thanks for replying Bobo, the part I linked is fully runnable even though you don’t have the correct functions etc, I overrode them with what they will have when the user runs it. run the above code and just press “no” at first.

What happens is the DOSCommand (“”” + commandToRun + “””) is getting run before asking the user “Would you like to add files manually to the zip file before it’s packed?”…

So it automatically is zipping the files before the “queryBox” even pops up for the user.

It’s on an off, the above code sometimes works in order, sometimes doesn’t to me (I can’t get it to run out of order at the moment, but it was).

If you aren’t sure how to solve it, I’ll go with the lock file method.

Thanks again,
Colin