ScriptSpot

Forum topic · General Scripting

How do I run a script on startup of a specific file

By Gindin · 2008-03-20

Description

I have a script that checks for updates on a FTP server & updates some materials automatically.

Now I want it to run at startup of a specific max file. I know I can place it in certain folders as Startup Scripts, but then they'll run on every startup.

Any ideas

Eran?

Comments (2)

Gindin · 2008-03-24

Hi Ofer,

 

 Thanks for the help, I already went with the callbacks.addScript route. Works fine.

 

Great to see someone from Israel :-)

& some great scripts on your site

 

Thanks

Eran

Ofer Zelichover · 2008-03-23

Hi,

 

If I understand you correctly, you wish to run the script every time a specific file is opened. If so, I would do it like so:

First, you will have save save some variable with the file. There are a few way to do this:

1. Use appData. e.g. setAppData globalTracks 654321 "update from ftp"

2. Use a persistent global variable. e.g. persistent global g_UpdateFromFTP = true

3. Use a custom attribute on a global track.

I would use the appData method, as persistent globals had issues in older versions of max. It should be safe to use them since max 8, though.

 

Next, write a small script that will be placed in the scripts/startup folder. This script should look something like:

(

callbacks.addScript #filePostOpen "if getAppData globalTracks 654321 == \"update from ftp\" then fileIn \"path/to/your/script.ms\"" id:#updateFromFTP

-- Or if you used the persistent global option use the following:

--callbacks.addScript #filePostOpen "if g__UpdateFromFTP == true then fileIn \"path/to/your/script.ms\""
id:#updateFromFTP

)

 

 

hOpe this helps,

o