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

it's true, thanks you :)

it's true, thanks you :)

AttachmentSize
arbo.png 134.26 KB
vusta's picture

File upload error..

this comes and goes...sometimes I waited til next day..it then worked...

or simply upload pic somewhere that's bombproof...then just paste the link here...

Gnn's picture

Yo mawou, thanks for all the

Yo mawou, thanks for all the explanations and the video you made, you're the boss! but as me, it's not possible to select layers inside another layer? this: ".nodes &objsArr" doesn't collect layers also?

fn SelectObjectsInLayer layerName: = -- list of layers founed to founded in the layer "Clones":
(
local objsArr
(LayerManager.getLayerFromName layerName).nodes &objsArr --is it possible to filter only the layers founded (first childs)?
objsArr -- return the selected layer
)
objsInLayerArr = SelectObjectsInLayer layerName:"Props"
select objsInLayerArr -- here the layers aren't selected

miauu's picture

.

I thought that you want to select only the objects in the layer, not the objects in the nested layers.

Can you post an image to show how your layers are organized and which objects do you want to be selected?

Gnn's picture

--HEllo MIIAU, sOrry Again

--HEllo MIIAU, sOrry Again and Again, but as i'd never work without js in softimage , and it's the last script that i need, i feel totaly lost in maxscript ...
-- About operations on layers, nothing appened, what did i miss? i thought "SelectObjectsInLayer" will select childs, but no.. (ligne 12)
-- it's possible to use the sign OR in this way in maxscript? (ligne 28)
-- why is my mergeMaxFile variable false? (ligne 31)
-- always my probleme to select a layer... (ligne 35)
-- Can you tell to me the way to put a variable string in a selection set? (ligne 41)
-- how to write and save a message log (in a.txt file)? (ligne 46)
fn SelectObjectsInLayer layerName: = -- list of layers founed to founded in the layer "Clones":
(
local objsArr
(LayerManager.getLayerFromName layerName).nodes &objsArr --is it possible to filter only the layers founded (first childs)?
objsArr -- return the selected layer
)
objsInLayerArr = SelectObjectsInLayer layerName:"Props" -- here nothing appened
select (
if objsInLayerArr.count != 0 do
(
for o in objsInLayerArr do
(
arrAsset = (o.name)[1] -- find the first letter of the layer's child name
if arrAsset == "" do
(
strArr = filterString o.name "_"
arrNum = strArr[strArr.count - 1] -- find the Number of the layer's child name (NameAsset)
arrName = strArr[1] -- find the Name of the layer's child name (NameAsset)
if arrAsset == "A" do
(
Mergepath = "Z:\\LL_common\\models\\A_MP_Persos\\"
if (arrNum != "") || (arrName != "") do
(
arrNum2 = arrNum[slice 2] -- slice the 2 first digits (arrNum=A001 > arrNum2=01)
mergeMaxFile @"+Mergepath+"MP_"+arrNum2+"_"+arrName+"\AutoRIG\"+o.name+".max" #select #neverReparent #autoRenameDups #useMergedMtlDups missingDLLsAction: #default quiet:true
-- Path expected: mergeMaxFile @"G:\models\A_MP_Persos\MP_01_Danael\A001_Danael.max" #select #neverReparent #autoRenameDups #useMergedMtlDups missingDLLsAction: #default quiet:true
layer = LayerManager.getLayerFromName "Characters" -- find layer Characters
for n in (selection as array) do layer.addNode n -- put the mergeMaxFile in layer "Characters"
)
NewMaster = arrName + "_Setup_Ctrl_MasterWalk_C_O_G" -- New Master
OldMaster = "Old_"+arrName+"_A0_"+arrName+"_Master" -- old Master
)
)
select (#() + $NewMaster + $OldMaster) --how to select 2 strings variables?
for n in (selection as array) do n.isFrozen = False --unFrozen selection
for n in (selection as array) do n.isHidden = False --unHide selection
NewMaster.transform = OldMaster.transform --align masters
)
else ( print " Asset not find ! " + layerName) -- write and save a message log (in a.txt file)?
)
)

miauu's picture

.

(
	fn SelectObjectsInLayer layerName: = -- list of layers founed to founded in the layer "Clones":
	(
		local objsArr
		(LayerManager.getLayerFromName layerName).nodes &objsArr --is it possible to filter only the layers founded (first childs)?
		objsArr -- return the selected layer
	)
	objsInLayerArr = SelectObjectsInLayer layerName:"Props" -- here nothing appened
	select objsInLayerArr
	if objsInLayerArr.count != 0 do
	( 
	-- 	logFile = createFile @"D:\\LogFile.txt"
		for o in objsInLayerArr do
		( 
			NewMaster = undefined
			OldMaster = undefined
			arrAsset = (o.name)[1] -- find the first letter of the layer's child name
			if arrAsset == "" do
			(
				strArr = filterString o.name "_"
				arrNum = strArr[strArr.count - 1] -- find the Number of the layer's child name (NameAsset)
				arrName = strArr[1] -- find the Name of the layer's child name (NameAsset)
				if arrAsset == "A" do
				(
					Mergepath = "Z:\\LL_common\\models\\A_MP_Persos\\"
					if (arrNum != "") or (arrName != "") do
					(
						arrNum2 = arrNum[slice 2] -- slice the 2 first digits (arrNum=A001 > arrNum2=01)
						--	WRONG SYNTAXIS
	-- 					mergeMaxFile @"+Mergepath+"MP_"+arrNum2+"_"+arrName+"\AutoRIG\"+o.name+".max #select #neverReparent #autoRenameDups #useMergedMtlDups missingDLLsAction: #default quiet:true
						--	THIS IS CORRECT
						mergeMaxFile (Mergepath + "MP_"+arrNum2+"_"+arrName+"\\AutoRIG\\"+o.name+".max") #select #neverReparent #autoRenameDups #useMergedMtlDups missingDLLsAction:#default quiet:true
						--	CHECK IF THERE ARE SELECTED OBJECTS BEFORE TO CONTINUE
						if selection.count != 0 then
						(
							-- Path expected: mergeMaxFile @"G:\models\A_MP_Persos\MP_01_Danael\A001_Danael.max" #select #neverReparent #autoRenameDups #useMergedMtlDups missingDLLsAction: #default quiet:true
							layer = LayerManager.getLayerFromName "Characters" -- find layer Characters
							for n in (selection as array) do layer.addNode n -- put the mergeMaxFile in layer "Characters"
						)
						else
							messagebox "No objects are selected/merged" title:""
					)
					--	if NEWMASTER and OLDMASTER are objects then convert strings to actual nodes
					NewMaster = getNodeByName (arrName + "_Setup_Ctrl_MasterWalk_C_O_G") -- New Master
					OldMaster = getNodeByName ("Old_"+arrName+"_A0_"+arrName+"_Master") -- old Master
				)
			)
			if NewMaster != undefined and OldMaster != undefined do
			(
				select #(NewMaster, OldMaster) --how to select 2 strings variables?
				for n in (selection as array) do n.isFrozen = False --unFrozen selection
				for n in (selection as array) do n.isHidden = False --unHide selection
				NewMaster.transform = OldMaster.transform --align masters
			)
		)
 
		--	THIS CAN"T BE USED HERE. USE IT WHERE YOU WANT TO CHECK IF THE ASSED IS FOUND OR NOT
	-- 	else 
	-- 	(
			--	print " Asset not find ! " + layerName
	-- 		format "Asset not find ! %\n" layerName to:logFile
 
	-- 	) -- write and save a message log (in a.txt file)?
	-- 	close logFile
	)
)

Watch this video to see that the part of the script that selects the objects in the layer works properly: https://dl.dropboxusercontent.com/u/35093423/Other/Videos/Layrs_001.mp4

Gnn's picture

hello again and thanks to be

hello again and thanks to be so patient,
do you know how to call a script inside another one, like in .js the command: Application.ExecuteScript ( oScriptPath + "MakeScript.js")
and what do you think aboutBatch it Max? it don't look to make the job??
Do you know another way to run a script in batch in severals scenes at once, and save them like it?

miauu's picture

.

To run a script inside another one you have to use the FILEIN command.

fileIn @"C:\\MyScripts\\HideAllObjects.ms"

Batch in 3dsMax works ok. There are a lot of scripts in the forum that uses Batch to do differnet kind of tasks.

Gnn's picture

Hello Miaou, Since i'd tryied

Hello Miaou,
Since i'd tryied this, and all my problems seems to be gone with mergeMaxFile :

mergeMaxFile @"Z:\LL_common\models\A_MP_Persos\MP_01_Danael\AutoRIG\A001_Danael.max" #select #neverReparent #autoRenameDups #useMergedMtlDups missingDLLsAction: #default quiet:true

thanks a lot, again for for your patience,
but do you know why nothing appened when i try to move the layers? it answer me: OK and make nothing
i think i miss something very simple and essential...because i like your idea to make the script faster like doing object mode:

(
-- get the objects from the layer with the name "Layer001"
fn SelectObjectsInLayer layerName: =
(
local objsArr
(LayerManager.getLayerFromName layerName).nodes &objsArr
-- return the selected objects
objsArr
)
objsInLayerArr = SelectObjectsInLayer layerName:"Props"

-- move those objects to a layer with the name "Layer002"
layer = LayerManager.getLayerFromName "Clones"
for n in (selection as array) do layer.addNode n
)

miauu's picture

.

Your code for moving objects in Clones layer not works, because the script moves only the selected objects. If no objects are selected then there will be no moved objects.

If you want to move the objects, selected from the Props layer, then see the code below.

(
	-- get the objects from the layer with the name "Layer001"
	fn SelectObjectsInLayer layerName: =
	(
		local objsArr
		(LayerManager.getLayerFromName layerName).nodes &objsArr
		-- return the selected objects
		objsArr
	)
	objsInLayerArr = SelectObjectsInLayer layerName:"Props"
 
	-- move those objects to a layer with the name "Layer002"
	layer = LayerManager.getLayerFromName "Clones"
	--	if you do not have selected objects then no objects will be moved to the Clones layer using the code in the next line
-- 	for n in (selection as array) do layer.addNode n
	--	if you want to move the objects, selected from the Props layer, then you have to use
	for n in objsInLayerArr do layer.addNode n
)

Comment viewing options

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