Python: Read a .txt file for object position
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/12/2012 at 07:05, xxxxxxxx wrote:
Hi
i have this example script COFFEE:
//This script reads the text from a file called "position.txt" on the desktop and converts the string to a float value
//Then uses it to position the currently selected object
// NOTE: Make sure there are no spaces in your text file or you will get an error
var name = doc->GetFilename();
name->SetFullString("C:/Users/user/Desktop");
name->AddLast("values.txt");
var filename = name;
var file = new(BaseFile);
file->Open(filename, GE_READ);
var str = file->ReadString(file->GetLength());
var pos = file->GetPosition(); // Gets total number of characters
var seek = file->Seek(4,false);// Gets the fourth character
var read = file->ReadString( seek+1, GE_XBIT );// reads the fourth and fifth characters
var y = evaluate(read); //Converts string info from the file into a float value
op#ID_BASEOBJECT_REL_POSITION:VECTOR_Y = y;// Set the Y position to this valuehow is possible to convert this scritp in Python?
I Have search in python documentation but to no avail....
Thanks
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/12/2012 at 09:01, xxxxxxxx wrote:
i have find!
import c4d
from c4d import gui
import os
#Welcome to the world of Pythondef main() :
linestring = open('D:/Personal/Desktop/values.txt', 'r+') #File
linestring.seek(0,5) #cursor point
hello = linestring.read(4) #read
# Stampa
print helloif __name__=='__main__':
main()