PDA

View Full Version : click it, find it!


sunboy69
04-30-2008, 03:35 AM
I have got Bercon's script ,it's very helpful,i must thanks him.And maybe it's useful for you!

Now when i need to find some objs which use repeated materials by the list , i must to find objs names one by one in max,it's troublesome!

How to amend the script when i click one line of the list,

it can select relevant objs immediate!

http://imgbj.jpg.name/hjytzvhwhhvythhyzshwwtvtdzwtzdtyzvrsh.jpg

global findSharedMaps
try(DestroyDialog findSharedMaps)catch()
rollout findSharedMaps "Find Shared Maps" width:780 (
-- Shared
local foundMaps = #()
local foundParents = #()
-- Functions
fn gSubMaps map root = (
if map != undefined then (
local index = findItem foundMaps map
if (index == 0) then (
append foundMaps map
append foundParents #(root)
) else if findItem foundParents[index] root == 0 then (
append foundParents[index] root
)
showTextureMap root map false
for i in 1 to getNumSubTexmaps map do gSubMaps (getSubTexmap map i) root
)
)
fn gSubMatsMaps mat = (
if mat != undefined then (
for i in 1 to getNumSubMtls mat do gSubMatsMaps (getSubMtl mat i)
for i in 1 to getNumSubTexmaps mat do gSubMaps (getSubTexmap mat i) mat
)
)
-- UI items
button BUTTON_find "Find shared maps!" width: 200 height:30
listbox LISTBOX_found "" height:30
-- Events
on BUTTON_find pressed do (
foundMaps = #()
foundParents = #()
for i in meditMaterials where superClassOf i == Material do gSubMatsMaps i
for i in sceneMaterials where superClassOf i == Material do gSubMatsMaps i
local list = #()
for i in 1 to foundMaps.count where foundParents[i].count > 1 do (
local item = foundMaps[i].name + " : "
for j in foundParents[i] do item = item + j.name + ", "
append list item
)
format "list %\n" list
LISTBOX_found.items = list
)
)
CreateDialog findSharedMaps

labbejason
04-30-2008, 04:20 AM
Hey, here's an example I made up:

(
-- UI
rollout getMaterials "Get Matching Materials"
(
listBox currentMaterials "Current Materials in Scene"
button getObjects "Get All Objects" width:175 height:15
listBox objList "Objects with matching materials"
button selectObject "Select Object" width:175 height:15

-- Populating first list of all current materials in the scene
on getMaterials open do
(
theMaterials = #()
for o in geometry where o.material != undefined do
(
if findItem theMaterials o.material.name == 0 do append theMaterials o.material.name
)
currentMaterials.items = theMaterials
)

-- Populating second list of all objects with the selected material from the first list
on getObjects pressed do
(
theObjs = #()
for o in geometry where o.material != undefined do
(
if o.material.name == currentMaterials.selected do append theObjs o.name
)

-- At this point, if you wanted to do something with the objects that share the same material, you have the array 'theObjs' to work with
objList.items = theObjs
)

-- Select object from the second list
on selectObject pressed do
(
if objList.items.count > 0 do
(
myObj = (getNodeByName objList.selected)
if myObj != undefined do
(
select myObj
)
)
)
)
createDialog getMaterials 200 370
)

This will get all materials in a listbox, where you can choose one to get all the objects that share it. You can study the code, and if there's something I missed please let me know.

sunboy69
04-30-2008, 06:35 AM
This will get all materials in a listbox, where you can choose one to get all the objects that share it. You can study the code, and if there's something I missed please let me know.

Oh,dear,dear!It's perfect, you're talented labbejason,I must thank you very much.:beer:
The script will get all materials or objs,i'm thinking...
Can it get the repeated materials only?
In this way, I can find the objects in my scene which used the repeated materials quickly,so i can ammend them convenient!
And i'm studying it now...But have a little difficulty!

labbejason
04-30-2008, 07:36 AM
Here's the updated script:

(
-- UI
rollout getMaterials "Get Matching Materials"
(
listBox currentMaterials "Current Materials in Scene"
button getObjects "Get All Objects" width:175 height:15
listBox objList "Objects with matching materials"
button selectObject "Select Object" width:175 height:15

-- Populating first list of all current materials in the scene
on getMaterials open do
(
theMaterials = #() -- Array where we'll place all duplicate materials
for o in geometry where o.material != undefined do
(
-- Checks if material is already in theMaterials array, so we don't have multiple of the same material
if findItem theMaterials o.material.name == 0 do
(
-- Checks if this material is being used more than 1 in the scene, if it is, append it to the material
duplicateMats = for x in geometry where x.material != undefined and x.material.name == o.material.name collect x
if duplicateMats.count >= 2 do append theMaterials o.material.name
)
)
currentMaterials.items = theMaterials -- Populate list with material names
)

-- Populating second list of all objects with the selected material from the first list
on getObjects pressed do
(
theObjs = #() -- Array where we'll place all objects that have matching materials
for o in geometry where o.material != undefined do
(
-- Check if the object's material is a match with the current selected material from the first list
if o.material.name == currentMaterials.selected do append theObjs o.name
)

-- At this point, if you wanted to do something with the objects that share the same material, you have the array 'theObjs' to work with
objList.items = theObjs
)

-- Select object from the second list
on selectObject pressed do
(
if objList.items.count > 0 do
(
-- Search the node by using the current item name from the second list
myObj = (getNodeByName objList.selected)
if myObj != undefined do
(
-- If we find the object, select it
select myObj
)
)
)
)
createDialog getMaterials 200 370
)
I only had to tweak the event where it populates the first list, where now it needs to have at least 2 objects in the scene that have the material. If there's something in the code you are having trouble understanding, let me know and I'll try to make it more clear. I've included some new comments in it. Glad it's working so far :)

feilang
04-30-2008, 07:44 AM
hi sunboy,it's glad to see that someone helped you,I also learn much from the codes above:)

hey labbejason,I'll thank you for your codes too.

sunboy69
04-30-2008, 08:57 AM
I only had to tweak the event where it populates the first list, where now it needs to have at least 2 objects in the scene that have the material. If there's something in the code you are having trouble understanding, let me know and I'll try to make it more clear. I've included some new comments in it. Glad it's working so far :)

wa ha...labbejason.You're conscientious really,you made me feel like that you are my real brother!!:) I really don't know how to express my gratitude to you.

OKay,i will study your script carefully,if anything in trouble, i'll consult to you.Thanks very much!

I'm very glad there's such standout people in our forums,
Thanks labbejason,thanks our forums!

Hi Lwang, glad to see you too...thanks, hoping we could make progress together.

sunboy69
05-02-2008, 04:55 PM
Is the method feasible? If it is illogical,is there a better method to solve the problem?

sunboy69
05-04-2008, 05:53 AM
Ok```````````

CGTalk Moderation
05-04-2008, 05:53 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.