Pymxs get textures on selected objects only

Hi, so we’re moving up our Max version at work, which means I need to rwwrite a whole bunch of MaxPlus stuff as pymxs. Which is proving rather trickey, as it’s not super obvious how to rewite everything (at least not to me!).

Starting on a basic issue, I have MaxPlus code that will find all the textures on all selected objects, and then change the filepaths to different textures (we use it to swap up and down texture versions and between formats). I managed to find the MaxPlus code I needed a few years back and that was fine, but can’t figure how to pymxs it.

Here’s the original code fragment:

        fn existFile fname = (getfiles fname).count != 0
        fn GetBitmapTextures theObjects =
            texMaps =  # ()
        for obj in theObjects do
        join texMaps (getClassInstances bitmapTexture target:obj asTrackViewPick:off)
        makeUniqueArray texMaps

        local sFrom = "{old_format}" -- previous format
        local sTo = "{new_format}" -- the format that we want

        texMaps = (GetBitmapTextures selection)
        for texMap in texMaps do print (
        local sFilename = texMap.filename
        local sPath = getFilenamePath sFilename
        local sFile = getFilenameFile sFilename
        local sType = replace (getFilenameType sFilename) 1 1 ""

        local newFileName = sPath +"JPEG/"+sFile + "." + sTo
        isThere = existFile newFileName
        if isThere == True do(

        if toLower sType == toLower sFrom do texMap.filename = newFileName

I know I can find all textures with pymxs.runtime.getClassInstances(rt.bitmapTexture) and I know I can find selected objects with pymxs.runtime.selection. But I can’t work out how to get the bitmaps only on the selected objects, whatever I try when iterating through the selected objects it tells me that the object doesn’t have the needed attribute.

If I can filter pymxs.runtime.getClassInstances(rt.bitmapTexture) in any way to only show me maps that are associated witht the selected objects, then doign the texture renaming/swapping is pretty trivial, but after masses of searching and my own trial and error, I just can’t work out how to get the textures only on my selected objects.

I’m assuming I’m just missing somethign obvious, any ideas? Thanks for any help!

I also asked this over at Autodesk, and got a solution there, in case anyone else stumbles across this and needs the answer:

1 Like