Att PreLoadScript


Attribute Att_PreLoadScript

Set this attribute of your main model to Typescript commands that you want executed during a model load, before the indicated object is loaded. It is usually set for the main model object, giving you an opportunity to abort the load before anything has been loaded into memory. If desired, you can abort the load by executing the typescript command Bye.

This provides the best opportunity to enforce licensing restrictions, require the user to agree to licensing terms, or tell the user that he can't run the model in this release of Analytica. However, be aware that your model HAS NOT YET been loaded into memory when these commands are executed, so your script cannot call any User-Defined Functions or access any variables in your model. All logic must be fully self-contained. You can call built-in functions.

You'll probably want to write an Analytica expression, enabling the use of If-Then, etc. To do this, surround the expression inside parenthesis. Otherwise, the commands you enter are interpreted as typescript.

There is not a UI for editing this attribute, so you have to set it from the Typescript window. Press the F12 key to open the typescript window. Assuming your top-level model's identifier is MyModel, you could configure it to show a message box with a YES-NO question like this:

prompt> Att_PreLoadScript MyModel: (MsgBox("Do you agree to my licensing terms?", buttons:4))

Save and reload and you should see this appear. Of course, it doesn't actually do anything based on what you answered. If the user enters No, you probably want to abort the load. So for that, you can do this:

prompt> Att_PreLoadScript MyModel: (If MsgBox("Do you agree to my licensing terms?", buttons:4)=7 Then EvaluateScript("Bye"))

If you type multiple typescript commands (one per line), you'll need to end each line with a tilde when typing them in the Typescript window. If you just want to continue a long command on the next line, but without an actual newline in the typescript, end the line with two tildes (~~).

Comments


You are not allowed to post comments.