ScriptSpot

Forum topic · General Scripting

Can anyone tell me where i'm going wrong?

By ce89 · 2016-08-16

Description

Hi Guys,

I have a selection of camera's in my scene. Some start with "cam_" other don't. I want to use matchpattern to select the camera's that do start with this prefix. Below is what I have been trying to use. Please could someone tell me where i'm going wrong, don't think i'm too far off, i just cant find the right syntax. Also it would be great to know how to search two matchpaterns in the same for loop if possible.

for i in cameras where matchpattern i.name pattern:"cam_*" collect i

Any help would be much appreciated!

Comments (3)

ce89 · 2016-08-16

Thank you both for your answers. Seems it was working after all then :-). Think I was trying for so long that 3DMax gets a bit buggy and doesn't run execute the code. Shut 3DMax done, restarted and all seems fine!? :-) Many thanks again!

.

miauu · 2016-08-16


camArr = for i in cameras where matchpattern i.name pattern:"cam_*" collect i

print camArr
select camArr

That code is working for me

Maarten · 2016-08-16

Hi, I ran the code in a simple scene with some cams and it works for me (see image). Are you sure the error is not in the rest of your code (could be a 'logic error' also)?

"Also it would be great to know how to search two matchpaterns in the same for loop if possible."

If I understand correctly (correct me if I'm wrong) you'd like to have a loop run only if two matchpatterns return as true.
This would be the way to do it:

if (test1==true) and (test2==true) do ( some code )
which is the same as
if (test1) and (test2) do ( some code )
(when the if/and loop receives two values of 'true' the code will be run)


If ( (matchpattern i.name pattern:"Cam_*") and (matchpattern someobj.name pattern:"Box*") do (
--put whatever code you want to run if both matchpatterns return true here
)

Attachments