STL batch export script help!

STL batch export script help!

Anonymous
Not applicable
3,410 Views
14 Replies
Message 1 of 15

STL batch export script help!

Anonymous
Not applicable
I need to get hold of a script that will batch export my geometry to individual STL files and set the individual STL file names to the same as the internal max object names.

The STLs need to be in ASCII format

I.e in my scene i have an object named BOX1 and one named BOX2
I want the option to export them individually or in a batch
I want BOX1 to create an STL with the name BOX1.STL etc etc
I have approx 700 objects in the scene and i want an individual STL for each

As i want to export a large number of files i dont want any prompts etc.
I would quite like to just have a box in the menu bar that i could click on an object or a collection of objects and click export and hav them all sent to a specific folder.

Any clue?

I am new to MAX script so this is probably an ambitious project to start with... HELP 🙂 !!

Anyone done anything similar that i could modify?
0 Likes
3,411 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
maybe this is you need

0 Likes
Message 3 of 15

Steve_Curley
Mentor
Mentor
Unfortunately that doesn't address the requirement for an STL export, as stated in the thread title / topic, neither does it address the reqirement for exporting each object to its own file named appropriately.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 4 of 15

Anonymous
Not applicable
I think he was suggesting that you could write the ASCII data 'manually' instead of relying on the exporter. The format of STL itself is pretty simple, although the code required to generate solid data from mesh data probably isn't.

It's not an optimal solution, but I suppose it would serve if no better way turns up.
0 Likes
Message 5 of 15

Steve_Curley
Mentor
Mentor
Thing is - there is already a way to do it - the "exportFile" function, but I can't get it working for STL files - see this thread. The rest of it - iterating over a selection, generating the right filename and so on is pretty straightforward, but I don't fancy reinventing that particular wheel when one already exists.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 6 of 15

Steve_Curley
Mentor
Mentor
Ok, here's your solution (I think 😉 ).

macroScript Export_Selected_2_STL category:"ScrewyScripts" tooltip:"Export selected to .STL"

