PDA

View Full Version : Strip all usedMaps() paths


kamel47
05-28-2008, 02:47 AM
Hi Guys,
I try to write a script which will strip and clean all paths in the scene. Including texture, Xref, proxies, HDRI, etc. I can very easy collect all paths in the scene using:maps_in_scene = usedMaps()
print maps_in_scene

"D:\WORK\08 03 20\reflection_city.jpg"
"D:\WORK\08 03 20\city.vrmesh"
"C:\scenes\temp.max" but is there a way to strip them at once without divide them per classes?
Thank you

erilaz
05-28-2008, 03:12 AM
Do you specifically want to strip the paths and only have the filenames remaining, or just clear all the paths completely?

kamel47
05-28-2008, 03:25 AM
Yes I want completly to clean the paths:

"\reflection_city.jpg"
"\city.vrmesh"
"\temp.max"

erilaz
05-28-2008, 03:30 AM
You can use either the filenamefrompath method or pathConfig.stripPathToLeaf. Both pretty much do the same thing.

Zbuffer
05-28-2008, 07:37 AM
Hi, for bitmaps, you can use:

for m in getClassInstances BitmapTexture do (m.fileName=filenameFromPath m.fileName)

kamel47
05-28-2008, 12:03 PM
Thanks for reply guys. Thank you Zbuffer. Yes I can do for Textures:for m in getClassInstances BitmapTexture do
(
m.fileName=filenameFromPath m.fileName
) for Vray proxies:for m in getClassInstances vrayproxy do
(
m.fileName=filenameFromPath m.fileName
) But my question is there a sigle class or code for all external resuorces?

ZeBoxx2
05-28-2008, 12:23 PM
nope - although IIRC there's some bits and pieces to get at external resource paths, there's no way to relate those back to a reference in 3ds Max in order to change it.

Your best bet is to traverse the entire scene (remember, getClassInstances does -not- actually return all instances of that class; though it will get most) and run over parameters to see if it is a (potential) filename string, then change from there.

Traversing a scene is .. frustrating, to say the least. Things like Scene States didn't particularly make it any easier either :)

If you -can- get by with getClassInstances and a few choice classes, then that's the way to go.

Edit: Last tab I opened a few minutes ago has some good reads on the scene traversal stuff: http://forums.cgsociety.org/showthread.php?f=98&t=527443 ; See also Neil Blevins' scripts, his lib has some traversal functionality that you could make use of.

PiXeL_MoNKeY
05-28-2008, 05:14 PM
Use ATSOps, since you have access to all files (input and output) you can handle most of it there. It should also store stuff in various Scene States, environment maps, etc.fileArray = #()
ATSOps.Refresh()
ATSOps.GetFiles &fileArray --collect all scene files and paths
deleteItem fileArray 1 --remove the actual scene file path
for infile in fileArray.count to 1 by -1 do ( --remove output file paths
if ATSOps.IsInputFile fileArray[infile] != true do (
deleteItem fileArray infile
)
)
ATSOps.SelectFiles &fileArray --select files for path stripping
ATSOps.SetPathOnSelection "" --set path to whatever you wantThis should do what you want,
-Eric

Edit: Added ATSOps.Refresh() to force a refresh of the data.

ZeBoxx2
05-28-2008, 07:12 PM
Use ATSOps [...] This should do what you want

It's the "should" par that always makes me twitch.

3ds Max 2009, 32-bit. File > Reset


-- Let's create a sphere and stick a bitmapped material on the thing.
myObj = Sphere()
myObj.material = Standard()
myObj.material.diffusemap = BitmapTexture()
myObj.material.diffusemap.filename = "c:\\temp\\test.bmp"

-- now let's see what ATSOps says
fileArray = #()
ATSOps.GetFiles &fileArray --collect all scene files and paths
print fileArray
"glare_streaks_star_camera_filter.tif"

-- Well that's not quite right; we'll ignore the mental ray filter thing. But turns out that ATSOps only works properly after the file has been saved; or ATS needs to be Refreshed? The help file only mentions refreshing a dialog, unfortunately.
saveMaxFile "c:\\temp\\test.max"
fileArray = #()
ATSOps.GetFiles &fileArray --collect all scene files and paths
print fileArray
"c:\temp\test.max"
"glare_streaks_star_camera_filter.tif"
"c:\temp\test.bmp"

-- Much better. So now let's change the path of these..
ATSOps.SelectFiles &fileArray
ATSOps.SetPathOnSelection "C:\\Documents and Settings\\My Username\\My Documents\\3dsmax\\sceneassets\\"
false

-- false? Whoops. Perhaps it doesn't like some file in there, but we can't tell which. Perhaps the max file because it's in use, perhaps the filter thing. So let's try with just our bitmap.

newArray = #(fileArray[3])
ATSOps.SelectFiles &newArray
ATSOps.SetPathOnSelection "C:\\Documents and Settings\\My Username\\My Documents\\3dsmax\\sceneassets\\"
false

-- still false. What gives?
ATSOps.SelectFiles &fileArray
ATSOps.numFilesSelected()
0

-- right-o.


Probably missing something obvious, but what?

PiXeL_MoNKeY
05-28-2008, 09:02 PM
You are missing:deleteItem fileArray 1 --remove the actual scene file pathNotice that the first entry is the actual scene file path, this can't be changed, and also disables the ability to set path on any other files. Same thing happens in the dialog if you select the scene at the top of the list. You may also need to call ATSOps.Refresh(), this updates the list.
-- Let's create a sphere and stick a bitmapped material on the thing.
myObj = Sphere()
myObj.material = Standard()
myObj.material.diffusemap = BitmapTexture()
myObj.material.diffusemap.filename = "c:\\temp\\test.bmp"

