Notifications
Clear all

[Closed] Testing object name against wildcards

Hello.

I’m working on a script for exporting object names, positions, etc to a list, that will later be used in game engine.

I’m already got most of things working, but one problem remains.
I got a list of object “types”. During the list creating, every selected object’s name has to be compared against the types list, and then assign a number (so i.e. object “Tree 01” will match a type “Tree” and will be given type number 0). Problem is this part of my code


for f=1 to Types.items.count do
(
    filter = Execute("$*" + Types.items[f] + "*")
    if (obj[i].name == filter) then 
    (
       Type = f-1
       format "% 	 Type:% 	Position  ........ [I](here is a very long code that writes all my needed info like positons, rotation, etc)[/I]
       Progress.value = i*(100/obj.count)
      )
)

Thing that doesnt work is the IF test. I have no idea why it doesnt work.
If anyone could shed some light on this I would be very grateful

Thanks in advance
Best Regards
Andrzej

5 Replies

Hi Andrzej,

Sorry, but I have only had a couple of minutes before a meeting to look at this, so I may be well off target. Could the problem be with your test of

obj.name == filter

which I assume is always returning false… I think a direct string comparision like this with wildcard values, probably is a bit risky.

Have you tried using “matchpattern” ? Search for “string values” in maxscript help. I think this will help you make a wildcard match more reliably with you object name…

Hope this helps, but I might be barking up the wrong tree…

Cheers,

Rich

 JHN

Have a look at matchPattern in the MXS help file, I think that will get you a lot further.

-Johan

First of all, let’s see why your code does not work.
The filter variable will contain a collection of all objects which match the pattern you supplied. Thus, the IF test cannot compare the name of an object with that collection, but it could perform a FindItem() using the object itself to see whether it is on the list or not, assuming you collect the objects into an array.

For example


(
for i = 1 to 10 do box() --create 10 boxes
 for i = 1 to 10 do sphere() --create 10 spheres
 theType = "Box" --define the type to compare the name to
 theCollection = Execute("$*" + theType + "* as array") --collect by type in name pattern
 for o in objects do
   if findItem theCollection o > 0  then
 	format "+The Object % is of type %
" o.name theType
   else
 	format "-The Object % is NOT of type %
" o.name theType
)

Of course, the above method is not the way to go and I don’t recommend using it, I am just explaining how your code could have worked.

The correct way to do the matching would be


(
for i = 1 to 10 do box() --create 10 boxes
  for i = 1 to 10 do sphere() --create 10 spheres
  theType = "Box" --define the type to compare the name to
  for o in objects do 
    if matchPattern o.name pattern:(theType + "*") then 
  	format "+The Object % is of type %
" o.name theType
    else
  	format "-The Object % is NOT of type %
" o.name theType
)
   

I would also look into assigning userprops to every object.

 setuserprop $ "ObjectType" "Tree"
 getuserprop $ "ObjectType"

returns
“Tree”

(Just off the top of my head. Can’t say for certain the syntax is perfect. I recommend checking the documentation.)

Thanks for the help. Quite a lot of ideas there, will keep me bussy for some time Cheers

Andrzej