Online Sim Racing netKar PRO


    detachById (script to detach multimaterial objects)

    Share

    Andrea Lojelo
    ---
    ---

    Posts : 12576
    Join date : 2009-04-26
    Age : 38
    Location : Den Haag

    detachById (script to detach multimaterial objects)

    Post by Andrea Lojelo on Fri Feb 19, 2010 6:17 pm

    uno script che divide in automatico gli oggetti con MultiMaterial in oggetti singoli, creando anche i materiali nuovi.

    http://www.scriptspot.com/3ds-max/scripts/detach-by-material-id#comments

    scaricatelo da quel sito. comunque, come back up, scrivo il contenuto del file detachbyId.ms anche qui
    Code:

    /*
    Detach by Material ID
    Version: 2
    by Jefferson Lim
    Terabye Inc./ Shirogumi Inc.

    [features]
    Detach Polygons based on its Material ID
    - works on a selection of objects
    - Options to name detached objects
    - material propagation
      - this will assign a corresponding material by id to the detached object

    [usage]
    1. select any number of objects
    2. set the desired paramteters
    3. optional: if you know the maximun number of ids the object has
      set the Max IDs to help speed up detachment.
    4. press detach

    [Internal Operations]
    Procedure:
    - object[s] is/are copied
    - then collapsed to an editable poly
    - faces are finally detached by material ID

    Naming:
    - "Numbered"
      - will creae numbered names
      - e.g. 0,1,2,3
      - preferable to use with the Prefix option checked
    - "Bitmap Name"
      - if not diffuse bitmap found, it will use the material name
      - if no material applied, it will use the object's name
    - "Material Name"
      - if no material applied, it will use the object's name
    - "Object Name"
      - will create a unique name based on the object's name
    */

    try(destroyDialog detachByID)catch()
    rollout detachByID "Detach by ID" width:140 height:250
    (
    local name_type = 1
    local the_polyobj
    local ran_color = true
    local the_name
    local the_mat_arr = #()
    local id_list = #()


       label lbl_maxids "Max IDs:" pos:[10,190] width:55 height:15
       GroupBox grp_naming "Naming: " pos:[5,0] width:130 height:125
       GroupBox grp_prefix "" pos:[5,75] width:130 height:50
       GroupBox grp_ops "Options:" pos:[5,125] width:130 height:90
       
       radiobuttons rb_naming "" pos:[10,15] width:107 height:64 enabled:true labels:#("Object Name", "Material Name", "Bitmap Name", "Numbered") default:1 columns:1   
       checkbox chk_prefix "Use Prefix" pos:[10,85] width:70 height:15 checked:false
       edittext edt_prefix "" pos:[5,100] width:125
       checkbox chk_prop "Propagate Materials" pos:[10,140] width:120 height:15 checked:true
       checkbox btn_del "Delete Original" pos:[10,155] width:120 height:15 checked:true
       checkbox chk_rancolor "Random Wire Colors" pos:[10,170] width:120 height:15 checked:true
       spinner spn_maxids "" pos:[70,190] width:60 height:16 range:[0,99,99] type:#integer scale:0.05   
       button detach_bot "DETACH" pos:[5,220] width:130 height:25   
       
       fn getMaterialIDs obj =
       (
          id_arr = #()
          
          for i in 1 to spn_maxids.value do
          (
             obj.selectByMaterial i
             the_faces = getFaceSelection obj
             if (the_faces as array).count != 0 do
             (
                append id_arr i
             )
          )
          id_arr
       )
       
       fn getMatTextureName mat =
       (
          local the_map_name = the_polyobj.name
          
          try
          (         
             bmp = mat.diffusemap   
             if classof bmp == Bitmaptexture then
             (
                the_mapfile = mat.diffuseMap.bitmap.filename
                the_map_name = getFileNameFile the_mapfile
             )
             else
             (
                the_map_name = mat.name
             )
          )
          catch()
          
          the_map_name
       )   
       
       on rb_naming changed val do
       (
          name_type = val
          the_name = edt_prefix.text
       )
       
       on edt_prefix entered txt do
       (
          the_name = txt
       )
       
       on chk_rancolor changed val do
       (
          ran_color = val
       )

       on detach_bot pressed do
       (
          undo "Detach by ID" on
          (
             the_sel = selection as array
             if the_sel.count != 0 do
             (
                for obj in the_sel where \
                superclassof obj == GeometryClass and \
                obj.material != undefined do
                (
                   try(convertToPoly obj)catch(exit; print "DetacByID: Error Occured on Object Conversion")
                   the_orig = obj
                   the_polyobj = copy the_orig

                   the_mat = obj.material
                   id_count = the_mat.numSubs
                   id_list = getMaterialIDs the_polyobj
                   
                   -- start detaching
                   for i in id_list do
                   (   
                      the_polyobj.selectByMaterial i
                      the_faces = getFaceSelection the_polyobj
                      
                       case name_type of
                      (
                         1: the_name = uniquename (the_polyobj.name)
                         2: the_name = uniquename (the_mat[i].name)
                         3: the_name = uniquename (getMatTextureName the_mat[i])
                         4: the_name = uniquename the_name
                      )
                      
                      if chk_prefix.checked do the_name = edt_prefix.text + the_name
                      polyOp.detachFaces the_polyobj the_faces asnode:true name:the_name
                      theDetachedObj = (getnodebyname the_name)
                      
                      if isValidNode theDetachedObj do
                      (
                         if chk_prop.checked do theDetachedObj.material = the_mat[i]
                         if ran_color do theDetachedObj.wirecolor = random black white
                      )
                      
                   )-- end detach loop
                   
                   if btn_del.checked do delete the_orig
                )-- end object check loop
             )-- end selection loop
          )-- end Undo
       )-- end button press
       
    )
    createDialog detachByID style:#(#style_sysmenu,#style_toolwindow)



    /*
    [2.0]
    2008-12-09
    - added material propagation
    - faster detachment procedure
      - old script was looping through every face to look for IDs
      - the new procedure will only search thru the <Max IDs> set by the user
    - cleaned up code
    - reworked UI

    [1.0]
    2005-05-24
    - initial public release

    [to do]
    - make a more intuitive naming option
    - save settings to ini file
    - add progress bar

    [notes]
    - script request by Eye of Hawk (CGTalk)
    - "Propagate Materials" feature request by titane357 (scriptspot)
    */


    Last edited by Andrea Lojelo on Mon Jan 10, 2011 12:05 pm; edited 1 time in total


    _________________
     

    Andrea Lojelo
    ---
    ---

    Posts : 12576
    Join date : 2009-04-26
    Age : 38
    Location : Den Haag

    Re: detachById (script to detach multimaterial objects)

    Post by Andrea Lojelo on Fri Aug 06, 2010 7:35 pm

    new version of this script modified by Juha Pyy:

    now the script will not fail anymore if you select an object that is not multiobject.

    This will allow to process objects in bulk, regardless if already processed or not.
    Code:
    /*
    Detach by Material ID
    Version: 2
    by Jefferson Lim
    Terabye Inc./ Shirogumi Inc.

    [features]
    Detach Polygons based on its Material ID
    - works on a selection of objects
    - Options to name detached objects
    - material propagation
      - this will assign a corresponding material by id to the detached object

    [usage]
    1. select any number of objects
    2. set the desired paramteters
    3. optional: if you know the maximun number of ids the object has
      set the Max IDs to help speed up detachment.
    4. press detach

    [Internal Operations]
    Procedure:
    - object[s] is/are copied
    - then collapsed to an editable poly
    - faces are finally detached by material ID

    Naming:
    - "Numbered"
      - will creae numbered names
      - e.g. 0,1,2,3
      - preferable to use with the Prefix option checked
    - "Bitmap Name"
      - if not diffuse bitmap found, it will use the material name
      - if no material applied, it will use the object's name
    - "Material Name"
      - if no material applied, it will use the object's name
    - "Object Name"
      - will create a unique name based on the object's name
    */

    try(destroyDialog detachByID)catch()
    rollout detachByID "Detach by ID" width:140 height:250
    (
    local name_type = 1
    local the_polyobj
    local ran_color = true
    local the_name
    local the_mat_arr = #()
    local id_list = #()


       label lbl_maxids "Max IDs:" pos:[10,190] width:55 height:15
       GroupBox grp_naming "Naming: " pos:[5,0] width:130 height:125
       GroupBox grp_prefix "" pos:[5,75] width:130 height:50
       GroupBox grp_ops "Options:" pos:[5,125] width:130 height:90
       
       radiobuttons rb_naming "" pos:[10,15] width:107 height:64 enabled:true labels:#("Object Name", "Material Name", "Bitmap Name", "Numbered") default:1 columns:1   
       checkbox chk_prefix "Use Prefix" pos:[10,85] width:70 height:15 checked:false
       edittext edt_prefix "" pos:[5,100] width:125
       checkbox chk_prop "Propagate Materials" pos:[10,140] width:120 height:15 checked:true
       checkbox btn_del "Delete Original" pos:[10,155] width:120 height:15 checked:true
       checkbox chk_rancolor "Random Wire Colors" pos:[10,170] width:120 height:15 checked:true
       spinner spn_maxids "" pos:[70,190] width:60 height:16 range:[0,99,99] type:#integer scale:0.05   
       button detach_bot "DETACH" pos:[5,220] width:130 height:25   
       
       fn getMaterialIDs obj =
       (
          id_arr = #()
          
          for i in 1 to spn_maxids.value do
          (
             obj.selectByMaterial i
             the_faces = getFaceSelection obj
             if (the_faces as array).count != 0 do
             (
                append id_arr i
             )
          )
          id_arr
       )
       
       fn getMatTextureName mat =
       (
          local the_map_name = the_polyobj.name
          
          try
          (         
             bmp = mat.diffusemap   
             if classof bmp == Bitmaptexture then
             (
                the_mapfile = mat.diffuseMap.bitmap.filename
                the_map_name = getFileNameFile the_mapfile
             )
             else
             (
                the_map_name = mat.name
             )
          )
          catch()
          
          the_map_name
       )   
       
       on rb_naming changed val do
       (
          name_type = val
          the_name = edt_prefix.text
       )
       
       on edt_prefix entered txt do
       (
          the_name = txt
       )
       
       on chk_rancolor changed val do
       (
          ran_color = val
       )

       on detach_bot pressed do
       (
          undo "Detach by ID" on
          (
             the_sel = selection as array
             if the_sel.count != 0 do
             (
                for obj in the_sel where \
                superclassof obj == GeometryClass and \
                obj.material != undefined do
                (
                   try(convertToPoly obj)catch(exit; print "DetacByID: Error Occured on Object Conversion")
                   the_orig = obj
                   the_polyobj = copy the_orig

                   the_mat = obj.material
                   id_count = the_mat.numSubs
                   id_list = getMaterialIDs the_polyobj
                   
                   -- check count to skip objects with only one material ID (otherwise causes error) -- by Juha Pyy
                   if id_list.count > 1 then
                   (
                      -- start detaching
                      for i in id_list do
                      (   
                         the_polyobj.selectByMaterial i
                         the_faces = getFaceSelection the_polyobj
                         
                          case name_type of
                         (
                            1: the_name = uniquename (the_polyobj.name)
                            2: the_name = uniquename (the_mat[i].name)
                            3: the_name = uniquename (getMatTextureName the_mat[i])
                            4: the_name = uniquename the_name
                         )
                         
                         if chk_prefix.checked do the_name = edt_prefix.text + the_name
                         polyOp.detachFaces the_polyobj the_faces asnode:true name:the_name
                         theDetachedObj = (getnodebyname the_name)
                         
                         if isValidNode theDetachedObj do
                         (
                            if chk_prop.checked do theDetachedObj.material = the_mat[i]
                            if ran_color do theDetachedObj.wirecolor = random black white
                         )
                         
                      )-- end detach loop
                      
                      if btn_del.checked do delete the_orig
                   )
                )-- end object check loop
             )-- end selection loop
          )-- end Undo
       )-- end button press
       
    )
    createDialog detachByID style:#(#style_sysmenu,#style_toolwindow)



    /*
    [2.0]
    2008-12-09
    - added material propagation
    - faster detachment procedure
      - old script was looping through every face to look for IDs
      - the new procedure will only search thru the <Max IDs> set by the user
    - cleaned up code
    - reworked UI

    [1.0]
    2005-05-24
    - initial public release

    [to do]
    - make a more intuitive naming option
    - save settings to ini file
    - add progress bar

    [notes]
    - script request by Eye of Hawk (CGTalk)
    - "Propagate Materials" feature request by titane357 (scriptspot)
    */


    thanks for the help Juha!


    _________________
     

    Gerrit de Vries
    Driver
    Driver

    Posts : 53
    Join date : 2009-06-07
    Age : 32
    Location : Zwaagwesteinde,Netherlands

    Re: detachById (script to detach multimaterial objects)

    Post by Gerrit de Vries on Fri Aug 06, 2010 7:36 pm

    awesome,very helpful script,and this way even better Smile

    M Carey
    Driver
    Driver

    Posts : 1076
    Join date : 2010-04-20

    Re: detachById (script to detach multimaterial objects)

    Post by M Carey on Fri Aug 06, 2010 10:20 pm

    Just tried the updated script, and it looked like it was working, but I can’t see any textures in KOFlite as if it didn’t detach any?

    Andrea Lojelo
    ---
    ---

    Posts : 12576
    Join date : 2009-04-26
    Age : 38
    Location : Den Haag

    Re: detachById (script to detach multimaterial objects)

    Post by Andrea Lojelo on Sun Aug 15, 2010 1:46 am

    new fix to the script by Juha

    http://www.lastplace-racing.com/downloads/detachbyID.ms

    Code:

    /*
    Detach by Material ID
    Version: 2
    by Jefferson Lim
    Terabye Inc./ Shirogumi Inc.

    [features]
    Detach Polygons based on its Material ID
    - works on a selection of objects
    - Options to name detached objects
    - material propagation
      - this will assign a corresponding material by id to the detached object

    [usage]
    1. select any number of objects
    2. set the desired paramteters
    3. optional: if you know the maximun number of ids the object has
      set the Max IDs to help speed up detachment.
    4. press detach

    [Internal Operations]
    Procedure:
    - object[s] is/are copied
    - then collapsed to an editable poly
    - faces are finally detached by material ID

    Naming:
    - "Numbered"
      - will creae numbered names
      - e.g. 0,1,2,3
      - preferable to use with the Prefix option checked
    - "Bitmap Name"
      - if not diffuse bitmap found, it will use the material name
      - if no material applied, it will use the object's name
    - "Material Name"
      - if no material applied, it will use the object's name
    - "Object Name"
      - will create a unique name based on the object's name
    */

    try(destroyDialog detachByID)catch()
    rollout detachByID "Detach by ID" width:140 height:250
    (
    local name_type = 1
    local the_polyobj
    local ran_color = true
    local the_name
    local the_mat_arr = #()
    local id_list = #()


       label lbl_maxids "Max IDs:" pos:[10,190] width:55 height:15
       GroupBox grp_naming "Naming: " pos:[5,0] width:130 height:125
       GroupBox grp_prefix "" pos:[5,75] width:130 height:50
       GroupBox grp_ops "Options:" pos:[5,125] width:130 height:90
       
       radiobuttons rb_naming "" pos:[10,15] width:107 height:64 enabled:true labels:#("Object Name", "Material Name", "Bitmap Name", "Numbered") default:1 columns:1   
       checkbox chk_prefix "Use Prefix" pos:[10,85] width:70 height:15 checked:false
       edittext edt_prefix "" pos:[5,100] width:125
       checkbox chk_prop "Propagate Materials" pos:[10,140] width:120 height:15 checked:true
       checkbox btn_del "Delete Original" pos:[10,155] width:120 height:15 checked:true
       checkbox chk_rancolor "Random Wire Colors" pos:[10,170] width:120 height:15 checked:true
       spinner spn_maxids "" pos:[70,190] width:60 height:16 range:[0,99,99] type:#integer scale:0.05   
       button detach_bot "DETACH" pos:[5,220] width:130 height:25   
       
       fn getMaterialIDs obj =
       (
          id_arr = #()
          
          for i in 1 to spn_maxids.value do
          (
             obj.selectByMaterial i
             the_faces = getFaceSelection obj
             if (the_faces as array).count != 0 do
             (
                append id_arr i
             )
          )
          id_arr
       )
       
       fn getMatTextureName mat =
       (
          local the_map_name = the_polyobj.name
          
          try
          (         
             bmp = mat.diffusemap   
             if classof bmp == Bitmaptexture then
             (
                the_mapfile = mat.diffuseMap.bitmap.filename
                the_map_name = getFileNameFile the_mapfile
             )
             else
             (
                the_map_name = mat.name
             )
          )
          catch()
          
          the_map_name
       )   
       
       on rb_naming changed val do
       (
          name_type = val
          the_name = edt_prefix.text
       )
       
       on edt_prefix entered txt do
       (
          the_name = txt
       )
       
       on chk_rancolor changed val do
       (
          ran_color = val
       )

       on detach_bot pressed do
       (
          undo "Detach by ID" on
          (
             the_sel = selection as array
             if the_sel.count != 0 do
             (
                for obj in the_sel where \
                superclassof obj == GeometryClass and \
                obj.material != undefined do
                (
                   try(convertToPoly obj)catch(exit; print "DetachByID: Error Occured on Object Conversion")
                   the_orig = obj
                   the_polyobj = copy the_orig

                   the_mat = obj.material
                   id_count = the_mat.numSubs
                   id_list = getMaterialIDs the_polyobj
                   
                   -- start detaching
                   for i in id_list do
                   (   
                      the_polyobj.selectByMaterial i
                      the_faces = getFaceSelection the_polyobj
                      
                      case name_type of
                      (
                         1: the_name = uniquename (the_polyobj.name)
                         2: the_name = uniquename (the_mat[i].name)
                         3: the_name = uniquename (getMatTextureName the_mat[i])
                         4: the_name = uniquename the_name
                      )
                      
                      if chk_prefix.checked do the_name = edt_prefix.text + the_name
                      polyOp.detachFaces the_polyobj the_faces asnode:true name:the_name
                      theDetachedObj = (getnodebyname the_name)
                      
                      if isValidNode theDetachedObj do
                      (
                         -- added try-catch to catch Rollout Handler Exception in case the object has only one material (e.g. material had already been detached) -- by Juha Pyy
                         try(if chk_prop.checked do theDetachedObj.material = the_mat[i]) catch(print "DetachByID: Unable to convert: ReferenceTarget:ReferenceTarget to type: Material")
                         if ran_color do theDetachedObj.wirecolor = random black white
                      )
                      
                   )-- end detach loop
                   
                   if btn_del.checked do delete the_orig
                )-- end object check loop
             )-- end selection loop
          )-- end Undo
       )-- end button press
       
    )
    createDialog detachByID style:#(#style_sysmenu,#style_toolwindow)



    /*
    [2.0]
    2008-12-09
    - added material propagation
    - faster detachment procedure
      - old script was looping through every face to look for IDs
      - the new procedure will only search thru the <Max IDs> set by the user
    - cleaned up code
    - reworked UI

    [1.0]
    2005-05-24
    - initial public release

    [to do]
    - make a more intuitive naming option
    - save settings to ini file
    - add progress bar

    [notes]
    - script request by Eye of Hawk (CGTalk)
    - "Propagate Materials" feature request by titane357 (scriptspot)
    */


    _________________
     

    Andrea Lojelo
    ---
    ---

    Posts : 12576
    Join date : 2009-04-26
    Age : 38
    Location : Den Haag

    Re: detachById (script to detach multimaterial objects)

    Post by Andrea Lojelo on Sun Aug 22, 2010 5:07 pm

    copy the script in your 3dsmax script folder


    -select all objects
    -run the script



    all object will be now detached, so you will not have anymore multimaterial objects


    _________________
     

    M Carey
    Driver
    Driver

    Posts : 1076
    Join date : 2010-04-20

    Re: detachById (script to detach multimaterial objects)

    Post by M Carey on Sun Aug 22, 2010 5:43 pm

    Andrea Lojelo wrote:all object will be now detached
    Unless you run out of memory (like I always do) ::crying::

    Andrea Lojelo
    ---
    ---

    Posts : 12576
    Join date : 2009-04-26
    Age : 38
    Location : Den Haag

    Re: detachById (script to detach multimaterial objects)

    Post by Andrea Lojelo on Sun Aug 22, 2010 5:46 pm

    well..in that case take a smaller group of object at a time!


    _________________
     

    Andrea Lojelo
    ---
    ---

    Posts : 12576
    Join date : 2009-04-26
    Age : 38
    Location : Den Haag

    Re: detachById (script to detach multimaterial objects)

    Post by Andrea Lojelo on Thu Feb 10, 2011 5:06 pm

    A common method I use is:
    1) open the layer window
    2) create a new layer called Layer01 (this is automatically set as the default layer for the newly created objects)
    3) select groups of objects and detach them.
    NOTE: objects will move from default (original) layer to Layer01. default layer will always contain objects still to be detached.
    4) save often in a new file. This will prevent to loose your work if max crashes (happen often if you don't have enough RAM, and you select too many objects.


    _________________
     

    Attilio Barba
    Driver
    Driver

    Posts : 384
    Join date : 2010-03-03
    Age : 54
    Location : cumiana (TO)

    Re: detachById (script to detach multimaterial objects)

    Post by Attilio Barba on Tue Feb 22, 2011 1:06 am

    work, I thought it locked up, while in 1 minute I did Deatch of 1580 items

    CarloMaker
    Driver
    Driver

    Posts : 1
    Join date : 2012-01-18

    Re: detachById (script to detach multimaterial objects)

    Post by CarloMaker on Tue Jan 29, 2013 1:46 am

    Ciao ragazzi,
    sono nuovo nel forum ,
    sto cercando di importare in 3ds una pista per rf per alcuni esperimenti ,di conversione su un mio progetto
    ma sono piuttosto asciutto di 3ds...
    Da quello che ho capito lo scipt in oggetto dovrebbe separare gli oggetti e relativi submaterial in materiali standard , o sbaglio?
    perche' sembra non creare nulla.
    Seleziono gli oggetti... runno lo script , vedo che mi cambia il layer ma i submateriali rimangono tali e quali...che sbaglio???
    Grazie e scusate...

    Roberto Olivetti
    Driver
    Driver

    Posts : 88
    Join date : 2010-10-11
    Age : 46
    Location : Santa Sofia FC - Italy

    Re: detachById (script to detach multimaterial objects)

    Post by Roberto Olivetti on Thu Jan 31, 2013 1:25 am

    CarloMaker wrote:Ciao ragazzi,
    sono nuovo nel forum ,
    sto cercando di importare in 3ds una pista per rf per alcuni esperimenti ,di conversione su un mio progetto
    ma sono piuttosto asciutto di 3ds...
    Da quello che ho capito lo scipt in oggetto dovrebbe separare gli oggetti e relativi submaterial in materiali standard , o sbaglio?
    perche' sembra non creare nulla.
    Seleziono gli oggetti... runno lo script , vedo che mi cambia il layer ma i submateriali rimangono tali e quali...che sbaglio???
    Grazie e scusate...
    Ciao Carlo,
    purtroppo non so aiutarti su 3ds perché non l'ho mai usato. Io sto facendo un tracciato per netKar usando Blender (software FreeOpenSource) e anche se con una certa fatica si riesce a fare tutto (ci vuole pazienza...).
    Il modo più rapido per convertire un file di rf in 3ds credo che sia usare 3DSimED. Puoi scaricare da qui -> http://www.sim-garage.co.uk/
    una versione gratuita che dura 20 giorni, e se segui i tutorial che trovi in internet, o anche solo le istruzioni del progamma, vedrai che non ci vuole tantissimo.
    Buon lavoro, spero che tu risolva Smile

    Sponsored content

    Re: detachById (script to detach multimaterial objects)

    Post by Sponsored content Today at 5:20 pm


      Current date/time is Wed Dec 07, 2016 5:20 pm