CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 02-25-2013, 11:53 AM   #1
DaveWortley
<database error>
 
DaveWortley's Avatar
portfolio
David Wortley
Technical Director
London, United Kingdom
 
Join Date: Dec 2004
Posts: 1,845
Send a message via MSN to DaveWortley
Merge Objects In, Apply a Material...

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

Use the attached file...

Code:
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

Code:
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-25-2013, 12:01 PM   #2
DaveWortley
<database error>
 
DaveWortley's Avatar
portfolio
David Wortley
Technical Director
London, United Kingdom
 
Join Date: Dec 2004
Posts: 1,845
Send a message via MSN to DaveWortley
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!?

Code:
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-25-2013, 12:21 PM   #3
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
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-25-2013, 06:10 PM   #4
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,715
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 | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Old 02-26-2013, 11:21 AM   #5
DanGrover
Know-it-All
portfolio
Dan Grover
Technical Director
River Film
London, United Kingdom
 
Join Date: Sep 2004
Posts: 355
Send a message via MSN to DanGrover
EDIT: Crap, I didn't see your second post. Ignore this!

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

Code:
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-26-2013, 11:21 AM   #6
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:10 AM.


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