Amirmohammad Farhang
Amirmohammad Farhang

Reputation: 31

File exist issue with maxscript

Im writing a small script to wait for a file to exist and then read .Just it. But my issue is i have a while loop and it just wait for a file to be exist and my script and 3dsmax get unresponde . . . I dont have any idea to fix my unresponde error but i have done it many times in c# by threads. By the way, for now there is no idea. Its my script

while true do
(
file_name = openfile “C:/Users/Kasra/Dekstop/t.txt”
if file_name != “undefined” then
(
exit
)
)

file_address = readLine file_name

Can somebody give me a example or code/help/solution?

Thanks a lot!

Upvotes: 0

Views: 1359

Answers (1)

Jeremy
Jeremy

Reputation: 367

If you use an infinite loop, you will never leave time for anything else to execute, therefore making 3ds Max unresponsive. It should technically be responsive again once the file is correctly opened. If it is still unresponsive even if the file exist, I suspect that the 3ds Max process might not have enough privileges to successfully the file?

Alternatively, if you would like to avoid blocking the UI, you could use .Net timer to generate event every x ms to check if the file exist. This will avoid blocking 3ds Max. Here is a small snippet that might help you:

fileThatShouldExist = "C:/Users/Kasra/Dekstop/t.txt"
fn doWhatIsNext = (
    print "do what you want once the file exist"
)

fn executeEvertTick = (
    if doesFileExist fileThatShouldExist do (
        myTimer.stop()
        doWhatIsNext()
    )
)
myTimer = dotNetObject "System.Windows.Forms.Timer"

dotnet.addEventHandler myTimer "tick" executeEvertTick
myTimer.interval = 1000 -- every 1000 ms
myTimer.start()

Upvotes: 1

Related Questions