Importing data using Python


#1

I have a small ms used for taking position data to create an fbx animation. I would like it streamlined and converted to a python script. Can anyone help? Script :

AllFaceMarkers = #();
MkPos = #()
MkNms = #()
MkRots = #()
Scales =#()
XRot
YRot
ZRot
mkdum = 3
fn RotatePivotOnly obj rotation= (
local rotValInv=inverse (rotation as quat)
animate off
in coordsys
local obj.rotation = RotValInv
obj.objectoffsetpos
=RotValInv
obj.objectoffsetrot*=RotValInv
);

struct FaceMarker (MkNm, MkPos);

	fileName = getopenfileName caption:"After Effects Data:" \
		types:"|*.txt|All          *.*|*.*|"
	
	if fileName != undefined do
	(
		openedFile = openFile fileName mode:"r"
	
			local str = (readLine openedFile);
			str2 = (filterstring str " ")[1];
			if ((filterstring str " ")[1] != "End" )  do (
			if str == "Rig Vadar Facial Peformance Analysis" then
			(
				readLine openedFile;
				readLine openedFile;
				readLine openedFile;
				readLine openedFile;
				readLine openedFile;

				local header = (readLine openedFile);
					local LineHead = filterstring header "	"
												
			 readLine openedFile;
		local header = readLine openedFile;
				local LineHead = filterstring header "	";
	
					while (header!= "Rotation Data")do(
						if LineHead[1] == "Effects"  then (
							readLine openedFile;
							s2 = substitutestring header "	" ""
							s3 =substitutestring s2 " " ""
							s4 = substring s3 25 s3.count;
						    s5 = (filterstring s4 "#")[1];
						
						append MkNms s5
							MkPos = #()
						
							);
						if LineHead[1] != "Effects" and  header!= "Rotation Data" and LineHead[1] != "Frame"  then (
				
							if LineHead[2] != undefined then (
							
								append MkPos [LineHead[2] as float ,LineHead[3] as float,0];
							
				
							)  
							)
			local header = readLine openedFile;
                 

					local LineHead = filterstring header "	 "
						
							if LineHead[1] == "Effects" and MkNms.count != 0 then (
								
	appendifunique AllFaceMarkers (FaceMarker MkNm:MkNms[MkNms.count] MkPos:MkPos)
							);
						)		
								
							
				appendifunique AllFaceMarkers (FaceMarker MkNm:MkNms[MkNms.count] MkPos:MkPos)
						readLine openedFile;
				while (header!= "Scale Data")do(	
							local header = readLine openedFile;
				local LineHead = filterstring header "	";
					
				local LineHead = filterstring header "	";
				if LineHead[2] != undefined and LineHead[1] != "Scale" then (
							
							append MkRots [LineHead[2] as float ,LineHead[3] as float,LineHead[4] as float];
						
			
							)
							
				)		
				 readLine openedFile;
                	while (header!= "Mask Position Data")do(	
							local header = readLine openedFile;
				local LineHead = filterstring header "	";
					local LineHead = filterstring header "	";
					if LineHead[2] != undefined and LineHead[1] != "Scale" then (
							
								append Scales [LineHead[2] as float ,LineHead[2] as float,LineHead[2] as float];
						
			
							)
				)	

			
		
	rootDum = dummy boxsize:[mkdum*3,mkdum*3,mkdum*3] centermarker:false axistripod:false cross:false box:true 
rootDum.name = getFilenameFile filename
RotatePivotOnly rootdum (EulerAngles 180 0 0);
for i = 1 to AllFaceMarkers.count do (
	
  faceMarker =dummy boxsize:[mkdum,mkdum,mkdum] centermarker:false axistripod:false cross:false box:true wireColor:[200,200,0];
	
	faceMarker.name = AllFaceMarkers[i].MkNm;
	faceMarker.pos = AllFaceMarkers[i].MkPos[1]
	faceMarker.Parent = rootDum
	rootDum.pos = AllFaceMarkers[AllFaceMarkers.count].MkPos[1]
);

HeadRot =dummy boxsize:[mkdum2,mkdum2,mkdum*2] centermarker:false axistripod:false cross:false box:true wireColor:[200,200,0];
RotatePivotOnly HeadRot (EulerAngles 180 0 0);
HeadRot.name = “Head Rot_” + getFilenameFile filename
HeadRot.pos = rootDum.pos
HeadRot.Parent = rootDum
HeadRotRoot = copy HeadRot
hide HeadRotRoot
animationRange=interval 0 (AllFaceMarkers[1].MkPos.count + slidertime)
set animate on;
theObj = dotNetObject “MaxCustomControls.ProgressDialog”
theObj.Show()
theObj.text = “Importing Rig Vadar Facial MoCap Data”
theObj.Controls.Item[0].text = “STOP!”
theObj.Controls.Item[1].text = “Importing…”
sldrtm = slidertime
for j = 1 to AllFaceMarkers.count do (
slidertime = sldrtm
mk = getnodebyname AllFaceMarkers[j].MkNm
s2 = AllFaceMarkers[j].MkNm

	mk.name = s2
for i = 1 to AllFaceMarkers[j].MkPos.count do (
	
mk.pos= AllFaceMarkers[j].MkPos[i]  ;

	
	slidertime = slidertime + 1
		
	)
	
	
	theObj.Controls.Item[2].value =  100 *j/ AllFaceMarkers.count
);

slidertime = sldrtm

	for k = 1 to MkRots.count do (
		XRot = radtodeg MkRots[k][1]*100/Scales[k][1];
	Yrot = radtodeg MkRots[k][2]*100/Scales[k][1];	
	Zrot = radtodeg MkRots[k][3]*100/Scales[k][1];	
	rotate HeadRot  (Eulerangles XRot YRot ZRot);
		
	rootDum.scale = 100/Scales[k]
		
  --rotate HeadRot (angleaxis  XRot [1,0,0]);
  -- rotate HeadRot (angleaxis  YRot [0,1,0]);
   --   rotate HeadRot (angleaxis  ZRot [0,0,1]);
	slidertime = slidertime + 1
HeadRot.transform = HeadRotRoot.transform

		
	);

	

	slidertime = sldrtm

set animate off

slidertime = sldrtm
rotate rootDum (angleaxis -90 [1,0,0])
scale rootDum [.05,.05,.05];
rootdum.pos = [0,0,0];

theObj.Close();

for i = 1 to AllFaceMarkers.count do (
mk = getnodebyname AllFaceMarkers[i].MkNm
RotatePivotOnly mk (EulerAngles 180 0 0)
mk.parent = undefined
);
select rootdum

for i = 1 to AllFaceMarkers.count do (
mk = getnodebyname AllFaceMarkers[i].MkNm

mk.parent = rootdum
	);				
	rootDum.pos  =[0,0,0]	
	close openedFile

	) else (messagebox"Not a valid tracking  data file";close openedFile)

		)
	
	)