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

gone testing

first off it works!
I need your clarification:
If, Say I have 2 shortcuts:
1. 'R'- to copy mat+mod
2. 'T'- pastes the donor's mat+mod, keeps receiver's old mat name
2a.(Alt+Shift+T, Shift+T DO THE SAME, AM I CORRECT?)
2b. Alt+T - pastes mat ONLY, keeps receiver's old mat name.

What I noticed, the script tentatively inserts the donor's mesh, which sometimes could be huge and time consuming. could this mesh be substituted with say simple box
(mat+mod holder)?
Once again, salute!

miauu's picture

.

After 4 hours I have to go at work. When I go back home(after 24h shift) i will modify the script.
In the listenre will be printed what is happen - the mats or mats+mods are transmited to the receivers.

1rv's picture

Now I think all those key

Now I think all those key combinations just mess the things up. What do you think?
May be it'd be better to keep simple key hit for mat+mod+the old mat's name preserving,
AND hitting ALT+users key would pop-up the tiny window with following options (with combo boxes to check\uncheck:
1. keep the donor's mat name
2. don't transfer mods.
3. materials purging\instancing (tough one?):
a.instance all mats with the same name by inserted one;
b.instance all mats with the same maps\values by inserted one
BTW if the script could pick-up the isolated member of Multi\SubObject mat and do p.3
it'd be awesome.
Thank you for attention.

miauu's picture

.

I don't have much time, but try this:
When you dun the PASTE script it will create RC menu so you have to choose what action to be done. Feel free to change the names of the RC menu so you can undestand better what it will do.

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 with redraw off
	(
		curO = selection[1]
		b = box lengthsegs:1 widthsegs:1 heightsegs:1 isSelected:false
		b.name = ((timestamp()) as string) + "_" + ((timestamp()) as string)
		b.material = curO.material
		if curO.modifiers.count != 0 do
		(
			for m = curO.modifiers.count to 1 by -1 do
				addModifier b curO.modifiers[m]
		)
		saveNodes b thecopypastestring --this saves ("copies") the objects as a file
		delete b	
	)
)
 
 
macroScript Paste_MaterialsAndModifiers_From_File Category:"CG_Tools" toolTip:"Paste MatsAndMods from File"
(
	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
					i.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()
		)
	)
	function CopyMatAndMods01 oldName:true copyMods:true =
	(
		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 do
			(
				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 do
				(
					CopyMatAndMods obj selObjsArr parent_array keepMatName:oldName copyMods:copyMods
				)
				--
				delete obj
				select selObjsArr
			)
		)	
	)
 
	rcMenu rcMapSize
	(
		menuItem matModOld "Transfer Mat + Mod + Old Mat Name" checked:false
		menuItem matMotKeep "Transfer Mat + Mod + Keep Mat Name" checked:false
		menuItem matOld "Transfer Mat + Old Mat Name" checked:false
		menuItem matKeep "Transfer Mat + Keep Mat Name" checked:false
 
		on matModOld picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:true copyMods:true
		)
		on matMotKeep picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:false copyMods:true
		)
		on matOld picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:true copyMods:false
		)
		on matKeep picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:false copyMods:false
		)		
	) 
	popUpMenu rcMapSize pos:mouse.screenpos
)
1rv's picture

man it's fantastic, many

man it's fantastic, many thanks!
RC menu suites the best, but may be you could still ADD the possibility to the first option (mat+mod+old name) get executed with Cntl+key (just because it will be choosen in 90% of the cases)?
Once again, many thanks!

miauu's picture

.

When you run the script:
- click in the viewport will perform mat+mod+old mat name
- shift+click will invoke the rc menu

macroScript Paste_MaterialsAndModifiers_From_File Category:"CG_Tools" toolTip:"Paste MatsAndMods from File"
(
	global miauuMouseToolCopyPasteMatsAndMods
 
	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
					i.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()
		)
	)
	function CopyMatAndMods01 oldName:true copyMods:true =
	(
		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 do
			(
				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 do
				(
					CopyMatAndMods obj selObjsArr parent_array keepMatName:oldName copyMods:copyMods
				)
				--
				delete obj
				select selObjsArr
			)
		)	
	)
 
	rcMenu rcMapSize
	(
		menuItem matModOld "Transfer Mat + Mod + Old Mat Name" checked:false
		menuItem matMotKeep "Transfer Mat + Mod + Keep Mat Name" checked:false
		menuItem matOld "Transfer Mat + Old Mat Name" checked:false
		menuItem matKeep "Transfer Mat + Keep Mat Name" checked:false
 
		on matModOld picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:true copyMods:true
		)
		on matMotKeep picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:false copyMods:true
		)
		on matOld picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:true copyMods:false
		)
		on matKeep picked do with undo "Smart Spline Extrude" on
		(
			CopyMatAndMods01 oldName:false copyMods:false
		)		
	) 
 
	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
		(
			if clickno == 1 then
			(
				if keyboard.ShiftPressed then
				(
					popUpMenu rcMapSize pos:mouse.screenpos
				)
				else
				(
					CopyMatAndMods01 oldName:true copyMods:true
				)
				#stop
			)
			else
				#stop
		)
	)
	startTool miauuMouseToolCopyPasteMatsAndMods
)
1rv's picture

fantastic script,- put it

fantastic script,- put it into your pack! and sorry if I tortured you too much :)

1rv's picture

hm.. I can't make it work the

hm.. I can't make it work the new way- still only RC menu. What Am I Doing Wrong?

miauu's picture

.

Assign a hotkey to run the script
Press the hotkey
click anywehere in the screen.
If you have selected objects the script will transfer mat+mods+old mat names.

If you shift+click the RC menu will appear.

1rv's picture

..

it's OK now:)

Comment viewing options

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