Import position data

Moderators: Disciple, zlovatt

Post Reply
salvazalvi
Posts: 36
Joined: September 21st, 2004, 7:29 am

Hi,

I'm trying to import a position info from 3ds max. Someone wrote me a script that wrote the position of an 3d object and saved it in a txt file (reversing the y and z coordinates) with the same formatting as AE writes when copying keyframes data to a text file.

Now, AE doesn't seem to accept back the position data. Have you encountered this problem ? Does any of you have a work around ?

Any help would be great.

Thanks,

salvazalvi
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

Do a side-by-side comparison of the text generated when you paste AE position data into a text editor with the the text generated by your script. The header stuff has to match exactly. Maybe your script was written for an earlier version of AE?

Dan
salvazalvi
Posts: 36
Joined: September 21st, 2004, 7:29 am

I've tried to paste back a position text generated by after (Copy position keyframes and paste in notepad) but AE didn't recognize it's own file.

Does this usually work ? Am I doing something wrong ?

Thanks,

salvazalvi
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

>Does this usually work ?

Yes, you only have to copy the data from Notepad, select the target layer, and paste. The keyframe data will find it's way to the Position property (AE 6.5).

>Am I doing something wrong ?

Somewhere in the process. Does your keyframe data in Notepad look something like this:

Adobe After Effects 6.5 Keyframe Data

Units Per Second 29.97
Source Width 50
Source Height 50
Source Pixel Aspect Ratio 0.9
Comp Pixel Aspect Ratio 0.9

Position
Frame X pixels Y pixels Z pixels
0 102 63 0
30 589 72 0
61 584 402 0


End of Keyframe Data


Dan
salvazalvi
Posts: 36
Joined: September 21st, 2004, 7:29 am

Well, I don't know what I was doing wrong, it works now.

Thanks, I'll check, maybe there is a hidden tabulation somewhere in my script.

Thank you,

salvazalvi
hemanth
Posts: 9
Joined: August 2nd, 2005, 3:36 am

can u plz share the scrpt that u have to get max data to ae plz

thanks

hemanth
salvazalvi
Posts: 36
Joined: September 21st, 2004, 7:29 am

Code: Select all

POS_Fltr = newRolloutFloater "POS Tools , Xoff 2005 v0.0.1 230305 " (150) (190)

