PDA

View Full Version : Possible to avoid "Error on opening bitmap" on image buttons


am7
02-08-2010, 05:55 PM
Hi, I have searched this forum and the max help - and I can't seem to figure out how to fallback to the specified label in a button if an image doesn't exist.

For example:

button foo "label" images:#("dcybtns.bmp", undefined, 1, 1, 1, 1, 1)


If dcybtns.bmp doesn't exist I would like to avoid the compile error and just use the text label instead.

I could check if the file exist before in a if/else clause, but I was thinking there had to be an easier way? I couldn't get try/catch to work either..

denisT
02-08-2010, 07:47 PM
that's probably easiest way:

rollout test "test"
(
local images = if doesfileexist (getdir #ui + "\\icons\\dcybtns.bmp") then #("dcybtns.bmp", undefined, 1, 1, 1, 1, 1) else unsupplied
button bt "button" images:images
)
createdialog test

am7
02-08-2010, 08:27 PM
Thanks Denis, what if I'd want to check against the folder the script is executed from?

denisT
02-08-2010, 08:40 PM
Thanks Denis, what if I'd want to check against the folder the script is executed from?
use getFilenamePath (getSourceFileName()) to get the directory of the loading script

CGTalk Moderation
02-08-2010, 08:40 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.