How to Copy values to "Clipboard"

How to Copy values to "Clipboard"

Anonymous
Not applicable
3,154 Views
9 Replies
Message 1 of 10

How to Copy values to "Clipboard"

Anonymous
Not applicable

Hi,

 

And thanks in advance, this forum has been helpful to me in scripting.

 

I have a small question:

 

I need to display or copy values to be saved onto memory clipboard. In other words just like CTRL+C copies a bunch of number values.

 

What I want to do (either of the following should work):

 

Method 01:

I want to take XYZ transforms of a selected object (run a short script on them that reverses Y axis to the opposite of what it is - example if the value is X=80 Y=-75 Z=200 It will switch it to X=80 Y=-75 Z=200) and display these numbers individually somewhere in the maxscript ui so I could CTRL+C on them and copy them in memory to paste it in another application.

 

I couldn't get anything to "write to"  maxscript UI since maxscript doesn't seem to provide a UI box to do this?

 

There is "EditText UI" but that's for manual writing of text I couldn't find a way to write to it via maxscript?

 

Or Method 02:

Same as above but instead of displaying I have three individual buttons for individual axis X,Y and Z - when pressed, they automatically copy the desired value of said axis onto memory ready to be pasted.

 

Thanks.

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
3,155 Views
9 Replies
Replies (9)
Message 2 of 10

denisT.MaxDoctor
Advisor
Advisor

your question is a little confusing .. to work with strings in the system Clipboard MXS provides methods:

getclipboardText()
setclipboardText <string>

see MXS help (Copy To and From Clipboard) for details. 

 

Which means you have to coerce <int> or <float> values as string, and put the result to the Clipboard.

 

Do you ask about anything else?

 

 

0 Likes
Message 3 of 10

Anonymous
Not applicable

Here's the script so far: now instead of the "Print" All i want to do is "copy" or "save" the value into memory automatically with that one button click so that i can CTRL+V it into another application outside max, say a notepad.

 

 

rollout Tools "Tool"
					   
					(

					Group "Copy Axis Values"
				(
					button Xposition "X Position" width:130 height:25
					button Yposition "Y Position" width:130 height:25
					button Zposition "Z Position" width:130 height:25
					button Xrotation "X Rotation" width:130 height:25
					button Yrotation "Y Rotation" width:130 height:25
					button Zrotation "Z Rotation" width:130 height:25
				)
				

					on Xposition pressed do
					(
				    Xpos = $.pos.controller[1].value
					print Xpos
					)
					
					
						on Yposition pressed do
					(
					Ypos = $.pos.controller[2].value
					print Ypos
					)
					
						on Zposition pressed do
					(
					Zpos = $.pos.controller[3].value
					print Zpos
					)
				

						 on Xrotation pressed do
					(
					Xrot = $.rotation.controller[1].value
					print Xrot
					)
					
							 on Yrotation pressed do
					(
                     Yrot = $.rotation.controller[2].value
					 InverseY= Yrot * -1
					 print InverseY
					)
					
							 on Zrotation pressed do
					(
					Zrot = $.rotation.controller[3].value
					print Zrot
					)
					

				)

                 	RolloutFloaterTemplate = newrolloutfloater "test" 270 700
					
					addrollout Tools RolloutFloaterTemplate 
			
		

 

0 Likes
Message 4 of 10

denisT.MaxDoctor
Advisor
Advisor

i show you full working snippet and the example of good MXS coding style:

 

try(destroydialog TakeTransformRol) catch()
rollout TakeTransformRol "Copy Transform" width:191
(
	group "Position: "
	(
		button x_pos_bt "X" width:53 across:3
		button y_pos_bt "Y" width:53
		button z_pos_bt "Z" width:53
	)
	group "Rotation: "
	(
		button x_rot_bt "X" width:53 across:3
		button y_rot_bt "Y" width:53
		button z_rot_bt "Z" width:53
	)

	fn copyNodePositionComponent node: index:1 =
	(
		if node == unsupplied do node = selection[1]
		if isvalidnode node do try
		(
			setclipboardtext (node.position.controller[index].value as string)
			format "% #position[%] >> %\n" node.name index (getclipboardtext())
		)
		catch()
	)
	fn copyNodeRotationComponent node: index:1 =
	(
		if node == unsupplied do node = selection[1]
		if isvalidnode node do try
		(
			setclipboardtext (node.rotation.controller[index].value as string)
			format "% #rotation[%] >> %\n" node.name index (getclipboardtext())
		)
		catch()
	)

	on x_pos_bt pressed do copyNodePositionComponent index:1
	on y_pos_bt pressed do copyNodePositionComponent index:2
	on z_pos_bt pressed do copyNodePositionComponent index:3

	on x_rot_bt pressed do copyNodeRotationComponent index:1
	on y_rot_bt pressed do copyNodeRotationComponent index:2
	on z_rot_bt pressed do copyNodeRotationComponent index:3
		
	
	on TakeTransformRol open do
	(
	)
)
createdialog TakeTransformRol

 

