Batch / List names from my layers.

Hi, I'm quite new at scripting, and I haven't found yet what i'm looking for.

So i'm asking for tips or even part of codes to get me in the way.

I'd like to list the names of every single object of specifics layers
(layers with a prefix "XX" for exemple).

And get that list in an external .txt format.

It should look like

XX_Layer_name1 (5 objets) :
-------------------------------
Box001
Box002
Box003
Box004
Box005

XX_Layer_name2 (5 objets) :
-------------------------------
Box001
Box002
Box003
Box004
Box005

Thank's in advance.

alex

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
a1ex1s's picture

.

deleted

a1ex1s's picture

Awesome thank you so much for

..deleted..

barigazy's picture

...

This is your fn
BTW empty layers are not printed in *.txt

fn printAllLayerContentInTxt txtFile =
(
	local printArr = #()
	for i = 0 to LayerManager.count - 1 do
	(
		layer = (LayerManager.getLayer i).layerAsRefTarg
		nodes = refs.dependentNodes layer
		if (nCnt = nodes.count) != 0 do
		(
			append printArr (layer.name + " (" + nCnt as string + " objects) :")
			append printArr "-------------------------------"
			for n = 1 to nCnt do append printArr nodes[n].name
		)
	)
	if printArr.count != 0 do ((dotnetclass "System.IO.File").WriteAllLines txtFile printArr ; free printArr)
)
printAllLayerContentInTxt @"c:\temp\Layers Content.txt"

bga

a1ex1s's picture

Repost of the answer.

Awesome thank you so much for your help mate, it works perfectly!

Can I ask few a few things more,

How could I specify in this function, to check only specific layers.
I would like to print objects from layers with a specific Prefix. Because I work on heavy scenes with loads of objetcs and I don't need to have everything.

Also,what If I would like it to print my objects names, with ";" instead of "_" in my txt file.
I think it might be a $string replace, but i'm clueless due my lack of knowledge in MS.

Again, thank you for your time, much appreciated.
Cheers

barigazy's picture

...

I didn't test this but concept is good

fn printAllLayerContentInTxt txtFile _layerPrefix: _replace: _with: =
(
	local printArr = #()
	for i = 0 to LayerManager.count - 1 do
	(
		layer = (LayerManager.getLayer i).layerAsRefTarg
		nodes = refs.dependentNodes layer
		if (nCnt = nodes.count) != 0 do
		(
			if MatchPattern layer.name pattern:_layerPrefix ignorecase:on do 
			(
				append printArr (layer.name + " (" + nCnt as string + " objects) :")
				append printArr "-------------------------------"
				if _replace == unsupplied and  _with == unsupplied then
				(
					for n = 1 to nCnt do append printArr nodes[n].name
				)
				else
				(
					for n = 1 to nCnt do 
					(
						objName = substituteString nodes[n].name _replace _with
						append printArr objName
					)
				)
			)
		)
	)
	if printArr.count != 0 do ((dotnetclass "System.IO.File").WriteAllLines txtFile printArr ; free printArr)
)
printAllLayerContentInTxt @"c:\temp\Layers Content.txt" _layerPrefix:"XX_*" _replace:"_" _with:"."

bga

a1ex1s's picture

Perfect!

You're a life saver! Thank you so much barigazy , it works like a charm !

Cheers

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.