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.
Saij's picture

Thank you all!

Thank you all,

i learned a lot from you guys. i have changed the code slightly to make it do what i want it to do, here is the final code:

names = #("CH_*_A_*", "CH_*_S_*", "CH_*_M_*", "Set_*_A_*", \
"Set_*_S_*", "Set_*_M_*", "Prop_*_A_*", \
"Prop_*_S_*", "Prop_*_M_*")

theObjs = #()

for obj in objects do
(
tmp = for str in names where matchPattern obj.name \
pattern:str ignoreCase:true collect obj join theObjs tmp
)

select $*
deselect theObjs
macros.run "Tools" "Isolate_Selection"

Again thank you all

Anubis's picture

hm, is this better?

names = #("CH_*_A_*", "CH_*_S_*", "CH_*_M_*", \
	"Set_*_A_*", "Set_*_S_*", "Set_*_M_*", \
	"Prop_*_A_*", "Prop_*_S_*", "Prop_*_M_*")
theObjs = #()
 
for obj in objects do (
	tmp = for str in names where NOT \
	matchPattern obj.name pattern:str \
	ignoreCase:true collect obj
	join theObjs tmp
)
 
select theObjs
macros.run "Tools" "Isolate_Selection"

my recent MAXScripts RSS (archive here)

fajar's picture

maybe you could post a scene

maybe you could post a scene here....um just clear the scene from unwanted object and reduce the the filesize.....

Saij's picture

Mock scene

here you go fajar i have attached the max file. it is max 2012.

AttachmentSize
examplescene.max 204 KB
Saij's picture

ill post a mock scene

ill post a mock sene later tonight

miauu's picture

Or, using the fajar snippet,

Or, using the fajar snippet, instead of selecting all objects and then deselecting each object in mySel array you can use this

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

hi miauu

thanks for helping me out,
this version of the script dosn't seems to work.
it returns undefined when i run it

fajar's picture

did you already my script i

did you already my script i wrotte for you ?

Saij's picture

I tried

I tried your script but it didn't do what I need it to.

Saij's picture

I tried

I tried your script but it didn't do what I need it to. It selected a few objects but left some of them out. I'll take a few screenshots ill post them later.

Comment viewing options

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