Message 5 of 10

denisT.MaxDoctor
Advisor
Advisor

what does this snippet show?

 

it shows that you can put a value to the clipboard and get it back.

using the clipboard you can "paste" its value to any "edit" control - textbox, edittext, spinner, etc.

any control that can get a text value to its "edit control" has to handle it the way it needs. You shouldn't care about it  

Message 6 of 10

Anonymous
Not applicable

Denis Thanks a lot I did learn from this! There is one last part still missing from it, the rotation Y axis value needs to be taken as "inverted", in my above script I was multiplying the value by -1, I tried to figure out a way to do that with your string setup but couldn't.

It will be great if you can show me that last bit on how to manipulate the values.

 

Thanks again!

0 Likes
Message 7 of 10

denisT.MaxDoctor
Advisor
Advisor

where do you want to put these position and rotation data?

0 Likes
Message 8 of 10

Anonymous
Not applicable

Hi Denis and thanks again in advance!

 

Ok the situation is simple, sometimes I have objects I need to position in Unreal Engine 4 following a reference new position I did in Max.

I have a bunch of actual objects imported in zero space in UE4 as should be. I need to move them in reference to a new position created in Max. I wouldn't want to import a new reference position object inside UE4 all the time and match values there, it gets a bit annoying and time consuming, instead I can copy paste values quickly from max to UE4 on that specific object and the object will move to that exact new position.

 

But its not as simple as that since UE4 Axis values are a little different, they are as follows:

 

position X: Same

Position Y: This needs to be the Opposite ( ex. if its value is 120 in max in Unreal it should be -120)

Position Z: same

 

Rotation X: Same

Rotation Y: Opposite

Rotation Z: Opposite

 

The reason I want this script is because in Max its still a good bit time consuming to open the dialog boxes and manually do this whole procedure and watch out for inverting values and so on.

 

Your script works perfectly well just need a way to invert some of those values.

 

Thanks!

 

 

 

 

0 Likes
Message 9 of 10

denisT.MaxDoctor
Advisor
Advisor
Accepted solution
try(destroydialog TakeTransformRol) catch()
rollout TakeTransformRol "Copy Transform" width:191
(
	group "Position: "
	(
		button x_pos_bt "X" width:53 across:3
		button y_pos_bt "Y" width:53
		button z_pos_bt "Z" width:53
		button ix_pos_bt "-X" width:53 across:3
		button iy_pos_bt "-Y" width:53
		button iz_pos_bt "-Z" width:53
	)
	group "Rotation: "
	(
		button x_rot_bt "X" width:53 across:3
		button y_rot_bt "Y" width:53
		button z_rot_bt "Z" width:53
		button ix_rot_bt "-X" width:53 across:3
		button iy_rot_bt "-Y" width:53
		button iz_rot_bt "-Z" width:53
	)

	fn copyNodePositionComponent node: index:1 negative:off =
	(
		if node == unsupplied do node = selection[1]
		if isvalidnode node do try
		(
			v = node.position.controller[index].value
			if negative do v = -v
			setclipboardtext (v as string)
			format "% #position[%] >> %\n" node.name index (getclipboardtext())
		)
		catch()
	)
	fn copyNodeRotationComponent node: index:1 negative:off =
	(
		if node == unsupplied do node = selection[1]
		if isvalidnode node do try
		(
			v = node.rotation.controller[index].value
			if negative do v = -v
			setclipboardtext (v as string)
			format "% #rotation[%] >> %\n" node.name index (getclipboardtext())
		)
		catch()
	)

	on x_pos_bt pressed do copyNodePositionComponent index:1
	on y_pos_bt pressed do copyNodePositionComponent index:2
	on z_pos_bt pressed do copyNodePositionComponent index:3
	on ix_pos_bt pressed do copyNodePositionComponent index:1 negative:on
	on iy_pos_bt pressed do copyNodePositionComponent index:2 negative:on
	on iz_pos_bt pressed do copyNodePositionComponent index:3 negative:on

	on x_rot_bt pressed do copyNodeRotationComponent index:1
	on y_rot_bt pressed do copyNodeRotationComponent index:2
	on z_rot_bt pressed do copyNodeRotationComponent index:3
	on ix_rot_bt pressed do copyNodeRotationComponent index:1 negative:on
	on iy_rot_bt pressed do copyNodeRotationComponent index:2 negative:on
	on iz_rot_bt pressed do copyNodeRotationComponent index:3 negative:on
		
	
	on TakeTransformRol open do
	(
	)
)
createdialog TakeTransformRol
Message 10 of 10

Anonymous
Not applicable

Absolute gold! Thanks Denis you've been of great help!

 

 

 

0 Likes