Script for batch export

Become a member of the CGSociety

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

Thread Tools Search this Thread Display Modes
  12 December 2013
Nothing better than reading the code of others to learn to program.

"namePos = substring layerName (layerName.count-1) 2"

<string>substring <string> <from_integer> <length_integer>
Returns a new string consisting of the substring in string starting at index from_integer, and of length length_integer. If the sum of from_integer and length_integer is greater than the length of string, a shorter string is returned containing as many characters as are available in the source. If a negative value is specified for length_integer, the remainder of the string starting from from_integer is returned.

if layerName = "esp_b2av4q_hp"
then layerName.count returns 13
and layerName.count -1 = 12, so
"substring layerName 12 2" = "hp"
Fernando Ferro
  12 December 2013
Clear (I think),
so if I add a new layer category, for example "esp_blabla_nurbs" conteining the nurbs version of the model I should add a new variable
"namePosBis = substring layerName (layerName.count-4) 5"


"if ((substring layerName 1 3 == "esp") and ((namePos == "hp") or (namePos == "lp") or (namePosBis = "nurbs"))) do ...
  12 December 2013
Yes, you are right:
Inside this "if" sentence, all layers starting with "esp" and ending with "lp" or "hp" or "nurbs" will do "something".
Fernando Ferro
  07 July 2014
Hi Mr. Ferro!

Can you tell me please the reason why of this errore message?

This is the code (your code) I launch:

 -- '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 =
 			namePos = substring layerName (layerName.count-4) 5
 			if ((substring layerName 1 3 == "esp") and (namePos == "nurbs")) do (
 -- if layers name starts with "esp" and end with "nurbs" 
 				select theNodes
 				fileName = substring layerName 5 (layerName.count-4)
 				exportFile (theDir + "\\" + fileName + ".3dm") #noprompt selectedOnly:true
 		free theNodes

This is the errore message:

-- Error occurred in k loop; filename: ; position: 462; line: 11
--  Frame:
--   namePos: undefined
--   theNodes: #($lh_1_base07, $lh_1_base06, $lh_1_base05, $lh_1_base04, $lh_1_base03, $lh_1_base02, $lh_1_base01, $lh_1_base00, $lh_1_anta, $lh_1_struttura)
--   k: 1
--   filename: undefined
--   layer: <MixinInterface:LayerProperties>
--   layername: "lh_1"
-- Runtime error: substring start out of range: 0

The layer I need to export are called "esp_lh_1_nurbs" ; "esp_lh_2_nurbs"; "esp_lh_v_nurbs".

Thank you in advance!!!
  07 July 2014
Hi Ossosso, good to know about you.

In your example:
The variable "Layername" has a four chars name "lh_1".
The sentence: "substring layerName 5 (layerName.count-4)" tries to pick the fifth char of the var, but there isn't. So...

I have replicated your example in a new fresh scene:
just 1 new layer named: "esp_lh_1_nurbs" with just 1 box inside it. The script worked like a charm.
May be you has a layer with a wrong (too short) name?
Fernando Ferro
  07 July 2014
Hi Ferro,
happy to write you again

Yes it works now... mha.... I don't understand... I manage a scene, then I run the script to export... then I reset and open a new scene to manage, then again I run the script to export the new models... after some times I manage more scenes the script returns some errors, it seems like some variable is stored... the software remembers... the software is alive... I can hear the software softly laughing while I'm in troubles....
  07 July 2014
I run other similar scirpts on the base of this one you written for me... maybe they can annoying each other, mha
  07 July 2014
You are right. The script is not bulletproof. To do so you have to work a little about variable scope and this kind of stuff.
For know it's implemented to use it once.
If you have to run it a lot of times or in conjunction with similar scripts, is better not to use the same names for variables or reset max from time to time.
Fernando Ferro
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
Society of Digital Artists

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

All times are GMT. The time now is 10:10 PM.

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