Script for batch export

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

REPLY TO THREAD
 
Thread Tools Search this Thread Display Modes
Old 12 December 2013   #1
Script for batch export

Hi!
I've orginized my scene in layers, each layer conteins a series of objects. What I have to do is to export in different file formats (.3ds, .dwg, .obj) each layers separetly, and the same name of the layer

The process is quite tedious and mechanic. How can I solve in an automatic way?
Thanks a lot.

The next step is to export each object in a separate file in different formats (.3ds, .dwg,..obj)
 
Old 12 December 2013   #2
Simple if you know a little of maxscript.
from the help file:

HTML Code:
for i = 0 to layerManager.count-1 do ( ilayer = layerManager.getLayer i layerName = ilayer.name layer = ILayerManager.getLayerObject i layerNodes = refs.dependents layer format "Layer: %; nodes: %\n" layerName layerNodes )

layerNodes in format line contains all the nodes in layerName layer.
So, you just have to add the export sentence below that line.
Best
__________________
Fernando Ferro
www.reconstruccionvirtual.com
 
Old 12 December 2013   #3
This is what you need:
-- exportObjsByLayer.ms
 -- 'noprompt' does not allow you to set the output settings. So to do this, you need to export once manually before running this script.
 
 -- to set the output folder change next line --
 theDir = getDir #export
 
 undo off with redraw off for k=1 to LayerManager.count-1 do (
 		layer = LayerManager.getLayer k
 		layer.nodes &nodes
 		exportFile (theDir + "\\" + layer.name + ".dwg") #noprompt electedOnly:true
 		exportFile (theDir + "\\" + layer.name + ".3ds") #noprompt electedOnly:true
 		exportFile (theDir + "\\" + layer.name + ".obj") #noprompt electedOnly:true
 )
    
__________________
Fernando Ferro
www.reconstruccionvirtual.com
 
Old 12 December 2013   #4
hi man! Sorry if I answer in late.

thanks a lot for your support!

You're right, a bit of script knowledge everyone should have .. but you know... for those like me who doesn't work inside a big studio and I have to follow each step of the workflow it's hard to manage each subject.

Anyway I thank you very very much. Your script works correctly and allows me to make faster the workflow.

I would need some improvement in the script so I would ask you if I can contact you via mail or any other method. For example the script should export only selected objects, and each object of the layer in a separate file, things like that.
Obviously I don't want to ask your service for free.

Let me know if you are available.
Thanks again!
 
Old 12 December 2013   #5
Ah well.. I suppose that to export the selected objects only cna be solved adding the "s" to your script
 
Old 12 December 2013   #6
if I understand the "for" cycle does a number of exports equal to the number of layer in the scene, from the first to the last one.
What I'd like instead is: select objects into a layer and export (in the 3 formats) only the objects with the layer names, while the for cycle export again the objects also with the other layers name in other files... it's harder to explain that to understand
 
Old 12 December 2013   #7
Hi ossosso,
Like you, I work alone and sometimes suits me help others like me.
Let me know all what you need and I'll post the script here for everyone.
Best
__________________
Fernando Ferro
www.reconstruccionvirtual.com
 
Old 12 December 2013   #8
Ok, I try. Thank you in advance

1)
http://www.ossosso.com/scambio/shoot_01.JPG

you can see 12 objects selected inside a layer called "esp_b2av4q_hp", "b2av4q" is the code of the product, "esp" stays for "export" because the geometry inside that layer is ready to be exported (no modifiers on it, reset transform and so on..) and "hp" stays for "high poly".
The same version of the model is in "low poly":
http://www.ossosso.com/scambio/shoot_02.JPG

and also in nurbs but doesn't matter nurbs for now.

2)
Once the models (hp and lp) are ready, I have to export in the three format .3ds, .dwg and .obj. And in the computer folder this is the result:
http://www.ossosso.com/scambio/shoot_03.JPG
(nb. I have to add also a .max format for the only lp version with the "save selected" command, but if this complicates the script I can do it manually)

3)
So the final task is to select the objects of one layer (ex: "esp_b2av4q_hp")-->run the script-->output inside a folder the files esp_b2av4q_hp.3ds/esp_b2av4q_hp.obj/esp_b2av4q_hp.dwg

That's all
Two things:
1-about the file name, it can be the same as layer name, then with a nice software (bulk raname) I can easily eliminate the "esp_" prefix for all
2-In this way I should run the script each time for each layer and this is enough good because it save me a lot of time.. but.. if there is a way could be great to do it at once, I mean: unhide only the layers I need to export, select all the objects of the unhidden layers and run the script obteining that:

http://www.ossosso.com/scambio/shoot_04.JPG

I hope I was clear enough.
Again I thank you for your useful support.
 
Old 12 December 2013   #9
This script will save all nodes in each layer starting with "esp" and ending with "lp" or "hp".
It's not possible to know which layer is selected in the layer manager. So, I don't know how to do the same to just one layer.
Warning: All new files will overwrite existing files in the same directory.


 -- exportObjsByLayer.ms
 -- 'noprompt' does not allow you to set the output settings. So to do this, you need to export once manually before running this script.
 -- to set the output folder change next line --
 theDir = getDir #export
 
 undo off with redraw off for k=1 to LayerManager.count-1 do (
 		layer = LayerManager.getLayer k
 		layer.nodes &theNodes
 		if theNodes.count > 0 do (
 			layerName = layer.name
 			namePos = substring layerName (layerName.count-1) 2
 			if ((substring layerName 1 3 == "esp") and ((namePos == "hp" ) or (namePos == "lp" ))) do (
 -- if layers name starts with "esp" and end with "hp"  or "lp"
 				select theNodes
 				fileName = substring layerName 5 (layerName.count-4)
 				exportFile (theDir + "\\" + fileName + ".dwg") #noprompt selectedOnly:true
 				exportFile (theDir + "\\" + fileName + ".3ds") #noprompt selectedOnly:true
 				exportFile (theDir + "\\" + fileName + ".obj") #noprompt selectedOnly:true
 				saveNodes selection (theDir + "\\" + fileName + ".max") quiet:true
 			)
 		)
 		free theNodes
 )


