Mass Project sound file change?

General discussion about 3D DCC and other topics
User avatar
Shredder565
Posts: 1062
Joined: 02 Jan 2012, 20:04

Mass Project sound file change?

Post by Shredder565 » 20 Jan 2019, 19:39

I have projects with 360 scenes, and a sound file from a wav file in each one.

occasionally, I willl re-organize my folders, and all those sound files will be dead weight until I manually go into each project and update the link.

is there anyway to update them all at once? when i feel like doing it mannually, going through all 360 project files takes forever and is really boring :)

benmalartre
Posts: 10
Joined: 14 Jan 2014, 10:45
Location: clermont-ferrand france

Re: Mass Project sound file change?

Post by benmalartre » 20 Jan 2019, 21:39

Hello, I think it's time to dive into scripting!

you can edit the .scntoc associated with your .scn files

Code: Select all

import xml.etree.ElementTree as ET

to_replace = "pattern_to_replace"
replace_by = "new_pattern"

scenetoc = "E:\\Projects\\Softimage\\Procedural\\Scenes\\AudioTest\\AudioTest.scntoc"

# load and parse scenetoc
tree = ET.parse(scenetoc)
root = tree.getroot()

# find audio sources and update content
for src in root.findall('Sources'):
	for audio in src.findall('Audio'):
		old_value = audio.text
		new_value = old_value.replace(to_replace, replace_by)
		audio.text = new_value

# save scene toc 
tree.write(scenetoc)
or you can open your scenes in batch mode also using a script
see here :
http://download.autodesk.com/global/doc ... =d30e87012

here is some python code to find and update audio source filename

Code: Select all

# we assume that there is a pattern in your re-organisation
# for exemple you renamed the project or moved it to a new disk

to_replace = "pattern_to_replace"
replace_by = "new_pattern"

def FindAudioClipsUnderModel( in_model ) :
	if  in_model.HasMixer()== 0 :
		return []
	mixer = in_model.Mixer

	audioclips = []
	if mixer.Clips.Count > 0 :
		for clip in mixer.Clips :
			if clip.Type == "mixeraudioclip":
				audioclips.append(clip)
	return audioclips
	
audioclips = FindAudioClipsUnderModel( Application.ActiveSceneRoot )
for clip in audioclips:
	source = clip.Source
	old_value = source.FileName.Value
	new_value = old_value.replace(to_replace, replace_by)
	
	# source.FileName.Value = new_value 
	# object model not working here
	# use command instead
	Application.SetValue(source.FileName, new_value, "")

Application.SaveScene()