[Closed] Control the obj export option
Hi
Are there any ways in 3DSMax to control the obj export object. I need some special checkbox with obj export and want to make a script so it automatically export obj for me with these kind of option. However, it seems max force us to open the option export dialog.
So anyone know how to export obj with parameter?
Thanks for any helps
Not seeing any way to provide export options on a command line…
…and nowhere to set the defaults…
…so unless somebody finds something like the above, your solution is going to be similar to…
http://forums.cgsociety.org/showthread.php?f=98&t=639812&page=1&pp=15&highlight=sendmessage
[b][i]- Control some option in viewport config through Script
[/i][/b]I.e.
- detect the obj export dialog
- set the checkbox(es) of choice
- press the Export button
The only additionally annoying thing is that the exporter then pops up another dialog… either…
A. Error
B. A progress dialog
We don’t much care about A, other than reporting that error
We do care about B, however… the dialog pops up and does a little obj export progress thing. We can’t just go and press the button that closes the dialog as that button acts as “Cancel Export” until the export is finished. So instead, we’ll have to keep an eye on that dialog (via a .NET Timer) and check it once in a while (every 250ms, for example) to see if the export is done yet. Thankfully we can check that quite easily by seeing if there’s a button labeled “-= DONE =-”.
Below is the code that does all that… you’ll have to adjust it to check/uncheck the checkboxes you want to check/uncheck, probably remove the “sleep 3” when done (that sleep is in there so you can see if the checkboxes are being checked/unchecked OK), and maybe some further tweaks… I haven’t cleaned it up much… several global variables and whatnot.
So without further ado… more ScaryCode:
Edit: 3ds Max 2009 only. For 3ds Max 9 / 3ds Max 2008, see later post!
global BN_CLICKED = 0 -- clicky message ID
global BM_SETCHECK = 241 -- checkbutton toggle message ID
global WM_COMMAND = 273 -- windows command message
global theObjExportTimer -- a .NET timer to check whether obj export is complete or not.
dialogMonitorOPS.UnRegisterNotification id:#test -- remove any old instance
fn seeIfObjExportIsDoneYet = (
try (
-- get all of the popup dialogs
local popupWindows_hwnds = UIAccessor.GetPopupDialogs()
-- loop over all of these dialogs
for child_hwnd in popupWindows_hwnds do (
-- and find the one titled "Exporting OBJ"
if (UIAccessor.getWindowText child_hwnd == "Exporting OBJ") then (
-- now get all of its children UI elements
local dlgChildren_hwnds = UIAccessor.getChildWindows child_hwnd
-- loop over those UI elements
for dlgChild_hwnd in dlgChildren_hwnds do (
-- see if the "-= DONE =-" button appears to exist
-- ( the button always exists, but until the export is actually done, will be labeled "Cancel Export" )
if (UIAccessor.getWindowText dlgChild_hwnd == "-= DONE =-") then (
-- and press it if it does
UIAccessor.pressButton dlgChild_hwnd
-- oh and let's not forget to stop that timer...
print "Export to OBJ finished"
theObjExportTimer.stop()
)
)
exit
)
)
)
catch (
theObjExportTimer.stop()
)
)
theObjExportTimer = dotNetObject "System.Windows.Forms.Timer"
dotNet.addEventHandler theObjExportTimer "tick" seeIfObjExportIsDoneYet
theObjExportTimer.interval = 500
fn test = (
hwnd = DialogMonitorOPS.GetWindowHandle() -- check the dialog that popped up
hwnd_title = UIAccessor.GetWindowText hwnd
if (hwnd_title == "OBJ Export Options") then ( -- the obj export config dialog
local flipControl_hwnd = undefined
local flipControl_parent_hwnd = undefined
local controls = windows.getChildrenHWND hwnd -- get all controls for this dialog
for c in controls do (
if (c[5] == "Flip YZ-axis (Poser-like)") then (
flipControl_hwnd = c[1]
flipControl_parent_hwnd = c[2]
exit
)
)
local flipControl_id = UIAccessor.GetWindowResourceID flipControl_hwnd
windows.sendMessage flipControl_hwnd BM_SETCHECK 0 0 -- uncheck the Flip YZ-axis option. Set to '1 0' to check it.
windows.sendMessage flipControl_parent_hwnd WM_COMMAND ((bit.shift BN_CLICKED 16) + flipControl_id) flipControl_hwnd
-- REMOVE THIS WHEN CONFIDENT THINGS WORK
sleep 3 -- let's sleep here for a bit so you can check if that checkbox got checked
-- /REMOVE THIS WHEN CONFIDENT THINGS WORK
UIAccessor.PressButtonByName hwnd "Export" -- press the Export button
) -- hwnd_title == "OBJ Export Options"
else if (hwnd_title == "Exporting OBJ") then (
-- oh nasty. This dialog pops up, and it's a 'progress' dialog. So we'll have to check it at an interval.. lovely!
-- invoke the .NET timer
theObjExportTimer.start()
) -- hwnd_title == "Exporting OBJ"
else if (hwnd_title == "Error") then (
-- we could check what the actual error is, but let's save that for if/when that's needed.
print "An error occurred while attempting to export to .OBJ -- perhaps nothing to export?"
UIAccessor.pressButtonByName hwnd "OK"
)
true
)
dialogMonitorOPS.RegisterNotification test id:#test -- register the monitor
dialogMonitorOps.enabled = true -- enable the monitor
exportFile "c:\ emp\\somefile.obj" -- pop up the obj export config dialog (see above function for what happens next)
dialogMonitorOPS.UnRegisterNotification id:#test -- remove the monitor
dialogMonitorOps.enabled = false -- disable the monitor
Edit: “Without further adue”? Adieu? Ado!
Thanks ZeBoxx2, you are always so helpful
I could get a little clue of your script, however, I still can not make it run. As I guess, just simple run script and It automatically create a obj file in c:\ emp\somefile.obj, however Max still show the dialog for me as usual.
So where I am wrong :curious:
Thanks
Also I am using Max9 because client require it. However I have tested with Max 2008 and see nothing change too
well, let’s tackle 3ds Max 9 first -_-
Looks like its dialog is a bit different…
The dialog’s title is “OBJ Exporter” the button is “OK”.
There’s no error dialog, and no progress dialog…
And 3ds Max 9 doesn’t support “windows.getChildrenHWND”.
So…
Edit: 3ds Max 9 / 3ds Max 2008 only. For 3ds Max 2009, see earlier post!
global BN_CLICKED = 0 -- clicky message ID
global BM_SETCHECK = 241 -- checkbutton toggle message ID
global WM_COMMAND = 273 -- windows command message
dialogMonitorOPS.UnRegisterNotification id:#test -- remove any old instance
fn test = (
hwnd = DialogMonitorOPS.GetWindowHandle() -- check the dialog that popped up
hwnd_title = UIAccessor.GetWindowText hwnd
if (hwnd_title == "OBJ Exporter") then ( -- the obj export config dialog
local flipControl_hwnd = undefined
local flipControl_parent_hwnd = undefined
local controls = UIAccessor.GetChildWindows hwnd -- get all controls for this dialog
for c in controls do (
if (UIAccessor.GetWindowText c == "Use &materials") then (
flipControl_hwnd = c
flipControl_parent_hwnd = UIAccessor.GetParentWindow c
exit
)
)
local flipControl_id = UIAccessor.GetWindowResourceID flipControl_hwnd
windows.sendMessage flipControl_hwnd BM_SETCHECK 1 0 -- check the 'Use materials' options. Set to '0 0' to uncheck it.
windows.sendMessage flipControl_parent_hwnd WM_COMMAND ((bit.shift BN_CLICKED 16) + flipControl_id) flipControl_hwnd
-- REMOVE THIS WHEN CONFIDENT THINGS WORK
sleep 3 -- let's sleep here for a bit so you can check if that checkbox got checked
-- /REMOVE THIS WHEN CONFIDENT THINGS WORK
UIAccessor.PressButtonByName hwnd "OK" -- press the OK button
) -- hwnd_title == "OBJ Exporter"
true
)
dialogMonitorOPS.RegisterNotification test id:#test -- register the monitor
dialogMonitorOps.enabled = true -- enable the monitor
exportFile "c:\ emp\\somefile.obj" -- pop up the obj export config dialog (see above function for what happens next)
dialogMonitorOPS.UnRegisterNotification id:#test -- remove the monitor
dialogMonitorOps.enabled = false -- disable the monitor
Compare the two scripts to see what’s changed where… now for 2008 I’ll have to boot up the Vista machine
Edit: Looks like 3ds Max 2008 uses the same obj export bits as 3ds Max 9… so you should be all set
Thanks for your help.
I could get nearly all info except some point
windows.sendMessage flipControl_parent_hwnd WM_COMMAND ((bit.shift BN_CLICKED 16) + flipControl_id) flipControl_hwnd
What does it do… the bit.shift BN_CLICKED command really drive me out of the code I have got
*Edited: nevermind, I figure it out in your previous post…
Also how about a dropdown box. I want to choose triangle as option for faces option, but it is a dropdown and can not use checkbutton method
I nearly finish the export tool, except the option for choose triangle tris :)…
If you could, please share how to control the option box too…
Thanks
It sends a WM_COMMAND message to flipControl_parent_hwnd, notifying that a click (BN_CLICKED) event occurred on flipControl_id as owned by flipControl_hwnd.
The reason we have to tell the dialog that the control was clicked in addition to changing its checked state is because changing the checked state doesn’t automatically cause the code behind it to be run.
Compare this to maxscript rollout items… you can change the spinner value:
<spinner>.value = <some value>
But that won’t run the code:
on <spinner> changed val do ( )
You still have to invoke that yourself:
spinner.changed spinner.value
As for the listbox – that gets a bit more difficult…
==========
Then again… looks like 3ds Max 9 -does- have a config file which it re-uses… look in:
“c:\Documents and Settings\USERNAME\Local Settings\Application Data\Autodesk\3dsmax\9 – 32bit\enu\plugcfg\max2obj.cfg”
( default folder for english version )
Similar for 3ds Max 2008… still not seeing one for 3ds Max 2009, though.
Though I’m not sure where you need to use the script… if it’s only local, then you should be all set with that config file. If you need it on user’s machines, then I can see about that dropdownlist (or you’d have to tell your users to copy that config file / set it up once before using the script… presuming they don’t change it again afterwards)
Edit: Err… or just edit the config file using setIniSetting, of course -_-
Yes, I know the config is save and we could re-use it. But in production we want to make sure no wrong file is submitted, so the script to force out an obj is best
Now I only have 2 option left:
- Select triangle
- Select scene material
Or the easier way is open cfg file and write to it with our desired data. However I get no way to get in that folder and open it for edit