Please, need help me optimising this script

Hi everyone,

I am new to max scripting and need help optimizing this script. Although this script works as intended I can't but help to think that there must be a better way. That is however beyond my skills to identify.

I wrote this script to check naming conventions.

1- go through everything in the scene

2- check the if the names are matching the given names i.e.(ch_*_A_*, Set_*_A_*, Prop_*_A_*, etc)

3- select everything that are not matching the giving names

4- isolate it

beforehand thank you all for helping a noob out.

/*
Version: v1.1
Purpose: Check scene for names:

CH_*_A_*
CH_*_S_*
CH_*_M_*

Set_*_A_*
Set_*_S_*
Set_*_M_*

Prop_*_A_*
Prop_*_S_*
Prop_*_M_*

Select and isolate everything that does not fall within the parameters
*/

macroScript NameChecker
category:"Custom Tools"
icon:#("enss_maintoolbar",1)
(
fn Check=
(
nameList = stringStream ""

-- putting things in arrays
local Array1 = $ch_*_a_* as array
local Array2 = $ch_*_s_* as array
local Array3 = $ch_*_m_* as array

local Array4 = $set_*_a_* as array
local Array5 = $set_*_s_* as array
local Array6 = $set_*_m_* as array

local Array7 = $prop_*_a_* as array
local Array8 = $prop_*_s_* as array
local Array9 = $prop_*_m_* as array

-- selecting arrays
select Array1
selectmore array2
selectmore array3

selectmore array4
selectmore array5
selectmore array6

selectmore array7
selectmore array8
selectmore array9

-- putting all selected into a new array
tarObj = selection as array

-- select everything in the scene, deselect everything in tarObj array and unhide selection
select $*
deselect tarObj
selection.ishidden = off

-- isolate selection
macros.run "Tools" "Isolate_Selection"

for o in selection do print (o.name as string) to:nameList
messageBox (nameList)
)

-- create GUI
rollout rollout_NameChecker "Name Checker " width:200
(
-- create button
group "Checks"
(
button squashBtn "Check Names!"
)

-- call on function check()
on squashBtn pressed do
(
check ()
)
)
createdialog rollout_NameChecker style:#(#style_titlebar,#Style_toolwindow,#style_sysmenu)
)

Comments

Comment viewing options

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

hmm...dont know what youre

hmm...dont know what youre trying to accomplish...but if my mind correct you want to isolate all object in scene exclude theNames you mention....if then ....try

fn Check=
(
names=#("CH_*_A_*","CH_*_S_*","CH_*_M_*","Set_*_A_*","Set_*_S_*", "Set_*_M_*","Prop_*_A_*","Prop_*_S_*","Prop_*_M_*")
 
max select all
 
for i in selection do
 (
 	MySel=for o in names where matchPattern i.name pattern:("*"+o+"*") ignoreCase:true collect i
	deselect MySel
 )
 
if (maxVersion())[1]>=15000 then 
(
	IsolateSelection.IsolateSelectionModeActive()
)
else 
(
	macros.run "Tools" "Isolate_Selection"
)
)
Saij's picture

hi fajar,

hi fajar,

thanks for you response, i should have been more clear of what i needed.
this is a script that i wrote to check naming in a scene.

1- go through everything in the scene

2- check the if the names are matching the given names i.e.(ch_*_A_*)

3- select everything that are not matching the giving names

4- isolate it

the way i have done it is a very rudimentary:

-i selected the names and put then into its own array.

-then i selected the array using select(), with that selected i select the next one with selectMore() so that i have the original selection plus my second selection.

-when everything correct are selected then i pass it into a new array tarObj.

-after that i select everything in the scene and then deselect everything from tarObj. leaving me with objects that are not named correctly.

-finally isolate those objects.

that is how my script works, and it does what i want it to do but it feels very dragged out, so i am posting this to see if there is a better way to make the script do the same thing but more efficient.

but thanks for taking time to help me i appreciate it

Comment viewing options

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