Notifications
Clear all

[Closed] Possible to avoid "Error on opening bitmap" on image buttons

 am7

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…

3 Replies

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

Thanks Denis, what if I’d want to check against the folder the script is executed from?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

use getFilenamePath (getSourceFileName()) to get the directory of the loading script