--Bitmap Network Share 1.4 Final
--date:7/25/2001
--Written By Zhang Yang

--function:
--Did you ever be troubled by change your local map path to network map path one by one before you want to network rendering?
--Ok your nightmare ended! use this one-click tool and have a rest.
--network name also called UNC(Universal Naming Convention).
--Requirement:3ds max4
--contact:yang.zhang@autodesk.com



--Init Var
--sysinfo

machineName=sysInfo.computername
userName=sysInfo.username

--shareMapLib=#()
sharedMapCount=0

debug=createFile "c:/temp/debug.log"

--get inter string function
--function usage: interString <string> <string(begin)> <string(end)> <string(end2)>
fn interString wholeString startString endString endStringSnd=
(	
	startPos=findstring wholeString startString
	if startPos==undefined do return(undefined)
	wholeString=substring wholeString startPos -1
	endPos=findstring wholeString endString
	endPosSnd=findstring wholeString endStringSnd
	if endPos==undefined then endPos=-1
		else endPos=endPos-1
	if endPosSnd==undefined then endPosSnd=0
		else
			if (endPosSnd-1)<endPos or endPos==-1 do endPos=endPosSnd-1
	finalString=substring wholeString 1 endPos
	return (finalString)
)

--check and chang bitpmap path function
fn bitmapDetect mapName=
(
	        if (classof mapName)==Bitmaptexture then
				(	
					print "Processing detected bitmap........." to:debug
					if (substring mapName.filename 1 2)=="\\"+"\\" do return(true)
					print mapName.filename to:debug
					print pathNameDiv to:debug
					pathNameDiv=filterString mapName.filename ":"
					mapName.filename="\\"+"\\"+machineName+"\\" + pathNameDiv[1]+ pathNameDiv[2]
					print mapName.filename to:debug
					sharedMapCount=sharedMapCount+1
					return (true)
				)
			else
				return(false)
)

--following code idea part from "map_path_editor" which written by Jaroslaw Marcin's recursive function but enforced.
--main function
fn changeMaps item = (
		
		--exclude all other type of value except materials and texturemap
		if superclassof(item)!=material and superclassof(item)!=textureMap and classof(item)!=ArrayParameter do return()

		--processing Array type. mainly for multi/sub and blend materials
		--if classof(item)== ArrayParameter do
		--(	
		--	print "Processing Array Type" to:debug
		--	for aaProp in item do
		--	(	
		--		print aaProp to:debug
		--		flush debug
		--		changeMaps aaProp
		--	)
		--	return()
		--)
		

		--detect whether the current map is bitmap
		if bitmapDetect(item) do return()
		
		print "Processing properties table" to:debug
		--get all the properties in the material or texturemap
		--try (
				props=#()
				propsTable=stringStream ""
				showProperties item to:propsTable
				seek propsTable 1
				print "property table start:========" to:debug
				--collect props
				while (not eof propsTable) do
					(	
						appendString=interString (readline propsTable) "." " " "("
						print appendString to:debug
						if appendString==undefined do print "no bitmap property finded" to:debug
						
						append props appendString
					)
				
				print "property table end:========" to:debug
	     --) catch (return undefined)
		 
		print props.count to:debug
		--searching under the material or texturemap for bitmap
		for aProp in props do
		(   	
				print aProp to:debug
				newItem=item
                aProp="newItem"+aProp
				aProp=execute aProp
				print (classof aProp) to:debug
				print aProp to:debug
				print "\n" to:debug
				flush debug
				changeMaps aProp
		)
)
--end of recursive function

fn mapShare =
(	
	for proMat in sceneMaterials do
	(
		print proMat.name to:debug
		changeMaps proMat
		
	)
	stringCollect="Finish!Total "+ sharedMapCount as string +" Maps have been Shared."
	messageBox stringCollect

)

--Create Interface
Utility mapShareUti "Network Map Sharer" rolledUp:true
( 
 
    rollout aboutMapShare "About NetMapSharer"
    (
         label lab1 "NetMapSharer 1.2 Alpha" 
         label lab2 "Written By Snow"
         --bitmap the_bmp bitmap:icon_Snow3D
         label lab3 "Home http://zsnow.yeah.net"
         label lab4 "Email: yang.zhang@autodesk.com"
         label lab5 "discreet China AE. Nov,2000"
     )
    rollout MainParament "SysInfo"
    (
		 label lab6 "MachName:" align:#left
		 label lab8 "UserName:" align:#left
		 button shareb "ShareMap"
		 on shareb pressed do
		 (
		 	lab6.text="MachName:"+machineName
			lab8.text="UserName:"+userName
			--init var
			sharedMapCount=0
			mapShare()
		 )
	)
	
	 on mapShareUti open do
	 (	
		addRollout aboutMapShare
		addRollout MainParament
	 ) 

  	 --close Rollout
 	 on mapShareUti close do
  	 (  
   	   	removeRollout aboutMapShare
        removeRollout MainParament
      )   

)