Replace path prefix with predefined words

I have a bunch of fileservers of different locations which can be accessed over internet \\f1 \\f2 \\f3 (all of them are mirrored folderstructure). I want to repath all of them to a drive instead of a network path when I run a maxscript. As it takes a huge amount of data to read all textures over the vpn network.

Lets say I have textures in this folder \\f1\resources\textures and want to replace the prefix \\f1\resources\ to A:\ like this

oldPrefix1 = “\\f1\resources\, \\f2\resources\, \\f3\resources\”
newPrefix1 = “A:\”
oldPrefix2 = “\\f1\projects\, \\f2\projects\, \\f3\projects\”
newPrefix2 = “B:\”
etc

Is this possible with an easy ATSOps script (tried but couldnt get it to work) or any other kind of script? We usually do the same operation but with Interactive renamer or relink bitmaps but its allways the same path that needs to be replaced so I would be easier to have one script the replaces the "prefix" of the full path every time

Comments

Comment viewing options

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

Use substituteString

(
	fn change_path old_path old_prefixes new_prefix =
	(
		local new_path = old_path
 
		for prefix in old_prefixes do
		(
			new_path = substituteString new_path prefix new_prefix
		)
 
		new_path
	)
 
	old_prefixes = #("\\\\f1\\resources\\", "\\\\f3\\resources\\", "\\\\f2\\resources\\")
	new_prefix = "A:\\"
 
	the_path_to_change1 = "\\\\f1\\resources\\path1\\"
	the_path_to_change2 = "\\\\f2\\resources\\path2\\bla"
 
	new_path1 = change_path the_path_to_change1 old_prefixes new_prefix
	new_path2 = change_path the_path_to_change2 old_prefixes new_prefix
 
	print new_path1
	print new_path2
)

A prettier way would be to use RegEx...

swatchmate's picture

Thank you, I missed that

Thank you, I missed that somebody had commented on this thread :/.

I replaced all "\\\\" to our network config to our network configuration and run the function but the only thing that happens is that it prints the new_prefix in the max script listener but the texture itself in this case doesn't rename the prefix to the new path.
A:\
A:\
A:\

I tried to add the follow ATSOps before and after to retarget the prefix on one textures but it only ends up changing the full texture name into A:\ instead of ex A:\textures\eye.jpg

assets = #()
 
ATSOps.Visible = true
ATSOps.Refresh()
ATSOps.GetFiles &assets
 
for asset in assets do
(
(
	fn change_path old_path old_prefixes new_prefix =
	(
		local new_path = old_path
 
		for prefix in old_prefixes do
		(
			new_path = substituteString new_path prefix new_prefix
		)
 
		new_path
	)
 
	old_prefixes = #("\\\\f1\\resources\\", "\\\\f2\\resources\\", "\\\\f3\\resources\\")
	new_prefix = "A:\\"
 
	the_path_to_change1 = "\\\\f1\\resources\\"
	the_path_to_change2 = "\\\\f2\\resources\\"
 
	new_path1 = change_path the_path_to_change1 old_prefixes new_prefix
	new_path2 = change_path the_path_to_change2 old_prefixes new_prefix
 
	print new_path1
	print new_path2
)
ATSOps.ClearSelection()
ATSOps.SelectFiles #(asset)
ATSOps.RetargetSelection new_path1
)
ATSOps.Refresh()

Comment viewing options

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