Simplify Code

Hi all masters, i need some help here. I need simplify code script from my script, its work fine but i think it can be simplified.

try destroyDialog Rtest catch()
rollout Rtest "Test-Rollout"
(
button bt1 "Load_Material"
button bt2 "Apply"
edittext 'Fdir' "" width:130 height:20 enabled:false
on bt1 pressed do
(
local curpath = Fdir.text
local newPath = getSavePath initialDir:(curpath) caption:"Select the path where your Images are located"
if newPath != undefined then
(
Fdir.enabled = true
Fdir.text = newpath
--HERE START A LARGE CODE--
meditMaterials[1] = Multimaterial ()--Apply MultiMaterial in the first slot of Material Editor
meditMaterials[1].materialList[1].diffuseMap = Bitmaptexture fileName: (Fdir.text +"\1.png") -- Load image in diffuse slot map
meditMaterials[1].materialList[1].opacityMap = Bitmaptexture fileName: (Fdir.text +"\1.png") --Load the same image in opacity slot map
meditMaterials[1].materialList[1].opacityMap.monoOutput = 1 -- Active alpha ouput for mask diffuse map
meditMaterials[1].materialList[1].showInViewport = on --Show material in viewport

--- HERE MY QUESTION,: I HAVE TO REPEAT THIS STEP FOR ALL MATERIALS ?, SOME SUGGESTION TO SIMPLIFY THIS?--

meditMaterials[1].materialList[2].diffuseMap = Bitmaptexture fileName: (Fdir.text +"\2.jpg")
meditMaterials[1].materialList[3].diffuseMap = Bitmaptexture fileName: (Fdir.text +"\3.jpg")

)
)

on bt2 pressed do
for obj in selection do if obj.material == undefined then
(
obj.material = meditMaterials[1] -- Apply Material in selection objects
)
else
(
messagebox "Ready Material"
)
)
createDialog Rtest

thanks for your help.

Comments

Comment viewing options

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

...

try destroyDialog ::Rtest catch()
rollout Rtest "Test-Rollout"
(
	local sioDir = dotNetClass "System.IO.Directory"
	local sioSOpt = (dotNetClass "System.IO.SearchOption").AllDirectories
 
	button bt1 "Load_Material"
	button bt2 "Apply"
	edittext Fdir "" width:130 height:20 enabled:false
	on bt1 pressed do
	(
		local curpath = if sioDir.exists Fdir.text then Fdir.text else ""
		local newPath = getSavePath initialDir:(curpath) caption:"Select the path where your Images are located"
		if newPath != undefined then
		(
			local allFiles = sioDir.GetFiles newPath "*.*" sioSOpt
			if allFiles.count > 0 do
			(
				local extensions = #(".jpeg",".jpg",".png"), cnt = 0
				node = for f in allFiles where (ext = findItem extensions (tolower (getfilenametype f))) > 0 collect
				(
					mtl = if ext != 3 then standard name:(getFilenameFile f) diffusemap:(Bitmaptex fileName:f) else
					(
						map = datapair diff:(Bitmaptex fileName:f) trans:(Bitmaptex fileName:f monoOutput:1)
						standard name:(getFilenameFile f) diffusemap:(map.diff) opacitymap:(map.trans)
					)
					mtl.showInViewport = on ; mtl
				)
				meditMaterials[activeMeditSlot] = Multimaterial materialList:node
			)
		)
	)
	on bt2 pressed do if selection.count > 0 do selection.material = meditMaterials[activeMeditSlot]
)
createDialog Rtest

bga

Comment viewing options

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