(
global STL_Object_Name = ""

fn SetSTLExportOptions =
(
local BM_GETSTATE = 0xF2
local BM_CLICK = 0xF5
local BM_SETCHECK = 0xF1
local BST_CHECKED = 0x1

WindowHandle = DialogMonitorOPS.GetWindowHandle()
if ((UIAccessor.GetWindowText WindowHandle) == "Export STL File") then
(
children = UIAccessor.GetChildWindows WindowHandle
for i = 1 to children.count do
(
child = children
childTitle = (UIAccessor.GetWindowText child)
if (childTitle == "Object01") then
UIAccessor.SetWindowText child STL_Object_Name
if (childTitle == "Selected only") then
(
cbState = windows.sendMessage child BM_GETSTATE 0 0
checked = bit.get cbState BST_CHECKED
if (checked == false) then
(
windows.sendMessage child BM_CLICK 0 0
windows.sendMessage child BM_SETCHECK 1 0
)
)
)
uiAccessor.sendMessageID WindowHandle #IDOK
)
true
)

DialogMonitorOPS.unRegisterNotification id:#Set_STL_Export_Options
DialogMonitorOPS.RegisterNotification SetSTLExportOptions id:#Set_STL_Export_Options
DialogMonitorOPS.Enabled = true

selected = for obj in selection collect obj
for obj in selected do
(
STL_Object_Name = obj.name
select obj
exportFile ((getDir #export) + "/" + STL_Object_Name + ".stl")
)

DialogMonitorOPS.Enabled = false
DialogMonitorOPS.unRegisterNotification id:#Set_STL_Export_Options
)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 15

Anonymous
Not applicable
Tanks for That, but i am having trouble getting that last script to run
When i try to launch it from Max 2009 nothing happens


This is the Code sampe i have been using in the past, The problem is that it launches the internal STL export window without copying over the object name.
It can be used for multiple files, but is a bit buggy and due to the large number of files to export, it is a pain having to manually rename the internal STL names to match those in max.



--this script is made by Anton Berg at os3d.se
--antonos3d.se


rollout ExportObj "Export as separate files" width:232 height:107
(
global theClasses
global outPath
local debug = true
edittext edt1 "filename" pos: width:152 height:16 readOnly:false
button btn1 "Export" pos: width:56 height:40
checkbox chk1 "Prefix of the file:" pos: width:120 height:16 checked:true toolTip:"if this is checked then the prefix text will be used to name the file"
dropdownList ddl2 "FileType" pos: width:152 height:40
checkbox chk2 "Debug" pos: width:56 height:16 checked:true tooltip:"This will show error messages"


fn NewfileName inputPath objName ischecked nr= (
if ischecked == true then
(
--set the filename to this prefix
np = inputPath + "\\" + objName + "_"+ nr as string --+".obj"
if debug then print np
)

else
(
--set the filename to the object filename
np = inputPath + "\\" + objName --e+ ".obj"
if debug then print np
)
return np
)



on ExportObj open do
(
theClasses = exporterPlugin.classes
theClassesNames = #()
for exptyp in theClasses do
(
append theClassesNames (exptyp as string)
)
ddl2.items = theClassesNames
)
on btn1 pressed do
(
theClasses = exporterPlugin.classes
if outPath == undefined then outPath = ""
outPath = getSavePath initialDir:outpath
if outPath != undefined then
(
selArray = selection as array
sceneObjs =#()

for item in selArray do
(
try (explodeGroup item)
catch()
)

selArray = selection as array
for item in selArray do
(
if (isKindOf item GeometryClass) then append sceneObjs item
)


for i = 1 to sceneObjs.count do
(
oname = (if chk1.state then edt1.text else sceneObjs.name)

if i == 1 then
(
select sceneObjs
newName = NewfileName outPath oname chk1.state i

result = (exportFile newName using:(theClasses) selectedOnly: true)

if result != true then (
if chk2.state == true then (messageBox "OS3D debug INFO:\nYou have a selected a filformat that doesn´t except the selected only state..")
result = (exportFile newName using:(theClasses) selectedOnly: false)
)


)

if i > 1 then
(
select sceneObjs
newName = NewfileName outPath oname chk1.state i

result = (exportFile newName #noPrompt using:(theClasses) selectedOnly: true)
if result != true then (
--messageBox "You have a selected a filformat that doesn´t except the selected only state.."
result = (exportFile newName using:(theClasses) selectedOnly: false)
)
)

)
select sceneObjs
)
else
(
messagebox "No output path selected"
)
)
on chk1 changed theState do
(
if theState then edt1.readOnly = false else edt1.readOnly = true
)
)
createdialog ExportObj



0 Likes
Message 8 of 15

Steve_Curley
Mentor
Mentor
Remove the 1st line (that's outside the parenthesis) - quite why it doesn't like that I'm not sure, but it definitely works if you do that. Obviously "evaluating" a script in the editor isn't quite the same as Running a script.

Note. it expects the objects to be selected prior to running the script - and there's no error trapping to tell you if you haven't !

Just realised you want the output in ASCII format - I'll have a look at changing it to do that

Modified script attached

19298_p5gHAlgoqDmtRcDQvNgW.zip


Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 9 of 15

Anonymous
Not applicable
Perfect! That is exactly what i neeeded THANKS!
0 Likes
Message 10 of 15

Steve_Curley
Mentor
Mentor
I knew we'd get there eventually 😉

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 11 of 15

Anonymous
Not applicable
Hi, this is a great script but only works in max 9, is there a way of getting sorted in max 8?
Cheers for the help guys, pulling my hair out here.
0 Likes
Message 12 of 15

Steve_Curley
Mentor
Mentor
I'm afraid not. The UIAccessor and DialogMonitorOPS functions were introduced in Max 9 - they simply don't exist in Max 8.

The ExporterPlugin.classes and exportFile are there and work, the problem is accessing the UI elements in order to enable "Selected only" - that's the bit which doesn't exist in Max 8

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 13 of 15

spencer.fitch
Contributor
Contributor

Is there anyway I can get this script still? This is exactly what we need for a big project. Max 2021 

Message 14 of 15

mdoone03
Observer
Observer

Hey, did you ever solve this? Crazy old thread but very important topic and cant find anything else online with more recent MAX versions.

Message 15 of 15

denisT.MaxDoctor
Advisor
Advisor

@mdoone03 wrote:

Hey, did you ever solve this? Crazy old thread but very important topic and cant find anything else online with more recent MAX versions.


It's better to start a new topic and explain your needs and problems in detail, rather than reviving an old one.