Save all code in a .ms file and run it from Maxscript > Run Script...
Best
__________________
Fernando Ferro
www.reconstruccionvirtual.com
 
Old 12 December 2013   #10
You are the best man
It works, and it save me a lot of time.

Please, give me your paypal account, allow me to make a donation.

Last edited by ossosso : 12 December 2013 at 04:11 PM.
 
Old 12 December 2013   #11
The export settings are stored in an .ini file.
For Obj the name is: gw_objexp.ini
Look for it in your Local Settings directory for MAX.
In my case: C:\Documents and Settings\Administrator\Local Settings\Application Data\Autodesk\3dsMax\2010 - 64bit\enu\plugcfg\
Once you export, the new settings are stored in this file. So, when you export another time it should reflect the last edited settings. May be you have a problem with permissions to access this file.
The script could edit this file too, but it's simpler to edit it manually.
So, you should change the third line like this: Preset=Rhino
If this is not enough to the flipping axis, change this one too: FlipZyAxis=1
Best
__________________
Fernando Ferro
www.reconstruccionvirtual.com
 
Old 12 December 2013   #12
You red the post that I've modified, I've solved about .obj modifing the "None" preset with settings I need and it works.

But in my modifed post I've asked your paypal account for a donation.
 
Old 12 December 2013   #13
fernando ferro fferro@hotmail.com

Thank you very much. This will be my Christmas present
Best
__________________
Fernando Ferro
www.reconstruccionvirtual.com
 
Old 12 December 2013   #14
Now saves the nodes in each layer in a .max file
Also creates a thumbnail of these nodes

-- exportObjsByLayer.ms
 -- 'noprompt' does not allow you to set the output settings. So to do this, you need to export once manually before running this script.
 -- set the render settings and activate the desired viewport before running this script
 -- Note: all nodes will be unhide at the end
 
 -- to set the output folder change next line --
 theDir = getDir #export
 
 rendShowVFB = off
 rendSaveFile = on
 	
 max unhide all
 
 undo off with redraw off for k=1 to LayerManager.count-1 do (
 		layer = LayerManager.getLayer k
 		layer.nodes &theNodes
 		if theNodes.count > 0 do (
 			layerName = layer.name
 			namePos = substring layerName (layerName.count-1) 2
 			if ((substring layerName 1 3 == "esp") and ((namePos == "hp" ) or (namePos == "lp" ))) do (
 -- if layers name starts with "esp" and end with "hp"  or "lp"
 				select theNodes
 				fileName = substring layerName 5 (layerName.count-4)
 				exportFile (theDir + "\\" + fileName + ".dwg") #noprompt selectedOnly:true
 				exportFile (theDir + "\\" + fileName + ".3ds") #noprompt selectedOnly:true
 				exportFile (theDir + "\\" + fileName + ".obj") #noprompt selectedOnly:true
 				saveNodes selection (theDir + "\\" + fileName + ".max") quiet:true
 				max hide inv
 				max zoomext sel
 				rendOutputFilename = theDir + "\\" + fileName + ".jpg"
 				max quick render
 				format "% de % \"%.max\" with % nodes\n" k (LayerManager.count-1) fileName selection.count
 			)
 		)
 		free theNodes
 )
__________________
Fernando Ferro
www.reconstruccionvirtual.com
 
Old 12 December 2013   #15
Hi Fernando!
Using your script and looking on the maxscript support website I've written this code


-- exportObjsByLayer.ms
 -- 'noprompt' does not allow you to set the output settings. So to do this, you need to export once manually before running this script.
 -- to set the output folder change next line --
 theDir = getDir #export
 
 undo off with redraw off for k=1 to LayerManager.count-1 do (
		 layer = LayerManager.getLayer k
		 layer.nodes &theNodes
		 if theNodes.count > 0 do (
			 layerName = layer.name
			 namePos = substring layerName (layerName.count-1) 2
			 if ((substring layerName 1 3 == "esp") and ((namePos == "hp" ))) do (
 -- if layers name starts with "esp" and end with "hp"  or "lp"
				 
				(LayerManager.getLayer k).on=true
				
				 fileName = substring layerName 5 (layerName.count-4)
				 f_name = theDir + "\\" + fileName + ".jpg"
				Render outputfile:f_name
				
				(LayerManager.getLayer k).on=false
				
				
			 )
		 )
		 free theNodes
 )


I need to create a thumbnail of each model, but insert inside a Lighting set, not a screenshot.
So I've created a .max scene containing some planes, lights and a camera in the "0 default" layer, merged all the layers (only _hp), hidden all of them and run the script.

It simply unhide the first one, launch the render, save the .jpg file and hide the render, then the next one and so on.

It seems correct because it works .

I've studied your script and I've understood each line, except for:
"namePos = substring layerName (layerName.count-1) 2"
I understand namePos is a variable containing the last two character of the layer name, but I don't understand in which way it take the last two... yes there is the number "2" but why not the first two? or two in the middle? how it understand the last two?

Anyway, thanks a lot!
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:06 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.