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

thanks a lot!!! do you know

thanks a lot!!!
do you know why max is merging the layers when merging similars max file? and how to avoid this?

Gnn's picture

maw

whaou! are you a human?
it's almost perfect, but it's opened the oldest scene, it's possible to inverse it, and get the newest instead?
do you know how to close the dialogue box after pressed the button?

i'v got only 2 others littles troubles and after it's hollidays for you and me :)
-- how to select a merged max file?
-- and skip messages box when merging a Max File : message box 1: objet :autorename -- message box 2: materiel: use merged materials
--i'd try this but nothing appened...
mergeMaxFile @"Z:\ModelPath\ModelName.max"; #select #autoRenameDups #useMergedMtlDups

--how to select all the first childs of a layer and put them in another?
layer.setname "LayerName"
select (#() + LayersChilds) -- ???
for n in (selection as array) do layer.addnode n

miauu's picture

.

The code that I post finds the last modified scene. I don't know why it not works for you. This is the part of the script that does the job:
lastModifiedDate = amax filesModDateArr
You can try this:
lastModifiedDate = amin filesModDateArr
to see which file will be selected. OR write your own function that will compare the results in the filesModDateArr and will find the last modified file.

-- how to select a merged max file?
To select mered objects you have to use the #select argument

-- and skip messages box when merging a Max File :
the quite:true argument

Using your code(there is no ; after the file path):

mergeMaxFile @"Z:\ModelPath\ModelName.max" #select #autoRenameDups #useMergedMtlDups quiet:true

--how to select all the first childs of a layer and put them in another?
To select the objects from layer with tha name "Layer001" use this:

(
	fn SelectObjectsInLayer layerName: =
	(
		local objsArr
		(LayerManager.getLayerFromName layerName).nodes &objsArr
		select objsArr
	)
	SelectObjectsInLayer layerName:"Layer001"
)

To put the selected objects in another layer(with name "Layer002") use this:

(
	layer = LayerManager.getLayerFromName "Layer002"
	for n in (selection as array) do layer.addNode n
)

By the way, there is no need to select objects when you have them stored in array. Selecting the objects in the script will selects the objects in the scene and this will slow down the speed of your script. For example, you can combine the two snipets above like this:

(
	--	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:"Layer001"
 
	--	move those objects to a layer with the name "Layer002"
	layer = LayerManager.getLayerFromName "Layer002"
	for n in (selection as array) do layer.addNode n
)
Gnn's picture

Hello miauu, sorry to had

Hello miauu,
sorry to had send you so much text last day, it was an error... when i want to open the scene by last modifaication date:

-- prompt user to ask a number of a plan
global LL_Layout
try(destroyDialog LL_Layout)catch()
rollout LL_Layout "Enter Layout Plan to open"
(
edittext plan_name "plan"
button open_plan "OPEN"

on open_plan pressed do
(
if plan_name.text != "" do
(
-- get the number entered and make a variables:
planName = plan_name.text
camName = "107_"+ planName
-- path for open scene:
LoadPath = getFiles ("C:\\Users\\manue\\Desktop\\la_station\\les_legendaires\\"+camName+"\\"+camName+"*.max")
-- open last scene by date founded:
if filesArr.count != 0 do
(
filesModDateArr = for f in filesArr collect (getFileModDate f)
lastModifiedDate = amax filesModDateArr
index = findItem filesModDateArr lastModifiedDate
lastModifiedFile = filesArr[index]
format "_indx: % \n" index
format "filesArr: % \n" filesArr[index]
format "filesModDateArr: % \n" filesModDateArr[index]
-- "works with the last modified file"
resetMaxFile #noPrompt
loadMAXFile lastModifiedFile quiet:true
)
)
)--end on
)--end rollout
createDialog LL_Layout 250 75

the answer is:

- [stack level: 0]
-- In open_plan.pressed(); filename: G:\manue\MaxButtons\OpenLastLayoutScene.ms; position: 594; line: 19
-- member of: Rollout:LL_Layout
-- Locals:
-- planName: "278"
-- filesArr: undefined
-- LoadPath: #("C:\Users\manue\Desktop\la_station\les_legendaires\107_278\107_278.max", "C:\Users\manue\Desktop\la_station\les_legendaires\107_278\107_278_v000.max", "C:\Users\manue\Desktop\la_station\les_legendaires\107_278\107_278_v1.max")
-- filesModDateArr: undefined
-- lastModifiedDate: undefined
-- lastModifiedFile: undefined
-- camName: "107_278"
-- index: undefined
-- Externals:
-- owner: Rollout:LL_Layout
-- LL_Layout: Rollout:LL_Layout
-- plan_name: RolloutControl:plan_name in rollout:LL_Layout : EditTextControl:plan_name

do you know why? thanks again :)

