Bitmap swapping

Hi all, im a maxscript novice.

Im trying to swap a bitmap image in the ui with a button click. Ive tried calling a function from bitmap filename:. a variable works but not with the buttons.

so far not great:)

fn test1 =
(
img1 = @"B:\images1.jpg"
)

fn test2 =
(
img1 = @"B:\images2.jpg"
)

rollout _test "test"

(
bitmap bmp1 "Bitmap" pos:[7,11] width:146 height:121 --filename: --not sure here

button _A "A"
on _A pressed do

(
test1()
)

button _B "B"
on _B pressed do

(
test2()
))

createdialog _test

any help is appreciated

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sdds's picture

Thanks Swordslayer, really

Thanks Swordslayer, really appreciate the help!

The underscore is something i picked up from a tutorial. and murge is a typo lol.

I cant seem to get the max file to merge though. Ill look into variable scope.

thanks again

sdds's picture

thanks, that helped a

thanks, that helped a lot!!!

I have another issue trying to fix with string trimming.

the result is pulled into a list box, and i need to remove the .jpg and replace with .max to merge a max file on selection.

_MatItems = GetFiles @"F:\test\*.jpg"
_MatItemsUI = #()

for i = 1 to _MatItems.count do
(
_MatItemsUI[i] = (filterstring _MatItems[i] @"\") [7]
)

Rollout _MatImport "Exterior Materials" width:310
(

bitmap bmp1 "Bitmap" pos:[7,11] width:300 height:300

Listbox _InteriorMats "Materials" items: _MatItemsUI

Button _ApplyMat "Apply Material"
on _ApplyMat pressed do
(

MurgeFile = _MatItems[_InteriorMats.selection]".max"
mergemaxfile MurgeFile

)

createdialog _MatImport

Swordslayer's picture

Basically, aomething like

Basically, aomething like this should do the trick:

_MatItems = getFiles @"F:\test\*.jpg"
_MatItemsUI = for mat in _MatItems collect getFilenameFile mat
 
rollout _MatImport "Exterior Materials" width:310
(
	bitmap bmp1 "Bitmap" pos:[7,11] width:300 height:300
	listBox _InteriorMats "Materials" items:_MatItemsUI
	button _ApplyMat "Apply Material"
 
	on _ApplyMat pressed do
	(
		local murgeFile = _MatItems[_InteriorMats.selection] + ".max"
		mergeMaxFile murgeFile
	)
)
createDialog _MatImport

Btw. you have a peculiar choice of variable names, why all the underscores and stuff like murge instead of merge? Get used to using explicit locals, read about variable scope in the reference and fear not and use simple var names ;)

Swordslayer's picture

Use the bitmap property

Use the bitmap property instead:

rollout _test "test"
(
	bitmap bmp1 "Bitmap" pos:[7,11] width:146 height:121 bitmap:(openBitMap @"B:\images1.jpg")
	button _A "A"
	button _B "B"
 
	on _A pressed do bmp1.bitmap = openBitMap @"B:\images1.jpg"
	on _B pressed do bmp1.bitmap = openBitMap @"B:\images2.jpg"
)
createDialog _test

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.