Merge Objects In, Apply a Material...

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2013   #1
Merge Objects In, Apply a Material...

This 'should' be simple, but it's not....

Use the attached file...

theObjs = #()
mergeObjs = #()
max select none
mergeObjs = getMAXFileObjectNames "C:\\temp\\NameTest.max"
Mergemaxfile "C:\\temp\\NameTest.max" #select #renameMtlDups #autoRenameDups
for o in mergeObjs do append theObjs (getnodebyname o)

theMat = Standardmaterial diffuse:((color 255 0 0)) selfillumination:100

for o in theObjs where isvalidnode o do o.material = theMat


or

theObjs = #()
max select none
mergeObjs = getMAXFileObjectNames "C:\\temp\\NameTest.max"
Mergemaxfile "C:\\temp\\NameTest.max" #select #renameMtlDups #autoRenameDups

theMat = Standardmaterial diffuse:((color 255 0 0)) selfillumination:100

for o in selection do o.material = theMat


Neither work for the attached scene.
Attached Files
File Type: zip NameTest.zip (18.4 KB, 1 views)
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 02 February 2013   #2
Unless I'm missing something obvious the only way to deal with this situation is to get a list of the objects before merging in and then see what extra ones you have after merging!?

pObjects = objects as array
theObjs = #()

max select none
try(Mergemaxfile "C:\\temp\\NameTest.max" #select #renameMtlDups #autoRenameDups)catch()

for o in objects where finditem pObjects o == 0 do append theObjs o

theMat = Standardmaterial diffuse:((color 255 0 0)) selfillumination:100

for o in theObjs do o.material = theMat
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 02 February 2013   #3
you can remember the number of objects before merge. and all merged objects will be after this number in objects list

of course it is if you not replace dups.
 
Old 02 February 2013   #4
I once build something like that and I used the .inode.handle property of all existing nodes and compared that to the node handles after the merge. The different ones are obviously the merged nodes, can't remember if merge dups are handled correctly, you should check.

*edit* Quick test shows the handle gets "updated" or replaced by the merged object. This seems pretty save for this sort of thing.

-Johan
__________________
Online: LinkedIn
 
Old 02 February 2013   #5
EDIT: Crap, I didn't see your second post. Ignore this!

I imagine there are more computationally effective ways of doing it but...

origObjs = objects as array
Mergemaxfile "C:\\temp\\NameTest.max" #select #renameMtlDups #autoRenameDups
allObjs = objects as array
NewObhs = objects as array
for a_var in origObjs do
(
	for b_var in allObjs.count to 1 by -1 do
	(
		if a_var == allObjs[b_var] do
		(
			deleteitem allObjs b_var
		)
	)
)
theMat = Standardmaterial diffuse:((color 255 255 0)) selfillumination:100
for c_var in allObjs do c_var.material = theMat


Works. It basically makes an array of the current objects, merges file, creates another array, removes the first array from the latter (leaving an array of the new objects) and assigns materials based on that. So it works in scenes with objects already in.
__________________

 
Old 02 February 2013   #6
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:00 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.