3DCoatScripting  4.8.31β
You can manage 3DСoat features with help of scripting
🌀 Working with files

You may want to write the results of your work to a file and/or read some data from a file.

3DCoat can do that. Use these commands:

// allows access to the file "a.txt" through variable `a`
// take a note: file will not be created here
File a( "a.txt" );
// returns `true`, if file exists (access via `a` variable)
File a( "a.txt" );
if ( a.exists() ) {
// do something
}
// set a mode that allows input / output
// nor only with text symbols, but also with bytes;
// which allows you read / create your own binary files
File a( "a.data" );
a.binary( true );
// input / output is in text format
a.binary( false );
// returnes if a file is opened in binary mode
bool r = a.binary();
// returns file extension
File a( "a.txt" );
string ext = a.extension();
// returns full path (folder path and file name)
File a( "my/folder/a.txt" );
string fullPath = a.fullPathFile();
// returnes file path (only folder)
File a( "my/folder/a.txt" );
string path = a.path();
// replaces existing file data with our text
File a( "a.txt" );
a = "Line for demo...\n"
"and yet one, yes!";
// adds our text to the existing data
File a( "a.txt" );
a += "Line for demo...\n"
"and yet one, yes!";
// replaces existing file data with our binary data
File a( "a.bin" );
FormatBinary bin = { 0x46, 0x4c, 0x49, 0x46 };
a = bin;
// adds our binary data to the existing file data
File a( "a.bin" );
FormatBinary bin = { 0x46, 0x4c, 0x49, 0x46 };
a += bin;
// deletes file
File a( "a.txt" );
a.remove();

You may also need to open a dialog window for file selection. Here's the list of functions available:

// Show open file dialog. List extensions like in example - *.tga;*.jpg;
// The resulting file name will be placed in result.
// Function returns true if file is successfully chosen.
DEPRECATED bool OpenDialog(string &in extensions,string &out result);
// Show save file dialog. List extensions like in example - *.tga;*.jpg;
// The resulting file name will be placed in result.
// Function returns true if file is successfully chosen.
DEPRECATED bool SaveDialog(string &in extensions,string &out result);
// Show selecting folder dialog. The resulting file name
// will be placed in result.
// Function returns true if file is successfully chosen.
DEPRECATED bool FolderDialog(string &out result);
// Some functions in 3DCoat may engage file dialog that
// will wait user's input.
// You may skip that dialogs and provide file name
// automatically so that file dialog will return specified
// file name without waiting for user's input.
// Use empty name "" to stop automatic file dialogs skipping
// othervice all next file dialogs will be skipped and it may
// lead to loosing data.
DEPRECATED void SetFileForFileDialogs(string &in name);
// Returns true if Cancel pressed in the last file dialog.
DEPRECATED bool FileDialogCancelPressed();

Also if you prefer functional programing you may use these functions for files operations:

// Executes command, pass parameters. You may run executables,
// open webpages, open files in corresponding external editors.
DEPRECATED void Execute(const string& command, const string& parameters);
// 3DCoat script example - How to pass 3DCoat installation folder
// into python script under Linux:
void main() {
string instPath = installPath();
string userFolder = homePath(); // userFolder = "/home/YourUserName"
string pythonInterpreter = "/usr/bin/env python"; // Similar to standard "#!/usr/bin/env python"
string pythonScript = userFolder + "/bin/testLauncher"; // Path to python script
string arg = "-f " + "\"" + instPath + "\"";
string app = pythonInterpreter + " " + pythonScript;
print(app + "\n" + arg + "\n");
Execute(app, arg);
}
// Reads file content into the string.
DEPRECATED string ReadFromFile(const string& filename);
// Writes string content to the file.
// \param append `true` - string will be appended to file,
// `false` - string will be overwrote a file.
DEPRECATED void WriteToFile(const string& filename,const string& text,bool append);
// Checks if file exists.
DEPRECATED bool CheckIfFileExists(const string& filename);
// Removes file from the disk.
DEPRECATED void RemoveFile(const char* filename);
// Removes a path from the `s`.
DEPRECATED string RemoveFilePath(string &in s);
// Removes a file extension from the `s`.
DEPRECATED string RemoveExtension(string &in s);
// Converts `s` to absolute path.
DEPRECATED string EnsureAbsolutePth(string &in s);
// Returns a path from the `s`.
DEPRECATED string GetFilePath(string &in s);
// Returns a file extension from the `s`.
DEPRECATED string GetFileExtension(string &in s);
// Returns a file name from the `s`.
DEPRECATED string GetFileName(string &in s);
// `true` then a file exists by the path `s`.
DEPRECATED bool CheckIfExists(string &in s);
// Creates all folders to the path `s`.
DEPRECATED void CreatePath(string &in s);
// Calls Callback for each file in folder. If Folder is empty
// used will be asked to choose file in folder.
// Callback should be declared as `void Callback(string &in Path)`.
// `ExtList` contains list of extensions like "*.jpg;*.png"
DEPRECATED void ForEachFileInFolder(string &in Folder,string &in ExtList,string &in Callback);
// Returns a path where the 3DCoat was installed.
string installPath();
// Get an absolute path including write folder of the 3DCoat.
string rwPath( const string& userPath );
// Returns a path to home directory "~" (for example "/home/YourUserName").
string homePath();