-- now let's see what ATSOps says
fileArray = #()
ATSOps.Refresh() -- refresh the ATSOps list
ATSOps.GetFiles &fileArray --collect all scene files and paths
print fileArray

1
"c:\temp\test.bmp"-Eric

ZeBoxx2
05-28-2008, 11:02 PM
Okay, so when I used this code... (note the comment addressing what you just mentioned)


-- false? Whoops. Perhaps it doesn't like some file in there, but we can't tell which. Perhaps the max file because it's in use, perhaps the filter thing. So let's try with just our bitmap.
newArray = #(fileArray[3])
ATSOps.SelectFiles &newArray
ATSOps.SetPathOnSelection "C:\\Documents and Settings\\My Username\\My Documents\\3dsmax\\sceneassets\\"
false

-- still false. What gives?
ATSOps.SelectFiles &fileArray
ATSOps.numFilesSelected()
0


What happened, other than -not- selecting the third item in the original array?
I take it you need the refresh; which the help states refreshes a dialog (which to me would imply it makes sure a GUI element gets updated to reflect the internal state) but I guess would actually mean "make sure the internal state actually -is- what you just told it to be"?

Let's try the original example (with your added refresh) and add some prints and refreshes... I'll give output per line.

fileArray = #()
#()
ATSOps.Refresh()
OK
ATSOps.GetFiles &fileArray --collect all scene files and paths
2
deleteItem fileArray 1 --remove the actual scene file path
#("c:\temp\test.bmp")
for infile in fileArray.count to 1 by -1 do ( --remove output file paths
if ATSOps.IsInputFile fileArray[infile] != true do (
deleteItem fileArray infile
)
)
OK
fileArray
#("c:\temp\test.bmp")
ATSOps.SelectFiles &fileArray --select files for path stripping
OK
ATSOps.SetPathOnSelection "c:\\temp2\\" --this path exists.
false -- hmm?
ATSOps.numFilesSelected()
0 -- ah?
fileArray
#("c:\temp\test.bmp") -- okay, it's still there.
ATSOps.SelectFiles &fileArray --select files for path stripping
OK -- should be selected, no?
ATSOps.numFilesSelected()
0 -- I guess not.
ATSOps.Refresh()
OK -- refreshed
ATSOps.numFilesSelected()
0 -- nope


Is it just me?

kamel47
05-28-2008, 11:38 PM
Thanks for this code PiXeL_MoNKeY but it really works partially. It does strip the path of the bitmaps and HDRIs but doesn't with proxies, point chashe, xref (it change the path of the first one only)
Please have a look at the print screen of the AT after I run the script. Green - it did. Red - it didn't.
http://www.artray.co.uk/temp_for_forums/assettrack.gif

PiXeL_MoNKeY
05-28-2008, 11:42 PM
Ill look at it later, but the script I posted worked on a file with 180 files, and stripped the path of 178 files (the other being an output path and the actual scene file that is open). When I ran it I had the ATS dialog open, which may be the difference.

-Eric

PiXeL_MoNKeY
05-28-2008, 11:44 PM
kamel47, you may try removing the IsInputFile check. As Richard stated in another thread the file can give a false negative if the file can be an input and output file.

-Eric

Edit: If you literally want everything to have its path stripped try just this one line:ATSOps.SetPath ""

ZeBoxx2
05-29-2008, 12:27 AM
When I ran it I had the ATS dialog open, which may be the difference.

:lightbulb Turns out that it is. So..

ATSOps.visible = true
-- work with the bugger
ATSOps.visible = false


Next up, change the path in one map, but not in another ;)

kamel47
05-29-2008, 12:51 AM
PiXeL_MoNKeY I did try ATSOps.SetPath "" but still I had the same rezolt. Only one of the Xrefs was stripped.

PiXeL_MoNKeY
05-29-2008, 03:22 PM
I have no idea what is going on, kinda hard to diagnose without having a scene that exhibits the problems you are seeing. Did you run the Maxscript commands with the dialog open or closed? Did you also call ATSOps.Refresh() to refresh the list?

-Eric

kamel47
05-29-2008, 04:13 PM
It is very strage. Works fine on my workstation 32 and 64bit, but on laptop or low spec machine dosen't.

PiXeL_MoNKeY
05-29-2008, 05:37 PM
It appears that you need to have the dialog open for some of the maxscript ATSOps commands to work. So try something like:ATSOps.visible = true
ATSOps.Refresh()
ATSOps.SetPath ""
ATSOps.visible = falseNext up, change the path in one map, but not in another ;)That should just be a matter of extracting the paths from the filelist array and running ATSOps.SetPathOnSelection "NewPath" on the desired path(s).

-Eric

ZeBoxx2
05-30-2008, 03:03 AM
That should just be a matter of extracting the paths from the filelist array and running ATSOps.SetPathOnSelection "NewPath" on the desired path(s).

I was just being difficult - and not clear enough at that :)

If you have two maps, both pointing to "c:\temp\test.bmp", and you want to change the path for just one of those two maps, would have been the challenge.
The asset tracker just sees it as a single asset, and you can't get what's actually referencing that asset out of it.

And yes, I know, .RetargetAssets :) That only helps if you already know which MaxObject you want to poke at, though.

CGTalk Moderation
05-30-2008, 03:03 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.