Notifications
Clear all

[Closed] Copy/Paste (X,Y,Z) Values from an object

Greetings,

I am in the process of creating a script that allows me to copy/paste coordinates in translation values from an object.

*Before anyone suggests using the align tool, I need to copy the translation coordinates from an object before a load animation and paste the coords on the same object (after the animation load). So, align tool is not what I am after.

The script below is very similar to what I am trying to do, but without the checkboxes and other misc.:
http://www.scriptspot.com/3ds-max/scripts/copy-paste-transforms

Summary:
Have two GUI buttons “Copy” and “Paste”

  1. Select object
  2. “Copy” (button) translation coords
  3. “Paste” (button) the values onto a selected object

I hope that is understandable. Much appreciated for any advice as I had not found any relatable threads!

5 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

do you intend to write code yourself or not?

I fully understand why you cant find any relatable threads

Of course I will, I was just a bit hesitant what to include as it is a lot to paste onto here! Understood your point. I am planning to add this to another script that I have written.

Anyway, this is what I have now, but it is not there yet. First of all, I am a bit confused on the copy/paste mechanics as can be seen below.

rollout Tools "Tools" width:265 height:105
(
	GroupBox 'groupbxTranslation' "Translation" pos:[28,3] width:198 height:73 align:#left
	button 'copyPos' "Copy" pos:[49,27] width:70 height:33 align:#left
	button 'pastePos' "Paste" pos:[138,27] width:70 height:33 align:#left
	
	-- Copy Position Code
	on copyPos pressed do
	(
	TranslationSelection = getCurrentSelection()
	
	if TranslationSelection.count != 0 then
	(
	select TranslationSelection [1]
	CurrentTranslation = $.pos.controller.value
	)

)
	
	-- Paste Position Code
	on pastePos pressed do
	(
	undo "Paste Position" on (
	
	if CurrentTranslation != 0 then 
	(
	
	TranslationPos = getCurrentSelection()  
		
	(
	select TranslationPos
	$.pos.controller.value = CurrentTranslation
	)
	
	) 
	
	) 
	
	)
)

rdFloater = newrolloutfloater "Tools" 275 105

addrollout Tools rdfloater
try(destroydialog rol) catch()
rollout rol "Test" width:191
(
	local last_pos
	
	button copy_pos_bt "Copy" width:89 align:#left offset:[-8,0] across:2 tooltip:"Copy Current Position"
	button paste_pos_bt "Paste" width:89 align:#right offset:[8,0] tooltip:"Paste Current Position"
	
	on copy_pos_bt pressed do if isvalidnode (node = selection[1]) do last_pos = node.pos
	on paste_pos_bt pressed do undo "Paste Pos" on 
	(
		if (selection.count > 0 and iskindof last_pos Point3) do 
		(
			selection.pos = last_pos
		)
	)
)
createdialog rol

working with this snippet you will see that we can copy/paste pos for one object, multiple objects, and between different objects if we change selection for source and target

it’s very simple.

the most complicated part will be when you will try to set position in another than #world coordinate system (#parent is for example)

Perfect, thank you! I was overcomplicating the code on my part… Was able to make a few other additions to personalize it.

Moving off-topic slightly, but the same general idea but regarding complex “rotations.” I would imagine I would need get eulerAngles of the first selected object rather than quaternions (as I would not need to worry about gimbal lock here) then paste the needed values onto the second object.

What would I need to do in a similar fashion to the local translation copy/paste for rotations?

Edit:
Anyway, found a solution to copy/pasting rotation values. Hopefully someone will find this useful in the future!

rollout Tools "Tools" width:265 height:105
(
	local last_rotation
	
	GroupBox 'groupbxRotation' "Rotation" pos:[28,3] width:198 height:73 align:#left
	button 'copyRot' "Copy" pos:[49,27] width:70 height:33 align:#left
	button 'pasteRot' "Paste" pos:[138,27] width:70 height:33 align:#left
	

	on copyRot pressed do if isValidNode $ then
	(
		last_rotation = $.rotation
		pasteRot.enabled = on	
	)	
	else messageBox "Please select one object."	
	
	on pasteRot pressed do
		if isKindof last_rotation Quat do with undo "Paste Rotation" on
			for obj in selection do
			(
				local pos = obj.pos
				obj.rotation = last_rotation
				obj.pos = pos	
			)
)

rdFloater = newrolloutfloater "Tools" 275 105

addrollout Tools rdfloater