[Closed] open bitmap of selected objects
Hi, we needed a script that would open all the bitmaps of the currently selected objects including any within multisubs etc…
so i found a script that sort of did what i needed and editied it…i have it to a stage where it opens up several images but only ones that are within in a multi material and any that are just top level dont seem to work…its something to do with my “if then else” statement i think, but i just cant spot it…
cs = getcurrentselection()
cscount = cs.count
for i = 1 to cscount do
(
if (cs[i].material) != undefined do
(
if classof cs[i].material == multimaterial then
(
for t = 1 to cs[i].material.numsubs do
(
if (classof cs[i].material.material[t].diffusemap) == bitmaptexture do
(
shelllaunch (getDir #maxroot + "Photoshp.exe.lnk") cs[i].material.material[t].diffusemap.filename
print i
Print t
print cs[i].material.material[t].diffusemap.filename
)
)
)
else
(
if (classof cs[i].material.diffusemap) == bitmaptextue do
(
shelllaunch (getDir #maxroot + "Photoshp.exe.lnk") cs[i].material.diffusemap.filename
print i
print cs[i].material.diffusemap.filename
)
)
)
)
Can anyone see what im doing wrong here…
Thanks again for your help…
Do not assume that all materials will be of a certain type or even have a diffusemap property.
Here is an example that scans for any sub-anims in the materials of the current selection that have a property “filename” and collects the bitmaps referenced there.
(
local theMats = #() --pre-initialize the array to collect into
--function to recursively collect sub-anims
fn getSubAnims theParent = (
for i = 1 to theParent.numsubs do ( --for each sub-anim
append theMats theParent[i] --add to the array and then call recursively
try(getSubAnims theParent[i].object)catch(getSubAnims theParent[i])
)--end i loop
)--end fn
--collect all valid materials from the current selection into the initial array
theMats = for o in selection where o.material != undefined collect o.material
for m in theMats do getSubAnims m --call the recursive function for each material
local theTextures = #() --initialize an array to collect the actual bitmaps
for o in theMats where --for each subanim, look for a filename property and if it was not collected yet,
hasProperty o "filename" and findItem theTextures o.filename == 0 do
append theTextures o.filename --collect it
-- do something with each bitmap file, replace with your code...
-- In the loop, we are also checking to see if the bitmap path is valid...
for t in theTextures where doesFileExist t do print t
OK
)