⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rename.ms

📁 3DSMAX中物体的指重命名脚本
💻 MS
字号:
/* 	Script:		newRenamer.ms
	Written by: 	Alec Fredericks 
	Date:			Sept. 21, 2008
	Description: 	An object renaming rollout to replace the ugly one that comes with Max.
					I know a lot of people will be hurt by me calling Max's base rename script
					"ugly" but I come from the Maya realm and am used to the excellent renaming
					script originally written by Michael Comet.  This MXS version is both an
					homage, as well as an attempt to begin improving my Max workflow from the
					very beginning of my Max adventures.
					Right now, the script is just an executable, but I'd like to find a way to replace
					Max's native rename script with my own.  Once I do that, I'll make modifications
					that will allow the script to embed itself in the appropriate location for such
					behavior to be added.
	To Do:			If I get any feedback, I'll make needed modifications.  I'm guessing people
					might like to have the remove N character from the front and end of a name.
					I honestly don't see the need for it yet, but as MXS regex doesn't exist in
					the base package, I might need to add it for my own use. */
			
MacroScript RenameObjects
enabledIn:#("max", "viz")
	category:"Tools"
	internalCategory:"Tools"
	tooltip:"Rename Objects..."
	buttontext:"Rename Objects..."
(
	function getSelected = 
	(
		sel = selection as array
	)

	try(destroyDialog newRename_rollout)catch()
	rollout newRename_rollout "Object Renamer"
	(

		
		group "Options"
		(
			label objects_label "Apply To:" width:50 align:#left
			radiobuttons objects_radioButtons labels:#("All", "Selected") default:2 align:#right offset:[-30,-18]
		)
		group "Search and Replace"
		(
			editText search_editText "Search:  " offset:[3,1] align:"right"
			editText replace_editText "Replace:" offset:[3,1] align:"right"
			button searchReplace_button "Search & Replace" width:230
		)
		group "Prefix"
		(
			editText prefix_editText "" align:"right" width:155
			button prefix_button "Add Prefix" align:"right" offset:[85,-23]
		)

		group "Suffix"
		(
			editText suffix_editText "" align:"right" width:155
			button suffix_button "Add Suffix" align:"right" offset:[85,-23]
		)
		
		group "Rename"
		(
			editText baseName_editText "Base Name:        " align:"right" width:224
			checkbox numbering_checkbox "Numbering" width:75 checked:true
			spinner startingNumber_spinner "Start#:" align:#left width:55 type:#integer range:[0,1000,1] offset:[75,-20]
			spinner padding_spinner "Pad  :" align:#left width:55 offset:[162,-22] type:#integer range:[0,10,1]
			button newRename_button "Rename" width:230
		)
		
		group "Delete Characters"
		(
			spinner startChar_spinner "Start:" align:#left width:50 type:#integer range:[-10,100,1]
			label arrow_label "->" width:20 align:#left offset:[69,-22]
			spinner endChar_spinner "End:" align:#left width:50 type:#integer range:[1,100,3] offset:[80,-17]
			checkbox endOfWord_checkbox "End Of Word" width:95 offset:[155,-20]
			button deleteChar_button "Delete Characters" width:230
		)
		
		
		-- APPLY TO
		on objects_radioButtons changed objectsState do with undo on
		(
			applyTo = objectsState
			lastSelection = #()
			newSelection = getSelected()
			
			lastSelection = selection as array

			if applyTo == 1 then
			(
				newSelection = objects as array
				select(lastSelection)
			)	else if applyTo == 2 then
					newSelection = getSelected()
		)
		
		-- SEARCH & REPLACE
		on searchReplace_button pressed do with undo on
		(
			newSelection = getSelected()
			
			obj = ""	-- object receiving the name modification

			s = search_editText.text
			r = replace_editText.text	
			searchPattern = ""

			if s == "" then
			(
				messagebox "Nothing in the \"Search\" box.  \nPlease type something into that field.\n" title:"Object Renamer: ERROR"
			)	else
				(
					searchPattern = "*"+s+"*"
					for obj in newSelection do
					(
						if (matchPattern obj.name pattern:searchPattern) then
							obj.name = substituteString obj.name sr
					)
				)

		)
		
		-- PREFIX
		on prefix_button pressed do with undo on
		(
			newSelection = getSelected()
			
			obj = ""	-- object receiving the name modification
			
			prefix = prefix_editText.text
			
			if prefix != "" then
			(
				for obj in newSelection do
					obj.name = prefix + obj.name
			)
			
		)
		
		-- SUFFIX
		on suffix_button pressed do with undo on
		(
			newSelection = getSelected()
			
			obj = ""	-- object receiving the name modification
			
			suffix = suffix_editText.text
			
			if suffix != "" then
			(
				for obj in newSelection do
					obj.name = obj.name + suffix
			)
		)
	
		
			
		-- NUMBERING ON/OFF
		on numbering_checkbox changed numState do
		(
			-- get the state of the numbering spinners
			if numState == false then
			(
				startingNumber_spinner.enabled = false
				padding_spinner.enabled = false
			) else
				(
					startingNumber_spinner.enabled = true
					padding_spinner.enabled = true
				)
		)
		
		on newRename_button pressed do with undo on
		(
			newSelection = getSelected()
			
			obj = ""
			startStr = ""
			startNum = 0
			base = baseName_editText.text
			
			startNum = startingNumber_spinner.value

			startStr = startNum as string
			pad = padding_spinner.value
			startLength = startStr.count
			
			for obj in newSelection do
			(
				if base == "" then
					base = obj.name
				if numbering_checkbox.checked == true then
				(
					zeroes = ""
					startStr = startNum as string
					startLength = startStr.count
					addPad = startLength-pad
					
					for i=startLength to (pad-1) do
						zeroes += "0"
				
					obj.name = base+zeroes+startStr
					
					startNum += 1
				) else
					obj.name = base
				
			)
		)
		
		on endOfWord_checkbox changed chkVal do
		(
			if (chkVal) then
				endChar_spinner.enabled = false
			else
				endChar_spinner.enabled = true
		)
		
		on deleteChar_button pressed do with undo on
		(
			newSelection = getSelected()

			startVal = startChar_spinner.value
			endVal = endChar_spinner.value
			
			obj = ""
			
			for obj in newSelection do
			(
				if endOfWord_checkbox.checked then
				(
					endVal = obj.name.count
					obj.name = replace obj.name ((endVal+1)-startVal) startVal ""
				)	else				
						obj.name = replace obj.name startVal ((endVal-startVal)+1) ""
			)
		)
	)
	createDialog newRename_rollout height:420 width:260
)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -