copy mat+modifiers from file A to file B (object to object)

http://3d-kstudio.com/3ds-max-plugins-scripts/trackscripts/#CopyMaterial...

There's some brilliant script in the Track's pack that copies material and modifiers (with Shift+click) from one object to another within one file.
Could there be a similar tool that does the same between objects in separate files?
Thank you in advance.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
1rv's picture

May be it would help you to

May be it would help you to shorten the things..
Alex, the author of original script helped me to cook alternative version that keeps original mat name:

in TrackScripts.mcr, find the fragment

MacroScript CopyMat category:"Track" tooltip:"Copy Material and Modifiers" Icon:#("Material_Modifiers",3)(

in the function the line

for i in selobjs do i.material=obj.material

to be replaced with:

for i in selobjs do
(
local oldName = i.material.Name
i.material = obj.material
i.material.Name = oldName
)

---
It worked well, but what I didn't like in this alternative (please pay attention to this case) is the Error pop-ups when the receiver had no
material (and it's name of course) before mat switching.
Thank you, Miauu once again

miauu's picture

.

Test the scripts. I have made some changes to the Copy_ script. The saved object will be saved with unique name, so when you use the Paste script there will be no problems when you have object with the same name in the scene(there is a built-in solution for cases like this, but they will works on max2011+).
The Paste script works as follows:
- run it and click anywhere in the viewport. The Alt and Alt+Shift keys will works as is described in the code.

macroScript Copy_MaterialsAndModifiers_To_File Category:"CG_Tools" toolTip:"Copy MatsAndMods to File"
(
    thecopypastedir = getdir #autoback -- CHANGE THIS TO ANY FOLDER YOU WANT
    thecopypastefile = "\pastefile.max" --this is the filename to save as...
    thecopypastestring = thecopypastedir + thecopypastefile --this is the complete string
 
    if selection.count == 1 do
	(
		c = copy selection[1]
		c.name = ((timestamp()) as string) + "_" + ((timestamp()) as string)
		saveNodes c thecopypastestring --this saves ("copies") the objects as a file
                delete c		
	)
)
 
macroScript Paste_MaterialsAndModifiers_From_File Category:"CG_Tools" toolTip:"Paste MatsAndMods from File"
(
	global miauuMouseToolCopyPasteMatsAndMods
	tool miauuMouseToolCopyPasteMatsAndMods
	(
		-- -- set up so that a node is created on a mouse button down, move node -- drag, release node at mouse button up. -- -- if clickno == 1, then we are at first mouse click, which is a mouse -- button down. If clickno != 1, at following mouse button up.
		on mousePoint clickno do
		(
			function CopyMatAndMods obj selObjsArr parent_array keepMatName:true copyMods:true =
			(
				if obj.material != undefined do
				(
					for i in selObjsArr do
					(
						oldName = if i.material != undefined then i.material.name else undefined
						i.material = obj.material
						if keepMatName == true and oldName != undefined do
							obj.material.name = oldName
					)
				)
				if copyMods == true do
				(
					try
					(
						x = obj.modifiers.count+1
						while x > 1 do
						(
							objmod = obj.modifiers[x-=1]
							for obj in parent_array do addModifier obj objmod
						)
					)catch()
				)
			)
			if clickno == 1 then
			(
				if selection.count != 0 then with redraw off
				(
					local    selObjsArr
					local    parent_array = #()
					local    temp_array = #()
 
					selObjsArr = for o in selection as array where isGroupHead o == false collect o
 
					if selObjsArr.count != 0 then
					(
						for i in selObjsArr where (finditem temp_array i == 0) do
						(
							InstanceMgr.GetInstances i &inst_array
							append parent_array inst_array[1]
							join temp_array inst_array
						)
 
						thecopypastedir = getdir #autoback -- CHANGE THIS TO ANY FOLDER YOU WANT
						thecopypastefile = "\pastefile.max" --this is the filename to save as...
						thecopypastestring = thecopypastedir + thecopypastefile --this is the complete string
 
						mergemaxfile (thecopypastedir + thecopypastefile) #select --this merges ("pastes") and selects objects from file
						obj = selection[1]		
						-- 
						if obj!=undefined then
						(
							if keyboard.AltPressed and keyboard.ShiftPressed then
							(
								print "Material and Modifiers are copied. Original Material's Name is preserved"
								CopyMatAndMods obj selObjsArr parent_array keepMatName:true copyMods:false
							)
							else
							(
								if keyboard.AltPressed then
								(
									print "Material is copied. Original Material's Name is preserved"
									CopyMatAndMods obj selObjsArr parent_array keepMatName:true copyMods:false
								)	
								else
								(
									print "Material and Modifiers are copied"
									CopyMatAndMods obj selObjsArr parent_array keepMatName:true copyMods:true
								)
							)
						)
						--
						delete obj
						select selObjsArr
						#stop
					)
					else
						#stop
				)
				else
					#stop
			)
			else
				#stop
		)
	)
	startTool miauuMouseToolCopyPasteMatsAndMods
)
1rv's picture

Mate, it works precisely as

Mate, it works precisely as expected! Amazing, thank you so much!
Now the routine of revisions (I import models from Sketchup) will be much more easier.
Thought about some polishing:
1. IF ADDITIONALLY , the ALT key will be used, so the object-receiver would get the mat, but preserve its original mat name (only name!)
2. IF ADDITIONALLY , the ALT+SHIFT key will be used, so the receiver object would preserve its original mat name (only name!) and receive mat+UVW.
NB: If there's no mat upon the receiver the script, the shouldn't be the Error pop-up.
Is it possible?
---
Once again, thank you!

miauu's picture

.

Now you can't use Alt, Shift or Ctrl to achieve different results because the script is a macro and if you run it with hotkey then the keyboard kyes can't be used. Tommorow I will ty to add what you have asked and will change the way of how the script works so you can use it with a hotkey.

1rv's picture

@fajar: No, it's

@fajar: No, it's overcomplicated, I dreamt about something elegant, fluent and easy like eye dropper. Essentially the Track's script is ideal (the main limitation it works within one file).
@miauu My bad :( by saying modifiers I meant UVW mod. So is my humble request doable?
Thank you in advance.

miauu's picture

.

You will have two instances of 3dsMax running at the same time or the situation is different?

1rv's picture

Yep, 2 (BTW are 2+ instances

Yep, 2 (BTW are 2+ instances of 3ds max problem?) Windows of Max will be open side by side.
This is how I see this tool :
1. In file A, select object-donator and hit shortcut (i.e. Cntl+C for mat copy only, Cntl+Shift+C for copying mat+UVW mod)
2. In file B,select object and hit shortcut (i.e. Cntl+V for mat paste only, Cntl+Shift+V for pasting mat+UVW mod)
3. Profit..

BTW may be it will also help:

http://www.scriptspot.com/3ds-max/scripts/copy-and-paste-objects

http://www.scriptspot.com/3ds-max/scripts/copypaste-material-to-file

Use them constantly

miauu's picture

.

Test the scripts below. I just combined(with little modification) the Track's and Christopher Grant's scripts.

</p>
<p>macroScript Copy_MaterialsAndModifiers_To_File Category:"CG_Tools" toolTip:"Copy MatsAndMods to File"<br>(<br>&nbsp;&nbsp;&nbsp; thecopypastedir = getdir #autoback -- CHANGE THIS TO ANY FOLDER YOU WANT<br>&nbsp;&nbsp;&nbsp; thecopypastefile = "\pastefile.max" --this is the filename to save as...<br>&nbsp;&nbsp;&nbsp; thecopypastestring = thecopypastedir + thecopypastefile --this is the complete string<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; if selection.count == 1 do <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; saveNodes $ thecopypastestring --this saves ("copies") the objects as a file<br>)<br>&nbsp;<br>macroScript Paste_MaterialsAndModifiers_From_File Category:"CG_Tools" toolTip:"Paste MatsAndMods from File"<br>(<br>&nbsp;&nbsp;&nbsp; if selection.count != 0 then with redraw off<br>&nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; local&nbsp;&nbsp;&nbsp; selobjs<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; local&nbsp;&nbsp;&nbsp; parent_array = #()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; local&nbsp;&nbsp;&nbsp; temp_array = #()<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; selobjs = for o in selection as array where isGroupHead o == false collect o<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for i in selobjs where (finditem temp_array i == 0) do <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; InstanceMgr.GetInstances i &amp;inst_array<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; append parent_array inst_array[1]<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; join temp_array inst_array<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; thecopypastedir = getdir #autoback -- CHANGE THIS TO ANY FOLDER YOU WANT<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; thecopypastefile = "\pastefile.max" --this is the filename to save as...<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; thecopypastestring = thecopypastedir + thecopypastefile --this is the complete string<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mergemaxfile (thecopypastedir + thecopypastefile) #select --this merges ("pastes") and selects objects from file<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; obj = selection[1]<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if obj!=undefined then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if obj.material!= undefined do <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for i in selobjs do i.material=obj.material<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; format (obj.material.name + "\n")<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; x=obj.modifiers.count+1<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while x&gt;1 do<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; objmod=obj.modifiers[x-=1]<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for obj in parent_array do addModifier obj objmod<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )catch()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete obj<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; select selobjs<br>&nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; messagebox "Select som eobjects" title:"Empty Selection"&nbsp;&nbsp;&nbsp; <br>)</p>
<p>

fajar's picture

the way to do it , may be

the way to do it , may be make little box dummy object then copy selected object material & modifier to box dummy and save node those box and then load the box dummy to another file then apply to desired object on those file [file 2]

miauu's picture

.

There is one thing tht you should to know - you can't copy the Edit Poly modifier. The script will add is as a modifier to the new object, but it will be as new modifier. All changes to geometry that the original Edit Poly mod has made to the object will not be applied to the new object(where the copy is applyed).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.