Notifications
Clear all

[Closed] Getting a list of scene bitmap paths

Hey guys,
I’m trying to get a list of all the bitmap paths used in my scene. I am aware that you can get this list from the asset tracker, but I need it in script so I can do further checks.
Any help would be appreciated.

Regards,
Adam

11 Replies

Ah did it.

for i in sceneMaterials do
(
bitmapName = getClassInstances BitmapTexture
for Bmap in bitmapName do
(sPath = getFilenamePath sFilename)
)

mmmm, now to figure out how to do it only for the selected objects only.

1 Reply
(@jsnb)
Joined: 11 months ago

Posts: 0

I’ve never been able to get that code to work as I only encounter bitmap files, which is not a MAXClass, but:

  1. I don’t think you need to loop through the scenematerials – you never call ‘i’. Unless the target option is used I think the function trolls through the scene level.
  2. You can send a target option to the getclassInstances function. For example:
    bitmaps = getClassInstances bitmapTexture target:someobject

I’m just reading/writing this pretty late – but I don’t believe that the sPath = getFilenamePath sFilename should do anything but give you errors – unless you have already defined sFilename.

if you search cgtalk for getClassInstances BitmapTexture – you should get a ton of examples.

 lo1
fn getFilesFromObjects objs =
(
	local mats = makeUniqueArray (for o in objs collect o.material)
	local totalFiles = #()
	for m in mats do
	(
		for b in getClassInstances bitmapTex target:m where b.filename != undefined and doesFileExist b.filename do
		(
			appendIfUnique totalFiles b.filename
		)
	)
	totalFiles
)

I still prefer to use the asset tracking commands as they are faster and will always find all file references. Then you can just filter out the files you want to tracks.


fn get_bitmaps = 
(	
	local files = #()
	local bitmaps = #()
	
	-- refresh asset tracking files
	atsops.Refresh()
	
	-- this call gets all external scene references bitmaps, shaders, audio, etc.
	atsops.getfiles &files
	
	-- next you can filter out the particluar files you are looking for
	for file in files do (
		if (matchpattern file pattern:"*.tga") do (
			append bitmaps file
		)		
	)
	
	-- print bitmaps
	format "Bitmaps:
"	
	print bitmaps
)
get_bitmaps()

there is nothing easier than use enumerateFiles. See mxs help for samples and details.

2 Replies
(@kickflipkid687)
Joined: 11 months ago

Posts: 0

But does that also pickup Bitmaps in a DX shader? I believe so, but can’t remember. I have a tool that collects all unique bitmaps in the scene, but I had to do 2 methods to get them all I think. Well and then even more methods to get XRef Bitmaps I believe.

(@denist)
Joined: 11 months ago

Posts: 0

it enumerates ALL bitmap files in the scene including all in DX shaders.

hm… good to know.

I realized now, I had other methods because I wanted to quickly get the bitmaps, but then later needed to find out where they came from.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

that’s a different story… ATSOps can’t give you this information anyway. Using getclassinstances you can’t collect bitmaps… So the only way is to collect bitmap files by node using enumerateFiles, and search the files in the node’s properties.

 JHN

This is a somewhat related snippet of code for repathing an asset. I can’t take credit for this, I got it from Larry Minton. It might be of use to someone.



gc() -- just for this example, to make sure everything is nice and clean

-- find the scene root. The rootnode, medit, etc are references off this scene root
sceneroot = (for r in (refs.dependents rootnode) where (classof r == Scene) collect r)[1]

-- collect all the assets
origAssets = for i = 1 to AssetManager.GetNumAssets() collect (AssetManager.GetAssetByIndex i)

-- for each of the assets...
for AUIO in origAssets do
(
	-- dump info on the asset
	local AID = AUIO.GetAssetId() --get the Asset’s ID
	local AType = AUIO.getType() --get the Asset’s Type
	local AFile = AUIO.getfilename() --get the Asset’s File Name
	format "ID:% Type:% File:%
" AID AType AFile --format the info
	-- generate new filename, prepend "XXXX_"
	local lFile = filenameFromPath AFile
	local lPath = getFileNamePath AFile
	local lNewName = lPath + "\\" + "XXXX_" + lFile
	-- do the retargetting
	atsops.RetargetAssets sceneroot AFile lNewName CreateOutputFolder:false
)

It will repath the assets so be sure to save first.

-Johan

Thanks for the help everyone.
I went with the enumerateFiles which proved to be a very simple way to do it.