Scripting: Importing plain text file or CSV

lucky101manlucky101man Posts: 0

Preamble:
Hello DAZ Community!
I just started using DAZ Studio about a week ago. Last night I started looking at the scripting IDE and discovered to my delight that it's based on the same spec as Adobe Extendscript, which I have some experience using for After Effects. My main focus is using scripting as a means of content creation, importing key frames etc. I would like to do the same in DAZ. It looks like it should be possible, but I'm not exactly sure about the ImportMgr as it seems there is a different importer class for different acceptable file types. For example CBvhIn for .bvh, DzCOLLADAImporter for dae files etc. The list of importer types from "Importer_Settings.dsa" on
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start
there's no plain text import as a class.

My Question:
Can I import (or parse) a pain text file or CSV, read it line by line and take these values and apply them to things like, X translate on a camera at frame 50 (or whatever).

This is how I would do it in extend script, but the 'File' Class doesn't exist in DAZ.
var aTextFile = File.openDialog ( 'Select a text file to import:', '*.*', false ) ;
Then I would read out of aTextFile as an array.

Looking at "Silent_OBJ_Importer.dsa" it appears FileDialog.doFileDialog() is what I need to use but it seems this takes arguments to describe the importer type and settings for import. So what importer type and settings would I use to import plain text or CSV?

Work Around:
The reason I want a plain text or CSV file is that I like plain text as a format. I hope to use PDE to generate text files for whatever I need and then run a script in DAZ Script IDE to import keyframes to the desired object.
Alternatively, I can imagine using BVH files to import 'well formatted' instructions to the timeline of a Genesis (as bvh files seem to need a skeleton - fair enough) and then use the script to transfer the keyframes from genesis to eg. a camera. I can Imagine this would work, but it would be nice to avoid doing something like that.

Thanks for reading, looking forward to response.

Comments

  • Richard HaseltineRichard Haseltine Posts: 97,315
    edited December 1969

    Yes, you can do that with DzFile{

    file = new DzFile( fileName );
    if ( file.open( file.ReadOnly ) ) {
         while ( ! file.eof() ) {
              lineOfFile = file.readLine();
              // Do stuff
         }
         file.close();
    }
  • lucky101manlucky101man Posts: 0
    edited March 2014

    Excellent. Thank you!

    This works great. Prompts for an 'all files' type and prints each line of the selected file to the console.

    {
    var sPath = FileDialog.doFileDialog(true);
    print(sPath);

    file = new DzFile( sPath );
    if ( file.open( file.ReadOnly ) ) {
    while ( ! file.eof() ) {
    lineOfFile = file.readLine();
    print(lineOfFile);
    }
    file.close();
    }
    }

    Post edited by lucky101man on
Sign In or Register to comment.