miauu's picture

.

What you post(and use) is not the script that I post earlierl. The error is on line 19.
The filesArr variable is not defined in your code. You have LoadPath variable(which collets all files). So, replace filesArr with LoadPath, or replace LoadPath with filesArr and test the script again.

Gnn's picture

i'm back

Hello again (and sorry to ask you again so much)can you help me one more time (and last?) do you know how to get the scene by last modifaication date?
and correct my bad language??

-- prompt user to ask a number of a plan
global LL_Layout
try(destroyDialog LL_Layout)catch()
rollout LL_Layout "Enter Plan to open"
(
edittext plan_name "plan"
button open_plan "OPEN"

on open_plan pressed do
(
if plan_name.text != "" do
(
-- get the number entered and make a variables:
planName = plan_name.text
camName = "108_"+ planName
-- path for open scene:
LoadPath = getFiles ("F:\\la_station\\A_FAIRE\\108\\"+camName+"\\"+camName+"*.max")
-- path for save as scene
SaveASPath = "C:\\Users\\manue\\Desktop\\la_station\\les_legendaires\\"+camName+"\\"
-- open last scene by date founded:
if LoadPath.count != 0 do
(
for f in LoadPath do
(
resetMaxFile #noPrompt
loadMAXFile f quiet:true
-- get the variable and make another:E
OldcamName = "Old_" + camName
extName = "_v000.max"
SaveFile = camName+extName
saveScene = SaveASPath + SaveFile
-- make folder:
-- "makeDir SavePath"

-- Renomme camName > Old_camName
select $camName
$.name = OldcamName
-- import the new cam and align postion and rotation on old cam
mergeMaxFile @"C:\Users\manue\Desktop\la_station\les_legendaires\SetupCamera.max";#select #autoRenameDups #useMergedMtlDups
macros.run "Coordinate System" "Coordsys_Local"
$cmra001_A_WORLD_001.pos = $OldcamName.pos -- align position
$cmra001_A_WORLD_001.rot = $OldcamName.rot --align rotation
-- and rotate it in rotation -90 en Z
rotate $cmra001_A_WORLD_001 (angleaxis -90 [0,0,1])
-- rename the new cam > camName
select $cmra001_H_camera_001
$.name = camName
-- select the oldCam and more to create a new layer called > Old_cam
select #($Old_108_242, $'Old_108_242.Target', $SafeFrame, $SafeFrame_Animate, $SafeFrame_Border_Animate, $SecuTV, $TEXT)
LayerManager.newLayer("Old_cam")
-- Rename the layer: CM_cmra001_A > "cam"
NewCamLayer = LayerManager.getLayerFromName "CM_cmra001_A" name
NewCamLayer.setname = "Old_cam"
--paste layer Old_cam in the layer "cam"
--...??
-- create 2 new layers called: Characters and NewProps
LayerManager.newLayer("Characters")
LayerManager.newLayer("NewProps")
-- select childnodes of layers: Clones + Props > rename Objects: decocher base name, cocher prefix: Old_
--...
)
)
)
)--end on
)--end rollout
createDialog LL_Layout 250 75

miauu's picture

.

I can't test the code

-- prompt user to ask a number of a plan
global LL_Layout
try(destroyDialog LL_Layout)catch()
rollout LL_Layout "Enter Plan to open"
	(
	edittext plan_name "plan"
	button open_plan "OPEN"
 
	on open_plan pressed do
	(
		if plan_name.text != "" do
		(
			-- get the number entered and make a variables:
			planName = plan_name.text
			camName = "108_"+ planName
			-- path for open scene:
			filesArr = getFiles ("F:\\la_station\\A_FAIRE\\108\\"+camName+"\\"+camName+"*.max")
			-- path for save as scene
			saveASPath = "C:\\Users\\manue\\Desktop\\la_station\\les_legendaires\\"+camName+"\\"
			-- open last scene by date founded:
			if filesArr.count != 0 do
			(
				filesModDateArr = for f in filesArr collect (getFileModDate f)					
				lastModifiedDate = amax filesModDateArr
				index = findItem filesModDateArr lastModifiedDate
				lastModifiedFile = filesArr[index]
				format "_indx: % \n" index
				format "filesArr: % \n" filesArr[index]
				format "filesModDateArr: % \n" filesModDateArr[index]
				--	"works with the last modified file"
				resetMaxFile #noPrompt
				loadMAXFile lastModifiedFile quiet:true
				-- get the variable and make another:E
				OldcamName = "Old_" + camName
				extName = "_v000.max"
				SaveFile = camName+extName
				saveScene = saveASPath + SaveFile
				-- make folder:
				-- "makeDir SavePath"
 
				-- Renomme camName > Old_camName
-- 				select $camName
				$camName.name = OldcamName
				-- import the new cam and align postion and rotation on old cam
				mergeMaxFile @"C:\Users\manue\Desktop\la_station\les_legendaires\SetupCamera.max" #select #autoRenameDups #useMergedMtlDups
 
				toolMode.coordsys #local
 
				$cmra001_A_WORLD_001.pos = $OldcamName.pos -- align position
				$cmra001_A_WORLD_001.rot = $OldcamName.rot --align rotation
				-- and rotate it in rotation -90 en Z
				rotate $cmra001_A_WORLD_001 (angleaxis -90 [0,0,1])
				-- rename the new cam > camName
-- 				select $cmra001_H_camera_001
				$cmra001_H_camera_001.name = camName
				-- select the oldCam and more to create a new layer called > Old_cam
				select #($Old_108_242, $'Old_108_242.Target', $SafeFrame, $SafeFrame_Animate, $SafeFrame_Border_Animate, $SecuTV, $TEXT)
				LayerManager.newLayer("Old_cam")
				-- Rename the layer: CM_cmra001_A > "cam"
				NewCamLayer = LayerManager.getLayerFromName "CM_cmra001_A"
				NewCamLayer.setName "Old_cam"
				--paste layer Old_cam in the layer "cam"
				--...??
				-- create 2 new layers called: Characters and NewProps
				LayerManager.newLayer("Characters")
				LayerManager.newLayer("NewProps")
				-- select childnodes of layers: Clones + Props > rename Objects: decocher base name, cocher prefix: Old_
				--...
			)
		)
	)--end on
)--end rollout
createDialog LL_Layout 250 75

