I wrote a new script a while back and thought I'd share it. It has already been excellent for me in my workflow.
Script: SelectObjsByMaterial
It extends and improves the functionality of the button in the material editor labeled "Select by Material". I was always frustrated by this button because to effectively get every object which a material is applied to I always had to unfreeze/unhide everything, and on heavy scenes, this proved to be difficult. Also, using this functionality is rough because it will only select the group head if an object that has the material applied is part of a group, resulting in me mistakenly assigning materials to whole groups.
This script allows you to select the material, click the button and have all the objects that material is assigned to selected (even if they are hidden or frozen), if the objects happen to be a part of a group, it will open every level of the group till it gets to the object with the assigned material.
To Use:
Run the script, goto Customize->Customize User Interface, Toolbars, Group: "Main UI", Category: "All Commands", drag the item "SelectObjsByMaterial" to a toolbar, or alternatively assign it to a QUAD menu.
Now, open the material editor and pick an object assigned to something in your scene (doesn't matter if the object is hidden/frozen/grouped etc.) and click the hotkey, the result will be you will have every object in the scene with that material selected (even if you can't see them, they are still selected).
Alternatively if you assign this script to a quad, you will also have an alternate box, if you use the alt box from the quad, it will automatically unhide/unfreeze all the objects making sure you can see and select them.
Quick Note: If the material you select is instanced/copied in a multi-sub material, it will not select the objects because it is not the exact material you have selected, this is correct functionality.
Script: SelectObjsByMaterial
It extends and improves the functionality of the button in the material editor labeled "Select by Material". I was always frustrated by this button because to effectively get every object which a material is applied to I always had to unfreeze/unhide everything, and on heavy scenes, this proved to be difficult. Also, using this functionality is rough because it will only select the group head if an object that has the material applied is part of a group, resulting in me mistakenly assigning materials to whole groups.
This script allows you to select the material, click the button and have all the objects that material is assigned to selected (even if they are hidden or frozen), if the objects happen to be a part of a group, it will open every level of the group till it gets to the object with the assigned material.
To Use:
Run the script, goto Customize->Customize User Interface, Toolbars, Group: "Main UI", Category: "All Commands", drag the item "SelectObjsByMaterial" to a toolbar, or alternatively assign it to a QUAD menu.
Now, open the material editor and pick an object assigned to something in your scene (doesn't matter if the object is hidden/frozen/grouped etc.) and click the hotkey, the result will be you will have every object in the scene with that material selected (even if you can't see them, they are still selected).
Alternatively if you assign this script to a quad, you will also have an alternate box, if you use the alt box from the quad, it will automatically unhide/unfreeze all the objects making sure you can see and select them.
Code:
macroScript SelectObjsByMaterial ( -- <array>SelectObjectByMaterial - returns array of objects a material is assigned to fn SelectObjectByMaterial reqMatEditOpen materialIndex = ( objarr = #() -- Select ALL objects with this material if MatEditor.isOpen() or (reqMatEditOpen == false) then ( if materialIndex > 0 and materialIndex < 25 then ( -- start index check objarr = for o in objects where o.material == meditMaterials[materialIndex] collect o -- Check if the obj is part of a group for obj in objarr where isGroupMember obj AND (NOT isOpenGroupMember obj) do ( par = obj.parent while par != undefined do ( if isGroupHead par then ( setGroupOpen par true par = undefined ) else par = par.parent ) ) ) -- end index check ) else -- Material Editor isn't open messageBox "Material Editor is not open" beep:false objarr ) on execute do ( clearSelection() max create mode if (objs = SelectObjectByMaterial true (medit.getActiveMtlSlot())) != undefined then select objs ) on altexecute type do ( clearSelection() max create mode if (objs = SelectObjectByMaterial true (medit.getActiveMtlSlot())) != undefined then select objs for o in objs where not(o.layer.on) do o.layer.on = true for o in objs where o.layer.isFrozen do o.layer.isFrozen = false for o in objs where o.isHidden do o.isHidden = false for o in objs where o.isFrozen do o.isFrozen = false select objs ) )
Quick Note: If the material you select is instanced/copied in a multi-sub material, it will not select the objects because it is not the exact material you have selected, this is correct functionality.
Comment