Notifications
Clear all

[Closed] filtering 3ds Max default object names

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

10 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

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>)

 JHN

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

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 "

Super Class Name: %
" 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
"
 				 format "----------------------------------------------------------
"
 				 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 "\"%\"
" objname 
 			 try 
 			 (
 				 delete obj
 			 )
 			 catch()
 		 )
 	 )		
 	 
 	 if not foundone do
 	 (
 		 format "<Nothing with a name can be constructed>
"
 	 )
 	 
  )
  
  for sc in superclasses do
  (
 	 DumpDefaultNames (sc as string)
  )
  

[Edit: clean up formatting]

oh, biddle! you are first!

that’s funny. we are used same variable names : “ss”, “cls”… hah!

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>

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

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

my bad.

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

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.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

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?

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