ScriptSpot is a diverse online community of artists and developers who come together to find and share scripts that empower their creativity with 3ds Max. Our users come from all parts of the world and work in everything from visual effects to gaming, architecture, students or hobbyists.
(
global rol_miauuBatchLoadXRefScenes
try(destroyDialog rol_miauuBatchLoadXRefScenes)catch()
rollout rol_miauuBatchLoadXRefScenes "miauu"(
local ConvertClass = dotnetclass "system.convert"
local ImageClass = dotnetclass "system.drawing.image"
local logoIcon = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACxIAAAsSAdLdfvwAAALcSURBVDhPbZJLSFRhGIa/1C6IMmmQFNownplzv8y5zIzOqGPimE5hFxfeZxQzu0AXDbtsXHWBwNpWaIt2lQWBFSS0qCholbsW7QwiiKBNRDlv//xTWtjiO9+B77zP+37/+QkA7QxXULu7mZLmVmq1K2lvtIzSjm/A0Wt/NjdEl0d62w+eGe2gyUyCTvXHaawnSRNDTVy7AuhwfdTt+Kg1XBFIWNVLmqZj/ryGc90yVN1CZ3vjx9PDLWpS3UJH+pI0nv0L0MaEaa+cYnr1M0OVIKkWNN0AXsQxe0KCIkvwCxI818bgvsTL8eFWmhpLrgLq9Korri4si4oJVTNg6Covy5RhGQrrOusqQqIEQVSQqI/mjvY1T68AhJCc0wwLuqbwmuwKAfdcDkl4MvAmjr1NEgNpMA0NghCEFXZzKwBRFHP54WhawudbNpbuePg+5+DVBR3vZlxgIYrFqwY+zNjoSckcbNvhVYAkhnIWI4/36czZRiNzzX/07kYYl7MSd812qsC8h96UxFOy81gLOLSHxX3ooi4scsBb5jrVL3PAGJt9u2uju7Wwpuc6awEne1mChRganALgy/0oprMiB5wdsXiCgV1yAeD8B3B8P0vwOIJUfWGFL7ct3DymcsDxLgV45GEo/SfBXyvIssQPcWKQ/XsGaP8NeP+gHtdGFA6YHLOBJxFkdv1nhUBtMOc4Nhflh/lusuKdifPp8j1fYWaksJtpOLFVgFNbOltd44fCLpFpsdiHJbZvhAPa6tj763pkUiJ000JIjzATGW12xfMVQIuygbZv2bhJ2uFbDAYFXDrh4dP1MAMoSCU14GkMnc0Wu+Immqyqz/2xdXXDsYKWPxqkUvJvKyM3UEJ6TUlc8ld+9QsqNNNmrg4ExUHEqPlxwF1/6nAD0WgjUU+0+F9ATVU5WYFSigY3kreDKOIvuaiGqpdNNYTdbtncSJzoYIIoGy+mTLyIAYqYFvQLPey9qVeXvysAAAAASUVORK5CYII="
local curMaxVersion = ((maxVersion())[1]/1000)
local openFileRoll = dotNetObject "System.Windows.Forms.OpenFileDialog"
local disableForeColor = (dotNetClass "System.Drawing.Color").white
local maxFiles = #()
dotNetControl lv_Batch "system.windows.forms.listView" height:200 width:273 pos:[10,10]
button btn_getDir "Get Directory" width:108 pos:[290,10] tooltip:"Select all .max files in the given folder and/or its sub-folders"
button btn_getFile "Get file(s)" width:108 pos:[290,35] tooltip:"Select one or multiple files in given folder"
button btn_Clear "Cear" width:108 pos:[290,60]
checkbox chkBox_showFullPath "Show Full Path" pos:[10,215]
label lbl_select "Select:" pos:[120,215]
button btn_all "All" pos:[157,214] width:40 height:18
button btn_none "None" pos:[200,214] width:40 height:18
button btn_invert "Invert" pos:[243,214] width:40 height:18
button btn_loadXRefScenes "Load xRef Scenes" width:275 height:30 pos:[10,235]
hyperLink http_miauu "miauu's MaxScripts" address:"http://miauumaxscript.blogspot.com/" pos:[300,270] color:(color 7231251)
progressBar pb_xRefprogress value:0 color:green width:275 pos:[10,270]-- Credist to Peter Addington - http://lonerobot.net/?p=314
function String2Bmp string =
(
local clipboardClass = dotNetClass "System.Windows.Forms.Clipboard"
local ConvertClass = dotnetclass "system.convert"
local imageclass = dotNetclass "System.Drawing.image"
local bytearr = convertclass.FromBase64String string
local memstream = dotnetobject "System.IO.MemoryStream" bytearr
local DecodedImg = ImageClass.fromstream memstream
memstream.close()
DecodedImg
)-- credits to Denis Trofimiv - http://forums.cgsociety.org/showpost.php?p=7708817&postcount=21
function LoadMyLogoAsTitlebarIcon =
(
d = (windows.getChildHWND 0 rol_miauuBatchLoadXRefScenes.title)[1]
WM_SETICON = 0x0080
ICON_SMALL = 0
bm = dotnetobject "System.Drawing.Bitmap"(String2Bmp logoIcon)
ptr = bm.GetHicon()
icon = (dotnetclass "System.Drawing.Icon").FromHandle (dotnetobject "IntPtr" ptr)
windows.SendMessage d WM_SETICON ICON_SMALL icon.handle
)
function AddColumns theLv columnsAr=
(if chkBox_showFullPath.state == false then
w=(theLv.width)-6
else
w=(theLv.width)+400
for x in columnsAr do(
theLv.columns.add x w
))
function PopulateListView theLv=
(
rows=#()for x=1 to maxFiles.count do(if chkBox_showFullPath.state == false then
mapName = (getFilenameFile maxFiles[x])else
mapName = maxFiles[x]
li = dotNetObject "System.Windows.Forms.ListViewItem" mapName
append rows li
)
theLv.items.addRange rows
)
function InitListView theLv=
(
theLv.clear()
theLv.headerStyle = theLv.headerStyle.none
theLv.view = (dotNetClass "system.windows.forms.view").details
theLv.FullRowSelect = true
theLv.MultiSelect = true
theLv.checkBoxes = true
theLv.backcolor = (dotNetClass "System.Drawing.Color").DimGray
theLv.forecolor = (dotNetClass "System.Drawing.Color").lightGray
)
function BatchListViewReIinit =
(
InitListView lv_Batch
AddColumns lv_Batch #("")
PopulateListView lv_Batch
)
function TurnBatchLVchkBoxOn =
(for i = 0 to lv_Batch.Items.count-1 do
lv_Batch.Items.Item[i].checked = true
lv_Batch.forecolor = disableForeColor
)
function OpenFolders folderToOpen =
(
local checkFolderName = substring folderToOpen 1 (folderToOpen.count-1)if(symbolicPaths.isPathName checkFolderName) then
(
folderToOpen = symbolicPaths.getPathValue checkFolderName
)
shellLaunch "explorer.exe" folderToOpen
)
function GetFilesRecursive root pattern =
(
dir_array = GetDirectories (root+"\*")for d in dir_array do
join dir_array (GetDirectories (d+"*"))
my_files = #()for f in dir_array do
join my_files (getFiles (f + pattern))
my_files
)
on btn_getDir pressed do(
dir = getSavePath caption:"Select the directory" initialDir:"$scenes"if dir != undefined do(
maxFiles = #()-- get all max files
maxFiles = getFiles (dir+"\*.max")-- check for subfolders
subFiles = GetFilesRecursive dir "*.max"if subFiles.count != 0 then
(
msg = "The selected folder have subfolders!\n"
msg += "Do you want to include the files from the subfolders too?"if queryBox msg title:"Sub-folders found"do
join maxFiles subFiles
)
makeUniqueArray maxFiles
PopulateListView lv_Batch
TurnBatchLVchkBoxOn()))
on btn_getFile pressed do(
result = openFileRoll.showDialog()
result.ToString()if(result.Equals result.OK)do(
filePath = (openFileRoll.fileNames)
join maxFiles filePath
makeUniqueArray maxFiles
BatchListViewReIinit()
TurnBatchLVchkBoxOn()))
on btn_all pressed do(for i = 0 to lv_Batch.Items.count-1 do lv_Batch.Items.Item[i].checked = true)
on btn_none pressed do(for i = 0 to lv_Batch.Items.count-1 do lv_Batch.Items.Item[i].checked = false)
on btn_invert pressed do(for i = 0 to lv_Batch.Items.count-1 do lv_Batch.Items.Item[i].checked = not lv_Batch.Items.Item[i].checked
)
on btn_Clear pressed do(
maxFiles = #()
BatchListViewReIinit())
on lv_Batch MouseDown arg do(-- delete selected max file from the listviewif arg.button==arg.button.middle then
(if(hitNode = lv_Batch.GetItemAt arg.x arg.y)!= undefined do(
deleteItem maxFiles (hitNode.index+1)
BatchListViewReIinit()))-- open folder of selected max fileif arg.button==arg.button.right then
(if(hitNode = lv_Batch.GetItemAt arg.x arg.y)!= undefined do(
f = (hitNode.index+1)
folderToOpen = (getFilenamePath maxFiles[f])
OpenFolders folderToOpen
)))
on chkBox_showFullPath changed state do(
cbState = for i = 0 to lv_Batch.Items.count-1 collect lv_Batch.Items.Item[i].checked
BatchListViewReIinit()for i = 0 to lv_Batch.Items.count-1 do lv_Batch.Items.Item[i].checked = cbState[i + 1])
on btn_loadXRefScenes pressed do(
local xRefCnt = (lv_Batch.Items.count - 1)
setWaitCursor()for i = 0 to xRefCnt where (lv_Batch.Items.Item[i].checked == true)do with redraw off
(
resetMaxFile #noprompt
loadMaxFile maxFiles[i + 1] useFileUnits:true quiet:true
delete cameras
delete lights
saveMaxFile maxFiles[i + 1] useFileUnits:true quiet:true
pb_xRefprogress.value = 100.0 * i / xRefCnt
if curMaxVersion > 12 do
windows.processPostedMessages())
setArrowCursor())
on rol_miauuBatchLoadXRefScenes open do(try(LoadMyLogoAsTitlebarIcon())catch()
openFileRoll.title = "Select Files"
openFileRoll.Multiselect = true
openFileRoll.Filter = "MAX (*.max)|*.max"
openFileRoll.FilterIndex = 1
openFileRoll.RestoreDirectory = true
InitListView lv_Batch
AddColumns lv_Batch #("Files")))
createdialog rol_miauuBatchLoadXRefScenes width:405)
I don't have time to rearange the UI. It will load all files and will delete all lights and cameras, then will save the loaded file with the same name in the same directory(the file will be overwritten).
Yes of course. but make sure you backup them before.
Just copy all files to one folder and change path to it -> maxfiles_Folder
This script will batch delate all camers and ligths in those files and resave them with new suffix "no_cams-lights"
maxfiles_Folder = "D:\\3d\\abc\\"
maxfiles = getFiles (maxfiles_Folder + "*.max")for f in maxfiles do(
loadMaxFile f quiet:true #noprompt
for o in objects where superclassof o == camera or superclassof o == light do delete o
saveMaxFile (getfilenamepath f + getfilenamefile f + "_no-cams-lights.max"))
or if you want to save them to new folder:
maxfiles_Folder = "D:\\3d\\abc\\"
newFolder = "D:\\3d\\newFolder\\"
makeDir newFolder
maxfiles = getFiles (maxfiles_Folder + "*.max")for f in maxfiles do(
loadMaxFile f quiet:true #noprompt
for o in objects where superclassof o == camera or superclassof o == light do delete o
saveMaxFile (newfolder + getfilenamefile f + "_no-cams-lights.max"))
Yes.
You have to batch load all 100 files, delete cameras and lights in each file, then save the file.
If you are sure that all cameras and lights have names that contains "Camera" and "Light" in it you can check the name of the objects, before loding the files, to avoid loading max file where there is no cameras or lights. Nut if the name of the cameras and lights do not have "Camera"/"Light" then you have to load all max files one by one.
Comments
want to delete Layer itself along with its content
hello
i want to delete some layers along with its content which contain geometry, light, cameras.
with this script, i can only delete camera and light is there any way to update this.
thanks for the Help!
.
Try this:
I don't have time to rearange the UI. It will load all files and will delete all lights and cameras, then will save the loaded file with the same name in the same directory(the file will be overwritten).
Tools and Scripts for Autodesk 3dsMax
yes
Yes of course. but make sure you backup them before.
Just copy all files to one folder and change path to it -> maxfiles_Folder
This script will batch delate all camers and ligths in those files and resave them with new suffix "no_cams-lights"
or if you want to save them to new folder:
But be careful changing / using it!
Best,
Pixamoon
.
Yes.
You have to batch load all 100 files, delete cameras and lights in each file, then save the file.
If you are sure that all cameras and lights have names that contains "Camera" and "Light" in it you can check the name of the objects, before loding the files, to avoid loading max file where there is no cameras or lights. Nut if the name of the cameras and lights do not have "Camera"/"Light" then you have to load all max files one by one.
Tools and Scripts for Autodesk 3dsMax