Community
All code used belongs to - Batch Convert MAX Files v1.0/miauu's Batch Save/Export tool
Batch Convert MAX Files v1.0
https://bodyulcg.com/product/batch-convert-max-files/
miauu's Batch Save/Export tool
https://miauu-maxscript.com/portfolio-item/miauus-batch-save-obj-fbx-3ds-as-max-files/
I've been trying to modify miauu's batch converter to export multiple formats. I think I'm close maybe, I still get errors
How can I get rid of the xRefCnt I think it was only used for saving previous max file versions.
for i = 0 to xRefCnt where (lv_Batch.Items.Item[i].checked == true) do with redraw off
Also having issues with this export code this says no data
for i = 0 to xRefCnt where (lv_Batch.Items.Item[i].checked == true) do with redraw off
(
importFile maxFiles[i+1] #noPrompt
filePath = getFilenamePath maxFiles[i+1]
fileName = (getFilenameFile maxFiles[i+1])
newName = filePath + "\\" + fileName + file_type
exportFile newName
resetMaxFile #noPrompt
pb_xRefprogress.value = 100.0 * i / xRefCnt
windows.processPostedMessages()
)
Full code
(
global rol_miauuBatchConvert
try(destroyDialog rol_miauuBatchConvert)catch()
rollout rol_miauuBatchConvert "miauu's BatchCovert" width:585 height:543
(
local get_path
local get_files
local set_path
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 openFileRoll = dotNetObject "System.Windows.Forms.OpenFileDialog"
local disableForeColor = (dotNetClass "System.Drawing.Color").white
local maxFiles = #()
local name_of_type = #(
"3D_StudioExporterPlugin (.3DS)",
"Adobe_Illustrator (.AI)",
"DWG_Export (.DWG)",
"DWF_Exporter (.DWF)",
"STL_Export (.STL)",
"FBXEXP (.FBX)",
"ObjExp (.OBJ)"
)
dotNetControl 'lv_Batch' "system.windows.forms.listView" pos:[10,10] width:273 height:200 align:#left
dropdownList 'ddl1' "File type:" pos:[13,308] width:176 height:40 items:#("3D_StudioExporterPlugin (.3DS)", "Adobe_Illustrator (.AI)", "DWG_Export (.DWG)", "DWF_Exporter (.DWF)", "STL_Export (.STL)", "FBXEXP (.FBX)", "ObjExp (.OBJ)") align:#left
checkbox 'chk1' "Show settings window for each file" pos:[15,354] width:188 height:15 align:#left
button 'btn_getDir' "Get Directory" pos:[290,10] width:108 height:21 toolTip:"Select all .max files in the given folder and/or its sub-folders" align:#left
button 'btn_getFile' "Get file(s)" pos:[290,35] width:108 height:21 toolTip:"Select one or multiple files in given folder" align:#left
button 'btn_clear' "Clear" pos:[290,60] width:108 height:21 align:#left
checkbox 'chkBox_showFullPath' "Show Full Path" pos:[10,215] width:94 height:15 align:#left
label 'lbl_select' "Select:" pos:[120,215] width:32 height:13 align:#left
button 'btn_all' "All" pos:[157,214] width:40 height:18 align:#left
button 'btn_none' "None" pos:[200,214] width:40 height:18 align:#left
button 'btn_invert' "Invert" pos:[243,214] width:40 height:18 align:#left
button 'bnt_saveAsPrevious' "Convert" pos:[10,235] width:275 height:30 align:#left
progressBar 'pb_xRefprogress' "" pos:[10,270] width:275 height:14 value:0 color:(color 0 255 0) align:#left
-- 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_miauuBatchConvert.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 rol_miauuBatchConvert 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")
)
on lv_Batch mouseDown arg do
(
-- delete selected max file from the listview
if 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 file
if 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 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_clear pressed do
(
maxFiles = #()
BatchListViewReIinit()
)
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_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 bnt_saveAsPrevious pressed do
(
local file_type = case ddl1.selection of
(
1:".3ds"
2:".ai"
3:".dwg"
4:".dwf"
5:".stl"
6:".fbx"
7:".obj"
default:".3ds"
)
for i = 0 to xRefCnt where (lv_Batch.Items.Item[i].checked == true) do with redraw off
(
(
importFile maxFiles[i+1] #noPrompt
filePath = getFilenamePath maxFiles[i+1]
fileName = (getFilenameFile maxFiles[i+1])
newName = filePath + "\\" + fileName + file_type
if chk1.state then
(
exportFile (set_path + "\\" + (GetFileNameFile i) + file_type)
)
else
(
exportFile (set_path + "\\" + (GetFileNameFile i) + file_type) #noPrompt
)
saveMaxFile newName useNewFile:true quiet:true
resetMaxFile #noPrompt
pb_xRefprogress.value = 100.0 * i / xRefCnt
if curMaxVersion > 12 do
windows.processPostedMessages()
)
)
completeRedraw()
resumeEditing()
setArrowCursor()
)
)
createdialog rol_miauuBatchConvert width:405
)
Can't find what you're looking for? Ask the community or share your knowledge.