CGTalk > Software Specific Forums > 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 04-25-2012, 02:05 PM   #1
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,296
Send a message via AIM to JokerMartini
mergeMaxFile nodes to array

What is the best and easiest way to put the incoming merged objects into an array?
Without having to do the select properties of the mergeMaxFile?

Code:
delete objects fxFile = @"C:\Users\Crabs User\Documents\3dsMax\scenes\test.max" --//Merge New Particles system mObjNames = getmaxfileobjectnames fxFile -- get the object names from the file great = mergemaxfile fxFile mObjNames #AutoRenameDups #renameMtlDups --#select -- merge in the objects and select them clearlistener() print great
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-25-2012, 02:32 PM   #2
Rotu
Not a new member.
Richard Katz
Senior Technical Artist
Blizzard Entertainment
Irvine, USA
 
Join Date: Aug 2004
Posts: 33
I've been using select and throwing selected into a layer right after the merge, but one thing that comes to mind is getting the scene objects before and after the merge...

Code:
scnObj = for o in objects collect o fxFile = @"C:\Users\Crabs User\Documents\3dsMax\scenes\test.max" mObjNames = getmaxfileobjectnames fxFile -- get the object names from the file mergemaxfile fxFile mObjNames #AutoRenameDups #renameMtlDups --#select -- merge in the objects and select them postMergeObj = for o in objects collect o for o in scnObj do ( local oIdx = findItem postMergeObj o if (oIdx>0) then (deleteItem postMergeObj idx) ) print postMergeObj
It's probably on the slow side though.
 
Old 04-25-2012, 02:43 PM   #3
Raytracer05
Frequenter
portfolio
Dan Brew
TSK group plc
Manchester, United Kingdom
 
Join Date: Jul 2010
Posts: 189
This is how I've done it in the past:
Code:
( firstObj = (objects.count)+1 mergeMAXFile "file path here!" if objects.count >= firstObj do ( lastObj = objects.count mergedObj = for objI = firstObj to lastObj collect (objects[objI]) ) )
 
Old 04-25-2012, 04:22 PM   #4
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,296
Send a message via AIM to JokerMartini
Thanks guys for the different methods for use.
Rotu - Your snippet was the same thing I came up with when merging in objects. I was not sure if there was a less taxing way of doing it. I say taxing becomes some scenes I'm working in have mass amounts of objects.

I'll test out the methods and see which is faster.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-25-2012, 04:27 PM   #5
lo
the frequentest!
portfolio
Rotem Shiffman
Tel Aviv, Israel
 
Join Date: Jul 2005
Posts: 2,826
why not just GetCurrentSelection() after the merge?
 
Old 04-25-2012, 04:42 PM   #6
PiXeL_MoNKeY
Expert
 
PiXeL_MoNKeY's Avatar
Eric Craft
Dallas, USA
 
Join Date: Mar 2002
Posts: 5,634
Why not use getNodeByName using the original mNameObjs to loop through? Probably be good to verify that the object is a valid object to begin with like this:
Code:
objArr = for obj in mObjNames where (isValidnode (getnodebyname obj)) collect (getnodebyname obj) select objArr

-Eric

EDIT: Though with your current setup that may be an issue and you should probably replace #AutoRenameDups to #mergeDups to ensure the names from the original file will match those in the current file.
__________________
"The Evil Monkey hiding in your closet."

Last edited by PiXeL_MoNKeY : 04-25-2012 at 04:45 PM.
 
Old 04-25-2012, 04:56 PM   #7
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,192
Send a message via ICQ to denisT
Quote:
Originally Posted by Raytracer05
This is how I've done it in the past:
Code:
( firstObj = (objects.count)+1 mergeMAXFile "file path here!" if objects.count >= firstObj do ( lastObj = objects.count mergedObj = for objI = firstObj to lastObj collect (objects[objI]) ) )


that's what i am using for many years too. i don't know a faster way.
the only problem is that doesn't work with the #deleteOldDups option. so if we are looking for an universal solution it's to merge with #select option and get selection after.

 
Old 04-25-2012, 05:09 PM   #8
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,296
Send a message via AIM to JokerMartini
Hey Eric,
Thanks for the idea. My only concern with that is the name will not match after merging if there are duplicates. Max will autorename the objects. In return making getNodeByName not work properly.

