Notifications
Clear all

[Closed] File Size issue

well, that just a script that export the scene to a new one using 3ds file format, but I added support for materialID, smootinggroup, object groupping, and light include\exclude list…it doesn’t get rid of the problem from the original file at all.

could you tell me where it crash ?


MAXScript Rollout Handler Exception

– Runtime error: dotNet runtime exception: Object of type ‘System.Int32’ cannot be converted to type ‘System.Decimal’.

OK

        2:(
            for f in 1 to (polyop.getNumFaces Fobj) do
                (
                XWriter.WriteLine(polyop.getFaceMatID Fobj f)
                YWriter.WriteLine(polyop.getFaceSmoothGroup Fobj f)
                )
            )
        )

sorry, my mistake

I just updated it for max2008, I don’t have it to test it , but it should work, I guest…


 /*

Title : Scene Cleaner v0.51
Author : Martin Dufour
Web : martroyx.890m.com
Email : martroyx@hotmail.com

know limitation :

-Don't export light animation
-Don't export skylight
-Don't export mentalraylight
-Some light property may not export correctly

*/

try (destroydialog Xcleaner) catch ()
(
if (heapsize<64000000L) do (heapsize=64000000L)
--//--
Global Xcleaner
local Xversion="Scene Cleaner v0.51"
local Xfolder=(getdir #scripts + "\\SceneFix") ; makedir Xfolder
local Xpath=undefined
local OriginalName=#()
local ModifiedName=#()
local MaterialList=#()
local WirecolorList=#()
local ClassList=#()
local ScriptedObject=#()
--//--
struct CleanUtil (
	--//--
	fn Write Fpath Fobj Ftype =
		(
		XWriter=(dotnetobject "System.IO.StreamWriter" (Fpath+".Xid") true)
		YWriter=(dotnetobject "System.IO.StreamWriter" (Fpath+".Xsm") true)
		--//--
		case Ftype of
			(
			1:(
				for f in 1 to (getNumFaces Fobj) do
					(
					XWriter.WriteLine(dotnetobject "system.int32" (getFaceMatID Fobj f))
					YWriter.WriteLine(dotnetobject "system.int32" (getFaceSmoothGroup Fobj f))
					)
				)
			--//--
			2:(
				for f in 1 to (polyop.getNumFaces Fobj) do
					(
					XWriter.WriteLine(polyop.getFaceMatID Fobj (dotnetobject "System.Int32" f))
					YWriter.WriteLine(polyop.getFaceSmoothGroup Fobj (dotnetobject "System.Int32" f))
					)
				)
			)
		--//--
		XWriter.close()
		YWriter.close()
		XWriter.dispose()
		YWriter.dispose()
		),
	--//--
	fn Read Fpath Fobj Ftype =
		(
		XReader=(dotnetobject "System.IO.StreamReader" (Fpath+".Xid"))
		YReader=(dotnetobject "System.IO.StreamReader" (Fpath+".Xsm"))
		--//--
		case Ftype of
			(
			1:(
				for f in 1 to (getNumFaces Fobj) where (not XReader.EndOfStream) do
					(
					setFaceMatID Fobj f (XReader.ReadLine() as integer)
					setFaceSmoothGroup Fobj f (YReader.ReadLine() as integer)
					)
				)
			--//--
			2:(
				for f in 1 to (polyop.getNumFaces Fobj) where (not XReader.EndOfStream) do
					(
					polyop.setFaceMatID Fobj f (XReader.ReadLine() as integer)
					polyop.setFaceSmoothGroup Fobj f (YReader.ReadLine() as integer)
					)
				)
			)
		--//--
		XReader.close()
		YReader.close()
		XReader.dispose()
		YReader.dispose()
		),
	--//--
	fn WriteLight Fpath Fobj =
		(
		XWriter=(dotnetobject "System.IO.StreamWriter" (Fpath+".XLg"))
		--//--
		NodeStr="#("
		--//--
		if Fobj.excludeList != undefined and Fobj.excludeList.count != 0 then 
			(
			for f in 1 to Fobj.excludeList.count do
				(
				NodeStr += ("$"+OriginalName[(Fobj.excludeList[f].name as integer)])
				if f != Fobj.excludeList.count then NodeStr += ","
				)
			)
		--//--
		NodeStr += ")"
		XWriter.WriteLine(NodeStr)
		--//--
		--//--
		NodeStr="#("
		--//--
		if Fobj.includeList != undefined and Fobj.includeList.count != 0 then 
			(
			for f in 1 to Fobj.includeList.count do
				(
				NodeStr += ("$"+OriginalName[(Fobj.includeList[f].name as integer)])
				if f != Fobj.includeList.count then NodeStr += ","
				)
			)
		--//--
		NodeStr += ")"
		XWriter.WriteLine(NodeStr)
		--//--
		XWriter.WriteLine(Fobj.inclExclType as string)
		--//--
		XWriter.close()
		XWriter.dispose()
		),
	--//--
	fn ReadLight Fpath Fobj =
		(
		XReader=(dotnetobject "System.IO.StreamReader" (Fpath+".XLg"))
		--//--
		x=(execute (XReader.ReadLine()))
		if x.count != 0 then (Fobj.excludeList = x)
		--//--
		 y=(execute (XReader.ReadLine()))
		 if y.count != 0 then (Fobj.includeList = y)
		--//--
		z=(execute (XReader.ReadLine()))
		Fobj.inclExclType = z
		--//--
		Fobj.wirecolor = (color 255 229 0)
		--//--
		XReader.close()
		XReader.dispose()
		),
	--//--
	fn ExportLight Fpath Fobj Fclass =
		(
		XWriter=(dotnetobject "System.IO.StreamWriter" (Fpath+".ms"))
		--//--
		XWriter.WriteLine("(")
		--//--
		if Fobj.target != undefined then
			(
			XWriter.WriteLine("NewLight = "+(Fclass as string)+" target:(targetObject())")
			XWriter.WriteLine("NewLight.target.transform = "+(Fobj.target.transform as string))
			XWriter.WriteLine("NewLight.target.name = \""+OriginalName[(Fobj.name as integer)]+".target"+"\"")
			)
		else
			(
			XWriter.WriteLine("NewLight = "+(Fclass as string)+"()")
			)
		--//--
		XWriter.WriteLine("NewLight.name = \""+(Fobj.name)+"\"")
		XWriter.WriteLine("NewLight.transform = "+(Fobj.transform as string))		
		--//--
		if (hasProperty Fobj "enabled") then XWriter.WriteLine("NewLight.enabled= "+(Fobj.enabled as string))
		if (hasProperty Fobj "castShadows") then XWriter.WriteLine("NewLight.castShadows= "+(Fobj.castShadows as string)) 
		if (hasProperty Fobj "rgb") then XWriter.WriteLine("NewLight.rgb= "+(Fobj.rgb as string))
		if (hasProperty Fobj "hsv") then XWriter.WriteLine("NewLight.hsv= "+(Fobj.hsv as string)) 
		if (hasProperty Fobj "hue") then XWriter.WriteLine("NewLight.hue= "+(Fobj.hue as string))
		if (hasProperty Fobj "saturation") then XWriter.WriteLine("NewLight.saturation= "+(Fobj.saturation as string)) 
		if (hasProperty Fobj "value") then XWriter.WriteLine("NewLight.value= "+(Fobj.value as string))
		if (hasProperty Fobj "multiplier") then XWriter.WriteLine("NewLight.multiplier= "+(Fobj.multiplier as string))
		if (hasProperty Fobj "contrast") then XWriter.WriteLine("NewLight.contrast= "+(Fobj.contrast as string))
		if (hasProperty Fobj "softenDiffuseEdge") then XWriter.WriteLine("NewLight.softenDiffuseEdge= "+(Fobj.softenDiffuseEdge as string))
		if (hasProperty Fobj "affectDiffuse") then XWriter.WriteLine("NewLight.affectDiffuse= "+(Fobj.affectDiffuse as string))
		if (hasProperty Fobj "affectSpecular") then XWriter.WriteLine("NewLight.affectSpecular= "+(Fobj.affectSpecular as string))
		if (hasProperty Fobj "ambientOnly") then XWriter.WriteLine("NewLight.ambientOnly= "+(Fobj.ambientOnly as string))
		if (hasProperty Fobj "nearAttenStart") then XWriter.WriteLine("NewLight.nearAttenStart= "+(Fobj.nearAttenStart as string))
		if (hasProperty Fobj "nearAttenEnd") then XWriter.WriteLine("NewLight.nearAttenEnd= "+(Fobj.nearAttenEnd as string))
		if (hasProperty Fobj "useNearAtten") then XWriter.WriteLine("NewLight.useNearAtten= "+(Fobj.useNearAtten as string)) 
		if (hasProperty Fobj "showNearAtten") then XWriter.WriteLine("NewLight.showNearAtten= "+(Fobj.showNearAtten as string)) 
		if (hasProperty Fobj "farAttenStart") then XWriter.WriteLine("NewLight.farAttenStart= "+(Fobj.farAttenStart as string)) 
		if (hasProperty Fobj "farAttenEnd") then XWriter.WriteLine("NewLight.farAttenEnd= "+(Fobj.farAttenEnd as string)) 
		if (hasProperty Fobj "useFarAtten") then XWriter.WriteLine("NewLight.useFarAtten= "+(Fobj.useFarAtten as string)) 
		if (hasProperty Fobj "showFarAtten") then XWriter.WriteLine("NewLight.showFarAtten= "+(Fobj.showFarAtten as string)) 
		if (hasProperty Fobj "attenDecay") then XWriter.WriteLine("NewLight.attenDecay= "+(Fobj.attenDecay as string))
		if (hasProperty Fobj "DecayRadius") then XWriter.WriteLine("NewLight.DecayRadius= "+(Fobj.DecayRadius as string))
		if (hasProperty Fobj "useGlobalShadowSettings") then XWriter.WriteLine("NewLight.useGlobalShadowSettings= "+(Fobj.useGlobalShadowSettings as string))
		--//--
		XWriter.WriteLine(")")
		XWriter.close()
		XWriter.dispose()
		),
	--//--
	fn ExportSceneState Fpath =
		(
		XWriter=(dotnetobject "System.IO.StreamWriter" Fpath)	
		--//--
		XWriter.WriteLine("(")
		--//--
		MidChild=#()
		MidChildName=#()
		ChildA=#()
		ChildB=#()
		--//--
		for f in objects where (isGroupHead f) and (f.parent != undefined) do 
			(
			ValidSubChild=true
			--//--
			for i in 1 to f.children.count do 
				(
				if (isGroupHead f.children[i]) then ValidSubChild=false
				)
			--//--
			if ValidSubChild==true then
				(
				NewChild="#("
				--//--
				for i in 1 to f.children.count do 
					(
					NewChild += ("$"+f.children[i].name)
					if i != f.children.count then (NewChild += ",") else (NewChild += ")")
					)
				--//--
				XWriter.WriteLine("group "+NewChild+" name:\""+(f.name)+"\"")
				)
			--//--
			)	
		--//--
		for f in objects where (isGroupHead f) and (f.parent != undefined) do 
			(
			ValidSubChild=true
			--//--
			for i in 1 to f.children.count do 
				(
				if (isGroupHead f.children[i]) then ValidSubChild=false
				)
			--//--
			if ValidSubChild==false then
				(
				NewChild="#("
				--//--
				for i in 1 to f.children.count do 
					(
					NewChild += ("$"+f.children[i].name)
					if i != f.children.count then (NewChild += ",") else (NewChild += ")")
					)
				--//--
				append MidChild ("group "+NewChild)
				append MidChildName f.name
				)
			--//--
			)	
		--//--
		if MidChild.count != 0 then
			(
			for f in 1 to MidChild.count do
				(
				Xfound=false
				--//--
				for i in 1 to MidChildName.count do
					(
					if (matchpattern MidChild[f] pattern:("*"+MidChildName[i]+"*") ignoreCase:true) then
						(
						append ChildB (MidChild[f]+" name:\""+MidChildName[f]+"\"")
						Xfound=true
						)
					)
				--//--
				if Xfound==false then (append ChildA (MidChild[f]+" name:\""+MidChildName[f]+"\""))
				)
			)
		--//--
		for f in ChildA do (XWriter.WriteLine(f))
		for f in ChildB do (XWriter.WriteLine(f))
		--//--
		for f in objects where (isGroupHead f) and (f.parent == undefined) do 
			(
			NewChild="#("
			--//--
			for i in 1 to f.children.count do 
				(
				NewChild += ("$"+f.children[i].name)
				if i != f.children.count then (NewChild += ",") else (NewChild += ")")
				)
			--//--
			XWriter.WriteLine("group "+NewChild+" name:\""+(f.name)+"\"")
			)	
		--//--
		XWriter.WriteLine(")")
		--//--
		XWriter.close()
		XWriter.dispose()
		)
	)
--//--
fn XRepair =
	(
	Xtemp=(Xfolder+"\\"+(getFilenameFile Xpath)) ; makedir Xtemp
	Xout=(Xfolder+"\\"+(getFilenameFile Xpath)+".3ds")
	XFinal=(Xfolder+"\\"+(getFilenameFile Xpath)+"_fixed.max")
	--//--
	resetMaxFile #noPrompt
	loadMaxFile Xpath useFileUnits:true quiet:true
	--//--
	CleanUtil.ExportSceneState (Xtemp+"\\SceneState.ms")
	--//--
	for f in objects where classof f != Targetobject do 
		(
		append OriginalName f.name
		)
	--//--
	for f in 1 to (OriginalName.count) do 
		(
		Xnode=(execute ("$"+"'"+OriginalName[f]+"'"))
		append ModifiedName (f as string)
		append MaterialList Xnode.material
		append WirecolorList Xnode.wirecolor
		Xnode.name=(f as string)
		)
	--//--
	Xcleaner.pb1.value=25
	sleep 0.1
	--//--
	for f in ModifiedName do 
		(
		Xnode=(execute ("$"+f))
		Xclass=classof Xnode
		XSuper=superclassof Xnode
		--//--
		case Xclass of
			(
			Editable_mesh:(
				Xfile=(Xtemp+"\\"+Xnode.name)		
				CleanUtil.Write Xfile Xnode 1
				)
			Editable_Poly:(
				Xfile=(Xtemp+"\\"+Xnode.name)	
				CleanUtil.Write Xfile Xnode 2
				)
			)
		--//--
		case XSuper of
			(
			light:(
				case Xclass of
					(
					Omnilight:(
						Xfile=(Xtemp+"\\"+Xnode.name)
						CleanUtil.WriteLight Xfile Xnode
						append ClassList light
						)
					targetSpot:(
						Xfile=(Xtemp+"\\"+Xnode.name)
						CleanUtil.WriteLight Xfile Xnode
						append ClassList light
						)
					Skylight:(append ClassList "Skip")
					default:(
						Xfile=(Xtemp+"\\"+Xnode.name)
						CleanUtil.ExportLight Xfile Xnode Xclass 
						CleanUtil.WriteLight Xfile Xnode
						append ClassList light
						append ScriptedObject (Xfile+".ms")
						)
					)
				)
			default:(append ClassList Xclass)
			)
		--//--
		)
	--//--
	exportfile Xout #noPrompt 
	resetMaxFile #noPrompt
	importfile Xout #noPrompt 
	deletefile Xout
	--//--
	Xcleaner.pb1.value=50
	sleep 0.1
	--//--
	for f in ScriptedObject do (filein f)
	--//--
	for f in ModifiedName do 
		(
		Xnode=(execute ("$"+f))
		--//--
		case ClassList[(f as integer)] of
			(
			Editable_mesh:(
				Xweld=vertexweld threshold:0.01
				addmodifier Xnode Xweld
				collapsestack Xnode
				Xfile=(Xtemp+"\\"+f)		
				CleanUtil.Read Xfile Xnode 1
				Xnode.material=MaterialList[(f as integer)]
				Xnode.wirecolor=WirecolorList[(f as integer)]
				Xnode.name=OriginalName[(f as integer)]
				)
			Editable_Poly:(
				Xweld=vertexweld threshold:0.01
				addmodifier Xnode Xweld
				collapsestack Xnode
				converttopoly Xnode
				Xfile=(Xtemp+"\\"+f)		
				CleanUtil.Read Xfile Xnode 2
				Xnode.material=MaterialList[(f as integer)]
				Xnode.wirecolor=WirecolorList[(f as integer)]
				Xnode.name=OriginalName[(f as integer)]
				)
			--targetobject:()
			Default:(
				if ClassList[(f as integer)]!="Skip" then
					(
					Xnode.name=OriginalName[(f as integer)]
					)
				)--end default
			)
		)
	--//--
	for f in 1 to OriginalName.count do 
		(
		Xnode=(execute ("$"+OriginalName[f]))
		--//--
		case ClassList[f] of
			(
			light:(
				Xfile=(Xtemp+"\\"+(f as string))	
				CleanUtil.ReadLight Xfile Xnode
				)
			)
		--//--
		)	
	--//--
	Xcleaner.pb1.value=75
	sleep 0.2
	--//--
	Xcleaner.pb1.value=100
	sleep 0.1
	Xcleaner.pb1.value=0
	--//--
	Xpath=undefined
	OriginalName=#()
	ModifiedName=#()
	MaterialList=#()
	WirecolorList=#()
	ClassList=#()
	--//--
	Xcleaner.edt1.text=""
	Xcleaner.btn2.enabled=false
	--//--
	filein (Xtemp+"\\SceneState.ms")
	--//--
	gc()
	--//--
	saveMaxFile XFinal quiet:true
	shellLaunch "explorer.exe" Xfolder
	)
--//--
rollout Xcleaner Xversion width:360 height:98
	(
	edittext edt1 " " pos:[0,8] width:248 height:24 readOnly:true
	button btn1 "Input" pos:[248,8] width:104 height:24
	button btn2 "Clean" pos:[8,65] width:344 height:24 enabled:false
	progressBar pb1 "ProgressBar" pos:[8,41] width:344 height:16 color:(color 255 255 0)
	--//--
	on btn1 pressed do 
		(
		Result=getOpenFileName caption:"Select a .Max file to repair." filename:(getdir #scene+"\\") types:"3dsmax (*.max) | *.max"
		--//--
		if (Result != undefined) and (isMaxFile Result) then
			(
			edt1.text=(filenameFromPath Result)
			Xpath=(Result)
			btn2.enabled=true
			)
		)
	--//--
	on btn2 pressed do 
		(
		Result=yesNoCancelBox "Do you want to proceed ?" title:"Please, save your work first !!!" beep:false
		if Result==#yes then XRepair()
		)
	--//--
	)
--//--
createdialog Xcleaner bgcolor:(color 160 160 160) fgcolor:(color 255 255 255) style:#(#style_sysmenu,#style_toolwindow)
)

 

edit: try this one instead …let me know if it work !!!

best regard,
martin


MAXScript Rollout Handler Exception

– Unable to convert: dotNetObject:System.Int32 to type: Integer

OK

hmm nope looks like this one no dice as well.

i had the same problem since 3ds max 9

it seems the problem persists
i dind’t have time to test 3ds max 2009, but i did’t see any signs from autodesk that they are even trying to solve theese problems.

“fortunately” they bought maya and xsi in the meanwhile

it seems that the best idea is OSS like blender, isn’t it?

Page 2 / 2