Announcement

Collapse
No announcement yet.

Maxscript help - object to layer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Maxscript help - object to layer

    Hello again!

    anyone know of a script that will take a bunch of selected objects and make layers for each of them with the same layer name as the object name

    so if an object is called 'Building_glass' it will make a new layer called 'Building_glass' and will stick that object on that layer.

    and then if there is already a suitable layer, it will skip creating the layer but will still move the object onto that layer

    thanks!
    www.peterguthrie.net
    www.peterguthrie.net/blog/
    www.pg-skies.net/

  • #2
    Hi, try these.
    http://www.scriptspot.com/blog/damie...om-object-name
    http://www.scriptspot.com/forums/3ds...e-layer-script
    And if you by any chance have to organize all that later, try this
    http://www.scriptspot.com/3ds-max/scripts/outliner

    Comment


    • #3
      trying a different approach - layers from materials (on sketchup import)

      I found this: http://www.scriptspot.com/forums/3ds...erials-3ds-max

      which i managed to get to work once, but now cant get it to work at all, can anyone spot anything up with the code?

      Code:
      layers = #()
      obj = #()
      for o in geometry where o.material != undefined do (append obj o)
      m = scenematerials
      c = m.count
      for i = 1 to c do (
      layername = m[i].name
      layer = layermanager.newLayerFromName layername
      for o in obj where o.material.name == m[i].name do (layer.addnode o)
      )
      www.peterguthrie.net
      www.peterguthrie.net/blog/
      www.pg-skies.net/

      Comment


      • #4
        and sometimes it fails on the 'addnode' part - perhaps if there is already a layer with that name?
        www.peterguthrie.net
        www.peterguthrie.net/blog/
        www.pg-skies.net/

        Comment


        • #5
          Not sure why it's failing on addnode, do you mean the entire script halts or just doesn't actually add the node?

          Here's what I came up with quickly, it's more verbose than what you're currently using.

          Code:
          (
          	clearListener()
          	
          	local layerNames = #()
          	
          	-- Go through all objects that have a material property and if it isn't undefined, add the name of the material (if unique) to the layerNames array
          	for o in objects where (isProperty o #material) and (o.material != undefined) do 
          		appendIfUnique layerNames o.material.name
          	
          	if not(queryBox ("Creating " + layerNames.count as string + " layers.  Would you like to continue?")) then		-- Just to make sure you don't have like 1000+ imported materials or something
          		return false
          		
          	-- Create all the layers from the material names
          	for layer in layerNames do 
          		layermanager.newLayerFromName layer
          	
          	-- Loop through all the objects and add them to the respective layers
          	for o in objects where (isProperty o #material) and (o.material != undefined) do (
          		layer = LayerManager.getLayerFromName o.material.name
          		layer.addnode o
          	)
          	
          	MessageBox "Done"
          )
          Colin Senner

          Comment


          • #6
            works a charm Colin! many many thanks
            www.peterguthrie.net
            www.peterguthrie.net/blog/
            www.pg-skies.net/

            Comment

            Working...
            X