I had initially tried that and it didn't seem reliable.

I'll try doing something along these lines.
Merge with #select and place that to an array, then restore the users original selection.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-25-2012, 05:12 PM   #9
PiXeL_MoNKeY
Expert
 
PiXeL_MoNKeY's Avatar
Eric Craft
Dallas, USA
 
Join Date: Mar 2002
Posts: 5,634
Hence my edit, from the maxscript help:
Quote:
#mergeDups Ignore name conflicts, merge anyway resulting in possibly duplicated names.
__________________
"The Evil Monkey hiding in your closet."
 
Old 04-25-2012, 05:48 PM   #10
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,296
Send a message via AIM to JokerMartini
Yeah, your right.
I'll see what I can come up with and what works. I'll be sure to let you guys know.
Thanks for the ideas guys.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-25-2013, 12:34 PM   #11
MrPingouin
Veteran
 
MrPingouin's Avatar
Laurent Chea
Paris, France
 
Join Date: Aug 2005
Posts: 65
This is damned crazy.

In my case I have to do this but handling duplicates.

One workaround I found (but I have to check if it's correct), is to use getMaxFileObjectNames as you people did, and "guess" how 3dsmax will change the object names using uniqueName function.

I just hope that when you specify #AutoRenameDups, 3dsmax uses uniqueName, but who can tell...
 
Old 04-25-2013, 01:07 PM   #12
MrPingouin
Veteran
 
MrPingouin's Avatar
Laurent Chea
Paris, France
 
Join Date: Aug 2005
Posts: 65
Ok, here's another version that could work.
This one works with #autoRenameDups, AND hidden layers (as we're not using #select).

Code:
objNameToMerge = getMaxFileObjectNames maxfile mergedObjNames = #() mergedObj = #() for n in objNameToMerge do ( -- We check if a node with this name already exists or not, if not it won't be renamed. if (getNodeByName n) != undefined then n = uniqueName n append mergedObjNames n ) mergeMaxFile maxfile objNameToMerge #AutoRenameDups #useSceneMtlDups for n in mergedObjNames do ( append mergedObj (getNodeByName n) )
 
Old 04-25-2013, 01:16 PM   #13
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,192
Send a message via ICQ to denisT
Quote:
Originally Posted by MrPingouin
Ok, here's another version that could work.
This one works with #autoRenameDups, AND hidden layers (as we're not using #select).

Code:
objNameToMerge = getMaxFileObjectNames maxfile mergedObjNames = #() mergedObj = #() for n in objNameToMerge do ( -- We check if a node with this name already exists or not, if not it won't be renamed. if (getNodeByName n) != undefined then n = uniqueName n append mergedObjNames n ) mergeMaxFile maxfile objNameToMerge #AutoRenameDups #useSceneMtlDups for n in mergedObjNames do ( append mergedObj (getNodeByName n) )

no... it's not correct. what if you merge multiple nodes with the same name?
 
Old 04-25-2013, 01:29 PM   #14
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,192
Send a message via ICQ to denisT
do it simple... you don't need any name comparison or search by name. do it by node:
Code:
( delete objects for k=1 to 5000 do box() -- current scene objects oldnodes = objects as array for k=1 to 1000 do dummy() -- merged objects newnodes = objects as array t1 = timestamp() while oldnodes.count > 0 do ( if isvalidnode oldnodes[1] do ( k = finditem newnodes oldnodes[1] if k != 0 do deleteitem newnodes k ) deleteitem oldnodes 1 ) newnodes.count format "all nodes:% merged nodes:% time:%\n" objects.count newnodes.count (timestamp() - t1) )

as you can see for 5000 nodes and 1000 merged it takes almost nothing
 
Old 04-25-2013, 01:38 PM   #15
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,192
Send a message via ICQ to denisT
i don't remember now why but in some situations i couldn't use merge with #select option. probably it was something about selection changed notification.
 
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 01:58 AM.


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