S.O.S!!!

Hi,
I'm very new with maxscript,
and i need to deconcatenate (with split and slice?? like in js) some strings
and unfortunatly, i'don't have any idea how to do that:

--1 make a collection of all obj in the scene named "*_Master":

for h in $*_Master do print h.name

-- i obtain a list:
--"A135_gg_PersoName_Master"
--"B256a_AnimName_a_gg_Master"
--"B256a_AnimName_a_gg_Master"
--"B256a_AnimName_a_gg_Master"

-->2 i need to keep only the fisrt letter: "A" or "B" of each obj founded
-->3 make a condition: if it's A: split "_" to obtain: "PersoName"
-->4 find this PersoName folder and import it

if anyone can help me with this, it would be geat because i'm lost :(

Comments

Comment viewing options

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

Hello again Miauu, I'd tryied

Hello again Miauu,
I'd tryied your last script and wonderfull video about moving layers, and it's working, except when i've got nested layers inside others layers... it's seams to be difficult to move layers exact sub hierarchy and contained nodes?

Gnn's picture

I can't attach you a jpg or

I can't attach you a jpg or png of 57K, the answer is: File upload error. Could not move uploaded file... there's another way?
yes, i need to select only layers inside another layers,
for example all the layers childs of the layer named "Characters"
and put them in another and keep their hierachy,
the same problem arrive when i want to put the parent of a merged max file, all is in mess because i can't select just the layer :(

MergeAsset=#("G:\models\A_MP_Persos\MP_05_Gryff\AutoRIG\A005_Gryff.max")
with undo off with redraw off
(
for i in MergeAsset do
(
clearselection()
local newlay = LayerManager.getLayerFromName "Characters"
mergeMaxFile i #select #autoRenameDups #useMergedMtlDups quiet:true
for i in selection do newlay.addnode i
)
)
newParent = LayerManager.getLayerFromName "Props"
(LayerManager.getLayerFromName "Clones").setParent newParent

miauu's picture

.

The code below will move all nested layers from the layer with the name "Characters" to a layer with the name "New_Layer". The "New_Layer" must exist.

(
	--	"the name of the layer whose nested have to be moved"
	mainLayerName = "Characters"
	--	"get the main layer"
	mainLayer = LayerManager.getLayerFromName mainLayerName
	--	"the layer where to put the nested layers from the main layer"
	targetLayerName = "New_Layer"
	--	"the target layer exist, so get it. Or create it if it not exist"
	targetLayer = LayerManager.getLayerFromName targetLayerName
 
	fn GetObjectsInLayer layer: =
	(
		local objsArr
		layer.nodes &objsArr
		-- return the objects
		objsArr
	)	
 
	--	"check if the main layer have nested layers"
	numChildLayers = mainLayer.getNumChildren()
	if numChildLayers != 0 then
	(
		--	"have nested layers"
		--	"for each nested layer..."		
		for i = 1 to numChildLayers do
		(
			--	"get the nested layer"
			nLayer = mainLayer.getChild i
			nLayerName = nLayer.name
			--	"get the objects in this layer"
			objsInnLayerArr = GetObjectsInLayer layer:nLayer
			--	"recreate the nested layer in the target layer. You can't have two layers with the same name, 
			--	"so the moved layers will have the _cloned suffix."
			clonedLayer = LayerManager.newLayerFromName (nLayerName + "_cloned")
			for n in objsInnLayerArr do clonedLayer.addNode n
			--	"make the cloned layer nested to the main layer"
			clonedLayer.setParent targetLayer
		)
	)
	else
	(
		--	"no nested layers. Possibly only objects"
 
	)
)
Gnn's picture

Thank you for your infinite

Thank you for your infinite patience, the video, and all your explanations, as soon as I have a little time I'll retent it, for the moment I just give you a donation, it is convenient your system of paypal, bravo mec!!

miauu's picture

.

Thank you.
I saw the donation before this post and sent you a mail to ask about the donation, but now I know who is the donator.

Gnn's picture

you welcome, viva Bulgaria :)

you welcome, viva Bulgaria :)

Gnn's picture

it's strange, i've got always

it's strange, i've got always the same problem, it's working for you?
if i'v got severals childs in the layer, it tells me:
-- Unknown property: "name" in undefined
if i try this:

mainLayer = LayerManager.getLayerFromName "Props" -- "get the main layer"
targetLayer = LayerManager.getLayerFromName "Clones" -- "the target layer exist, so get it. Or create it if it not exist"

fn GetObjectsInLayer layer: =
(
local objsArr
layer.nodes &objsArr
objsArr -- return the objects
)
numChildLayers = mainLayer.getNumChildren() -- "have nested layers"
if numChildLayers > 0 then
(
print numChildLayers
for i = 1 to numChildLayers do -- "for each nested layer..."
(
nLayer = mainLayer.getChild i -- "get the nested layer"
print nLayer
nLayerName = nLayer.name -- "get the objects in this layer"
print nLayerName
objsInnLayerArr = GetObjectsInLayer layer:nLayer
nLayer.setParent targetLayer
)
)

the answer is:

-- In i loop; filename: F:\la_station\manue\UTILS\MoveNestedLayer.ms; position: 679; line: 19
-- member of: anonymous codeblock
-- Parameters:
-- i: 2
-- Locals:
-- objsInnLayerArr: undefined
-- nLayer: undefined
-- nLayerName: undefined
-- i: 2
-- Externals:
-- targetlayer: Global:targetlayer :
-- mainLayer: Global:mainLayer :
-- owner:
-- GetObjectsInLayer: Global:GetObjectsInLayer : GetObjectsInLayer()

Gnn's picture

Thank you maou, it's almost

Thank you maou,
it's almost perfect!!! there is only one problem, it's when there's is more than 1 child, it can't find the name of the last nested layer, and retun "undefined" and so don't do anything... ther's another way to do: nLayer = mainLayer.getChild i ?
or may be it's the cycle: if numChildLayers > 0 then ?

mainLayer = LayerManager.getLayerFromName "Props" -- "get the main layer"
targetLayerName = "Clones" -- "the layer where to put the nested layers from the main layer"
targetLayer = LayerManager.getLayerFromName targetLayerName -- "the target layer exist, so get it. Or create it if it not exist"

fn GetObjectsInLayer layer: =
(
local objsArr
layer.nodes &objsArr
objsArr -- return the objects
)
numChildLayers = mainLayer.getNumChildren() -- "have nested layers"
if numChildLayers > 0 then
(
for i = 1 to numChildLayers do -- "for each nested layer..."
(
nLayer = mainLayer.getChild i -- "get the nested layer"
print nLayer
nLayerName = nLayer.name -- "get the objects in this layer"
objsInnLayerArr = GetObjectsInLayer layer:nLayer
nLayer.setParent targetLayer
)
)

miauu's picture

.

The code that I posted above works. Please, watch this video:

https://dl.dropboxusercontent.com/u/35093423/Other/Videos/Clone_Layers_0...

Comment viewing options

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