rollout skin_rollout "POS saver - Xoff 2005" 
(
	spinner spnStart "Start Frame" type:#integer range:[0,100000,0]
	spinner spnEnd "End Frame" type:#integer range:[0,100000,0]
	label lbl0
	checkbox chkAfter "After Effect" checked:true
	label lbl1
	button btnSaveModifier "Save POS"
	button btnSaveCameraFOV "Save FOV"
	on skin_rollout open do
	(	
		Global MyPath = maxfilepath
		spnStart.value = animationRange.start
		spnEnd.value = animationRange.end
		-------------------------------------------------------------  F U N C T I O N S  -----------------------
		Global GetWeights
		fn GetWeights obj =
		(
			WeightsArray = #()
			max modify mode
			if classof obj[4][1].value == skin then
			(
				for vtxID = 1 to skinops.getnumbervertices obj[4][1] do
				(
					for vtxCount = 1 to  skinops.getvertexweightcount obj[4][1] vtxID do
					(
						BoneID = skinops.getvertexweightboneID obj[4][1] vtxID vtxCount
						MyWeight = skinOps.GetVertexWeight obj[4][1] vtxID vtxCount
						append WeightsArray vtxID
						append WeightsArray BoneID
						append WeightsArray myWeight
					)			
				)
			)
		return WeightsArray
		)
		
		global copyVtxweight
		fn copyVtxweight obj =
		(
			CopyArray = #()
			if classof obj[4][1].value == skin then
			(
				for vtxID = 1 to skinops.getnumbervertices obj[4][1] do
				(
					if skinops.isvertexselected obj[4][1] vtxID == 1 then
					(
						for vtxCount = 1 to  skinops.getvertexweightcount obj[4][1] vtxID do
						(
							BoneID = skinops.getvertexweightboneID obj[4][1] vtxID vtxCount
							MyWeight = skinOps.GetVertexWeight obj[4][1] vtxID vtxCount
							append CopyArray BoneID
							append CopyArray myWeight
						)
					)
				)
			)
			return CopyArray
		)
		
		Global pasteVtxweight
		fn pasteVtxweight obj tmpBones tmpWeights =
		(
			for vtxID = 1 to skinops.getnumbervertices obj[4][1] do
			(
				if skinops.isvertexselected obj[4][1] vtxID == 1 then
				(		
					skinOps.ReplaceVertexWeights obj[4][1] VTXID tmpBones tmpWeights
				)
			)
		)
		
		------------------------------------------------------------------------------------------------------------
		Global InitializeEnv
		fn InitializeEnv obj =
		(
			max modify mode
			if classof obj[4][1].value == skin then
			(
				for vtxID = 1 to skinops.getnumbervertices obj[4][1] do
				(
					for thisBone = 1 to  skinops.getnumberBones obj[4][1] do
					(
						for CSCount = 1 to skinOps.GetNumberCrossSections obj[4][1] thisBone do
						(
							skinOps.setOuterRadius obj[4][1] thisBone CSCount 0
							skinOps.setInnerRadius obj[4][1] thisBone CSCount 0
						)
						skinOps.ReplaceVertexWeights obj[4][1] vtxID thisbone 0 
					)
				)
			)
		)
		------------------------------------------------------------------------------------------------------------	
	
		Global Write_File				-- W R I T E
		fn Write_File MyPOSFileName MyDataArray =
		(
			try
			(
				myFSValue = createfile MyPOSFileName			
				if myFSValue != undefined  then
				(
					print MyDataArray
					print (MyPOSFileName + " created")
					myFSValue = openfile MyPOSFileName mode:"w+"
					Seek myFSValue 0
					for MyData in MyDataArray do print MyData to:myFSValue
					try
					(
						flush myFSValue
						close myFSValue
					)
					catch (print "can't close")
				)
				else print "Error"
			)
			catch(print "Error creating file")	
		)
		
		Global Read_File				-- R E A D
		fn Read_File MyPOSFileName =
		(
			MyDataArray = #()
			try
			(
				myReadFSValue = openfile MyPOSFileName
				if myReadFSValue != undefined then
				(
					print ("reading... " + MyPOSFileName)
					while not(eof myReadFSValue) do
					(
						MyData = readvalue myReadFSValue
--						MyData = readline myReadFSValue
--						MyData = readChar myReadFSValue
						append MyDataArray MyData
					)
				)
			)
			Catch(messageBox "Problem reading file";MyDataArray=#())
			return MyDataArray
		)
		-------------------------------------------------------------  F U N C T I O N S  -----------------------	
	)

	on skin_rollout close do
	(
		callBacks.removeScripts #selectionSetChanged
		gc()
 	)

	on btnSaveCameraFOV pressed do
	(
			FOVArray = #()
			MyPOSFileName = MyPath + $cam.name + "FOV" + ".txt"
			for t = spnStart.value to spnEnd.value do at time t
			(
				str = t as string
				str2 = str + "	"  +  $cam[4][1].value as string
--				append FOVArray	$cam[4][1].value
				append FOVArray str2
			)
			

			try
			(
				Write_File MyPOSFileName FOVArray
				print (MyPOSFileName + " saved...")
			)
			catch(print ("Error saving modifier for : " + obj.name + ". Check env dir"))		
	)
	
	on btnSaveModifier pressed do
	(

		clearlistener()
		for obj in selection do
		(
			POSITIONArray = #()
			MyPath = maxfilepath
			MyPOSFileName = MyPath + obj.name + ".txt"
			append POSITIONArray "Adobe After Effects 6.5 Keyframe Data\n"
			append POSITIONArray "	Unit Per Second	25"
			append POSITIONArray "	Source Width	740"
			append POSITIONArray "	Source Height	410"
			append POSITIONArray "	Source Pixel Aspect Ratio	1"
			append POSITIONArray "	Comp Pixel Aspect Ratio	1\n"
			append POSITIONArray "Position"
			append POSITIONArray "	Frame	X pixels	Y pixels	Z pixels"
			for t = spnStart.value to spnEnd.value do at time t
			(
				strFrame = t as string
				strX = obj.center.x as string
				strY = obj.center.y as string
				strZ = obj.center.z as string
				Negative_centerZ = (-1 * obj.center.z) as string
				if chkAfter.checked then
				(
					strZ = Negative_centerZ as string
					str = "	" + strFrame + "	" + strX + "	" + Negative_centerZ + "	" + strY  as string
				)
				else
				(
					
					str = "	" + strFrame + "	" + strX + "	" + strY + "	" + strZ
				)
				append POSITIONArray str
			)
			append POSITIONArray "\n\nEnd of Keyframe Data"
			try
			(
				Write_File MyPOSFileName POSITIONArray
				print (MyPOSFileName + " saved...")
			)
			catch(print ("Error saving modifier for : " + obj.name + ". Check env dir"))
		)
	)
	
)
addRollOut skin_rollout POS_Fltr





It works, I've used it several times. It exports position as well as FOV and flips Y and Z.

But there are some problems :

The first one is that the generated header isn't correct. The solution is to copy a position keyframe in AE and then to paste it on a notepad document. Then replace the header from the text generated by the script with the one copied from AE.

Second problem, we didn't manage to avoid the script to generate quotes, so you'll have to remove them manually.

I've found a soft doing the same thing but between several softs called "nuutti". It exports position too but what i'm looking for now, is to export rotation and direction. If someone is interested in enhancing the script...

Salvazalvi
Post Reply