PDA

View Full Version : filtering 3ds Max default object names


bkravi
10-14-2009, 01:41 PM
Hi everyone,

I am working on a script where i want to copy only those object to my array who do not have any default names like ..Box01, Cone01, Rectangle125, or Omni05.

is there any function that comes with 3dsmax to filter the way I want, or Do I need to test all objects in a for loop?

please share if anyone knows how to do it.

thanks
ravi

JHN
10-14-2009, 02:13 PM
I don't think there is a default function for this.
You probably end up with an array of default names and check against that.
If you have such a list, please share it ;)

-Johan

biddle
10-14-2009, 05:47 PM
Here is an experiment to see what you can build on your system...

fn DumpDefaultNames superclass =
(
-- Try and construct something to see what its name is
local ss,spacing,ln,cls,obj,objname,foundone

ss = stringstream ""
showclass ("*:"+superclass) to:ss

format "\n\nSuper Class Name: %\n" superclass

foundone = false

-- Make sure cgtalk doesn't convert a string of spaces to tabs
spacing = ""
for x = 1 to 40 do (spacing += " ")

seek ss 0
while not eof ss do
(
ln = readline ss
cls = (filterstring ln " ") [1]

obj = undefined
try
(
obj = execute ( cls + "()" )
)
catch()

if (isproperty obj #name) do
(

if not foundone do
(
format "Class Name Default Name\n"
format "----------------------------------------------------------\n"
foundone = true
)

objname = obj.name as string
if (matchpattern objname pattern:"*0?") do
objname = substring objname 1 (objname.count-2)
format "%" cls
format "%" (if (spacing.count <= cls.count) then " " else (substring spacing 1 (spacing.count - cls.count)))
format "\"%\"\n" objname
try
(
delete obj
)
catch()
)
)

if not foundone do
(
format "<Nothing with a name can be constructed>\n"
)

)

for sc in superclasses do
(
DumpDefaultNames (sc as string)
)


[Edit: clean up formatting]

denisT
10-14-2009, 06:19 PM
I am working on a script where i want to copy only those object to my array who do not have any default names like ..Box01, Cone01, Rectangle125, or Omni05.


what is default name for you? Any creatable class can create a node and name it any way.
box names "Box", cone - "Cone",... but freeSpot names its created nodes "Fspot", omniLight - "Omni", etc.

So, there is no a simple criteria to collect all "default" names. Probably, you have to define for yourself the list of "default" names, and check against this list...

but there is a way to collect all these names.

fn collectAllCreatableNodeClasses = with undo off
(
fn sortByClass c1 c2 = (stricmp c1[1] c2[1])

ss = stringStream ""
showclass "*:*" to:ss
seek ss 0
nodeclasses = #()
while not eof ss do
(
str = readline ss
cls = filterstring str ": "
c = try((execute cls[1]).creatable) catch(false)
if c and not matchpattern cls[2] pattern:"*plugin*"\
and not matchpattern cls[2] pattern:"*material*"\
and not matchpattern cls[2] pattern:"*modifier*"\
and not matchpattern cls[2] pattern:"*controller*"\
and not matchpattern cls[2] pattern:"*texture*" do
(
with quiet on (node = try(execute (cls[1] + "()")) catch())
if isvalidnode node do
(
append cls (trimright node.name "0123456789")
append nodeclasses cls
delete node
)
)
)
qsort nodeclasses sortByClass
gc light:on
nodeclasses
)


this function returns list all classes that create a valid node sorted by class name.
returned format is:
#(<class name>, <superclass name>, <class id>, <node default name>)

denisT
10-14-2009, 06:20 PM
oh, biddle! you are first!

that's funny. we are used same variable names : "ss", "cls"... hah!

biddle
10-14-2009, 06:46 PM
Interesting note, I added a filter that tested to see if the class was 'creatable' like you have.

For my M2010 system I get 655 things than be created if I try, but only 99 that are marked as 'creatable' (and ugly error messages when I try to make something that clearly was never meant to see light of day)

WHOOPS: wrong number, that should be 571 'creatables', not 99!

[2nd edit] pls ignore my obvious counting error. It sure didn't make sense to be able to create a 'non-creatable' thing. I fixed my bug and get 655.

'exit' instead of 'continue' <sigh>

denisT
10-14-2009, 07:06 PM
Interesting note, I added a filter that tested to see if the class was 'creatable' like you have.

For my M2010 system I get 655 things than be created if I try, but only 99 that are marked as 'creatable' (and ugly error messages when I try to make something that clearly was never meant to see light of day)

WHOOPS: wrong number, that should be 571 'creatables', not 99!

as you see in my code i skip "plugins", "modifiers", "materials", "texture", and "controllers"... they are creatable but they don't create nodes.

biddle
10-14-2009, 07:13 PM
my bad.

the counting code I threw in was broken and I jumped to a conclusion (see edit)

bkravi
10-15-2009, 06:18 PM
Thank you very much for this custom function....thats what I want.

but now how can I use it, I don't know much about the file I/O in maxscript, so pls guide how it can be used against the name of any scene node in a conditional statement or in a loop.

denisT
10-15-2009, 06:48 PM
Thank you very much for this custom function....thats what I want.

but now how can I use it, I don't know much about the file I/O in maxscript, so pls guide how it can be used against the name of any scene node in a conditional statement or in a loop.

I have no idea where did you find file I/O but...

using my collectAllCreatableNodeClasses function you can collect all "default" names and:


fn collectDefaultNames =
(
data = collectAllCreatableNodeClasses()
for d in data collect d[4]
)

fn matchAnyPattern patterns node =
(
local act = off
local name = trimRight node.name "0123456789" -- cut index put of the name
for n in patterns while not act do act = (stricmp name n == 0)
act
)

fn findDefaultNamedNodes nodes: =
(
if nodes == unsupplied do nodes = objects as array -- by default search in all scene nodes
patterns = collectDefaultNames()
def_nodes = for node in nodes where (matchAnyPattern patterns node) collect node
)

if (nodes = findDefaultNamedNodes()).count > 0 then select nodes else clearSelection()



something like that...

but why do you need it? what a reason to get the list of "default" named nodes?

bkravi
10-16-2009, 08:26 AM
Many thanks denisT,

actually I am creating our custom Layer manager where everybody will follow naming convention as per our standard, so what I am trying to do is to automatically put all scene nodes in there respected layers avoiding any standard names. I also want to have option for the user where he do not know the name or he do not find it in standard in that case he can add the new name to library (I want to check if that name is not 3dsmax standard default name) so when my script find that name next time it will recognize it and can use it from INI (which is done automatically ).

thanks again
ravi

CGTalk Moderation
10-16-2009, 08:26 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.