Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Python: Read a .txt file for object position

    General Discussion
    0
    2
    417
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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 value

      how is possible to convert this scritp in Python?

      I Have search in python documentation but to no avail....

      Thanks 🙂

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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 Python

        def main() :

        linestring = open('D:/Personal/Desktop/values.txt', 'r+') #File
            
            linestring.seek(0,5)  #cursor point
           
            hello = linestring.read(4) #read 
            
            # Stampa
            print hello

        if __name__=='__main__':
            main()

        1 Reply Last reply Reply Quote 0
        • First post
          Last post