mergeMaxFile nodes to array

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 04 April 2012   #1
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?


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 April 2012   #2
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...

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 April 2012   #3
This is how I've done it in the past:
(
	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 April 2012   #4
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 April 2012   #5
why not just GetCurrentSelection() after the merge?
 
Old 04 April 2012   #6
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:

 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 April 2012 at 04:45 PM.
 
Old 04 April 2012   #7
Originally Posted by Raytracer05: This is how I've done it in the past:
(
  	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 April 2012   #8
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 April 2012   #9
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 April 2012   #10
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 April 2013   #11
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 April 2013   #12
Ok, here's another version that could work.
This one works with #autoRenameDups, AND hidden layers (as we're not using #select).


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 April 2013   #13
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).


 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 April 2013   #14
do it simple... you don't need any name comparison or search by name. do it by node:

(
	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 April 2013   #15
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



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 04:43 PM.


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