Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

[MAXScript] Try (...) catch (...) not working
show user profile  Nanne
I have the following code

include @"includes\"
format "ERROR:: Unable to include 'includes\', make sure you use 'Scripting -> Run Script...' from the menu in 3ds Max\n"

But the catch is never executed, I just get the regular error message in the listener.
-- Error occurred in anonymous codeblock;
-- Compile error: Can't find include file: includes\
-- In line: include @"includes\"

I want to skip this and have give the user a more helpful error message. Why isn't it working? I'm using Max 2016, is this a bug, or have I misunderstood how try/catch works?

Kristoffer Helander
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 146 times
9/30/2016 6:09:26 PM (last edit: 9/30/2016 6:09:26 PM)
show user profile  Garp
try/catch is a runtime mechanism and, according to the doc, include is done at compile time.
If the compiler fails to include the file, you get an compile-time error and the code never runs.

There's a workaround to get the functionality you need but it's a bit more involved.

read 121 times
10/1/2016 1:11:19 AM (last edit: 10/1/2016 7:53:23 AM)
show user profile  Nanne
Oh, I see. Thank you for pointing it out.

Could you give me some information to go on, regarding that workaround? :)

Kristoffer Helander
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 107 times
10/1/2016 1:26:06 PM (last edit: 10/1/2016 1:26:06 PM)
show user profile  Garp
I'm supposing that:
- you want to include a single file in a single place, let's call it my_include
- if my_include is not available, you just want to give a message and keep running the script my_script
You need two other parts, my_launcher and my_bridge.

my_script doesn't include my_include directly. instead it includes my_bridge.
my_launcher is also a script and it does the following:
- create my_bridge (or open it if already present)
- check for the availability of my_include
- if ok add (or override the content with) include "my_include" to my_bridge, otherwise add nothing (or empty the file) and display a message
- close my_bridge
- run my_script
When my_script runs, it includes my_bridge and runs whatever is in it. If my_include was found, my_script includes it and runs its content.

I haven't tested it. I hope there isn't some funky look-ahead during compilation such that when the compiler sees the instruction to run my_script inside my_launcher, it tries to compile my_script right away, before running my_launcher. That would defeat the whole thing.

The system is started by running my_launcher.
If you intended to run my_script from the UI, say a button, you have packaged it in a macro. If that's the case, turn it back to a regular script, make my_launcher a macro and hook this guy to the button.

Hope it's not too confusing.

read 102 times
10/1/2016 4:05:50 PM (last edit: 10/1/2016 4:19:41 PM)
show user profile  Nanne
Wow, that's a lot of info, thanks! :)

I think I understand what you mean. I hope I'll have time to try this, I will at least keep it around for future references!


Kristoffer Helander
  :: Works ::   |  :: Resumé ::   |  :: Contact ::   |  :: CG Blog ::   |  :: Links ::     
read 86 times
10/1/2016 8:33:50 PM (last edit: 10/1/2016 8:33:50 PM)
show user profile  Garp
Here's a running example.

my_script: the original script that does the useful work

my_include: the include file that adds extra stuff to the script

my_launcher: where the magic happens

If my_include is present, the output is
Running my_script before . . .
Running my_include . . .
Running my_script after . . .

If my_include is missing, you get
Running my_script before . . .
Running my_script after . . .

read 82 times
10/2/2016 12:33:07 AM (last edit: 10/2/2016 12:38:35 AM)
#Maxforums IRC
Open chat window