By the way, paste the code using "  --your code here "
without the quotes

Gnn's picture

You're a genius as cats, like

You're a genius as cats, like what words can care all evils, I love you :)

Gnn's picture

thank you so much for your

thank you so much for your generosity miauu!!!!

i've got another trouble today, if can you help me again with this script you can save me definitively...
anyway thanks you so much

Hello everybody! i'm trying to make a maxscript to open a scene and save it, do you know where i'm wrong? because nothing is working :(
by advance, thank you to make my dream become true...

-- prompt user to ask a number of a plan
rollout LL_Layout "Enter Plan to open"
(
edittext plan_name "plan"
button open_plan "OPEN"
on open_plan pressed do
(
if plan_name.text != "" do

-- get the number entered and make a variables:
planName = plan_name.text
camName = "108_"+ planName

-- path for open scene:
LoadPath = getFiles "E:\\"+camName+"\\"+camName+"*.max"
-- path for save as scene
SaveASPath = "E:\\Users\\"+camName+"\\"

-- open last scene by date founded:
if LoadPath .count == 1 do (
for f in LoadPath do (loadMAXFile f)

-- get the variable and make another:
OldcamName = "Old_" + camName

extName = "_v000.max"
SaveFile = camName+extName
saveScene = SaveASPath + SaveFile

-- make folder:
makeDir SavePath

-- save as the scene in the folder created:
saveMaxFile saveScene
)
)--end on
)--end rollout
createDialog LL_Layout 250 75

miauu's picture

.

YOu have some errors in your code.
I assume that you want to open and save each file separately?

makeDir tries to create a folder that is not declared in the script. If my example is wrong, use the proper variable.

-- prompt user to ask a number of a plan
global LL_Layout
try(destroyDialog LL_Layout)catch()
rollout LL_Layout "Enter Plan to open"
(
	edittext plan_name "plan"
	button open_plan "OPEN"
 
	on open_plan pressed do
	(
		if plan_name.text != "" do
		(
			-- get the number entered and make a variables:
			planName = plan_name.text
			camName = "108_"+ planName
			-- path for open scene:
			LoadPath = getFiles ("E:\\"+camName+"\\"+camName+"*.max")
			-- path for save as scene
			SaveASPath = "E:\\Users\\"+camName+"\\"
			-- open last scene by date founded:
			if LoadPath.count == 1 do 
			(
				for f in LoadPath do 
				(
					resetMaxFile #noPrompt
					loadMAXFile f quiet:true
					-- get the variable and make another:
					OldcamName = "Old_" + camName
					extName = "_v000.max"
					SaveFile = camName+extName
					saveScene = SaveASPath + SaveFile
					-- make folder:
					--	"SAVEPATH is not defiend.Use the proper variable."
					--	"makeDir SavePath"
					if makeDir SaveASPath == true then
					(
						-- save as the scene in the folder created:
						if (saveMaxFile saveScene quiet:true) == true then
							format "SAVED: %\n" saveScene
						else
							format "NOT SAVED: %\n" saveScene 
					)
					else
					(
						format "Can't create folder: % \n" SaveASPath
					)
				)
			)
		)
	)--end on
)--end rollout
createDialog LL_Layout 250 75

Comment viewing options

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