3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
coat::io Class Reference

General I/O access. More...

#include <CoreAPI.h>

Static Public Member Functions

static const char * installPath ()
 the 3DCoat installation path
 
static const char * dataPath ()
 the 3DCoat data path
 
static const char * documents (const char *path)
 convert the relative path to the path in documents, if the path is absolute, just return the original path
 
static bool fileExists (const char *path)
 check if file exists
 
static void copyFile (const char *src, const char *dest)
 copy the file from src to dest. If the src or dest is relative, it is relative to the documents folder. This function works correctly with relative paths, so it is recommended over the standard copy files routine.
 
static void copyFolder (const char *src, const char *dest)
 copy the whole folder from src to dest. If the src or dest is relative, it is relative to the documents folder. This function works correctly with relative paths, so it is recommended over the standard copy folder routine.
 
static void removeFile (const char *filename)
 remove the file. If the filename is relative, it is relative to the documents folder. If the path is in install folder, the corresponding file in documents will be removed. Files in the install folder can't be removed.
 
static void removeFolder (const char *folder)
 remove the folder. If the folder is relative, it is relative to the documents folder. If the path is in install folder, the corresponding folder in documents will be removed.
 
static std::string toFullPathInDataFolder (const char *path)
 convert the relative path to full path in documents folder. If the path is full and placed in the install folder, it will be converted to path in documents.
 
static void toFullPathInDataFolder (str *path)
 
static std::string toFullPathInInstallFolder (const char *path)
 convert the relative path to the full path in the install folder. If the path is full, it remains untouched.
 
static void toFullPathInInstallFolder (str *path)
 
static std::string convertToWritablePath (const char *path)
 If the path is relative or points into some file in the install folder, it will be converted to the path in documents folder.
 
static void convertToWritablePath (str *path)
 
static std::string convertToWritablePathIfFileExists (const char *path)
 If the path is relative or points into some file in the install folder, it will be converted to the path in documents folder. If the does not exist in the documents folder, but exists in the install folder, the resulting path will be in the install folder.
 
static void convertToWritablePathIfFileExists (str *path)
 
static std::string getExtension (const char *filepath)
 get the file extension (without .)
 
static std::string getFileName (const char *filepath)
 get the file name from the path
 
static std::string getFilePath (const char *filepath)
 get the file path without the filename
 
static std::string getFileNameWithoutExtension (const char *filepath)
 remove the file extension from the filename
 
static std::string strFromFile (const char *filename)
 read string from file.
 
static void strToFile (const char *text, const char *filename)
 write the string to file
 
static size_t getFileSize (const char *filename)
 get the file size
 
static vec2 cursorPos ()
 returns the current cursor position
 
static vec2 snappedCursorPos ()
 returns the snapped cursor position
 
static rect wholeScreen ()
 get the whole screen rectangle
 
static rect workArea ()
 get the work area rectangle
 
static void progressBar (float stage, float max_stage, const char *message)
 Show the progress bar.
 
static void progressBarInWindowHeader (float stage, float max_stage, const char *message)
 Show the progress bar only in the 3DCoat's window header.
 
static void setWindowTitle (const char *text, float seconds)
 Override the 3DCoat's window title for some amount of time.
 
static void step (int count=1)
 perform rendering cycles
 
static void exec (const char *command, const char *arguments=nullptr)
 execute command. It may be exe file, URL, batch command
 
static const char * execAndWait (const char *command, const char *arguments=nullptr)
 execute and wait till finished, the console output will be returned as string
 
static void updateCoatPyi (const char *folderOrFile)
 update the .pyi file for the given folder or py file
 
static void ListFiles (const char *folder, const char *mask, coat::list< coat::str > &result, bool recursive=true)
 list files in the folder
 
static std::vector< std::string > ListFiles (const char *folder, const char *mask, bool recursive=true)
 list files in the folder
 
static void ListFolders (const char *startFolder, coat::list< coat::str > &result)
 list folders within the folder, non-recursive, just plain list
 
static std::vector< std::string > ListFolders (const char *startFolder)
 list folders within the folder, non-recursive, just plain list
 
static const char * supportedImagesFormats ()
 returns the currently supported mesh export formats
 
static const char * supportedMeshesFormats ()
 returns the list of supported images formats
 
static bool openFileDialog (const char *extensions, str &fileName)
 show the file dialog
 
static std::string openFileDialog (const char *extensions)
 
static bool openFilesDialog (const char *extensions, list< str > &fileNames)
 open multiple files dialog
 
static std::vector< std::string > openFilesDialog (const char *extensions)
 open multiple files dialog
 
static bool saveFileDialog (const char *extensions, str &fileName)
 show the save file dialog
 
static std::string saveFileDialog (const char *extensions)
 
static const char * currentSceneFilepath ()
 returns the current scene filename, empty if the scene was not saved/opened
 
static void pipInstall (const char *requirements)
 install one or multiple python packages
 
static void pipUninstall (const char *requirements)
 
static std::string pythonPath ()
 get the python libraries folder
 
static void showPythonConsole ()
 Show the python console, clear it and pop up.
 
static void executeScript (const char *path)
 execute python (.py file) or angelscript (c++ like), or CoreAPI (native C++) script
 
static void installRequirements (const char *path_to_requirements_txt)
 Install all the requirements for the python script execution.
 
static std::string toJson (const pybind11::object &obj, const char *filename="")
 Store the object to the file or string as json.
 
static void fromJsonFile (pybind11::object &obj, const char *filename)
 Restore the object from the json file.
 
static void restoreObjectFormJsonString (pybind11::object &obj, const char *data)
 Restore the object from the json string.
 
static void createRedistributablePackageFromFolder (const char *folder, const char *package_name, const char *excluded_folders_names="", const char *excluded_extensions="")
 Create the 3dcpack file from the folder placed in Documents.
 
static void download (const char *url, std::function< void(const char *, const char *)> report_success)
 download the file from the url
 
static int getDownloadProgress ()
 returns the overall download progress
 
static void post_request (const char *url, const char *data, const char *headers, const std::function< void(const char *)> &report_success=nullptr, const std::function< void(const char *)> &report_error=nullptr)
 send the post request to the url
 
static void get_request (const char *url, const char *headers, const std::function< void(const char *)> &report_success=nullptr, const std::function< void(const char *)> &report_error=nullptr)
 send the get request to the url
 
static std::vector< std::string > listBlenderInstallFolders ()
 list the blender install folders
 
static void saveScreenshot (const char *filename, int x=0, int y=0, int width=0, int height=0)
 save the screenshot to the file
 
static void removeBackground (const char *image1, const char *image2, const char *result)
 

Detailed Description

General I/O access.

Member Function Documentation

◆ convertToWritablePath()

static std::string coat::io::convertToWritablePath ( const char * path)
static

If the path is relative or points into some file in the install folder, it will be converted to the path in documents folder.

Parameters
paththe path (full or relative)
Returns
the write-able path

◆ convertToWritablePathIfFileExists()

static std::string coat::io::convertToWritablePathIfFileExists ( const char * path)
static

If the path is relative or points into some file in the install folder, it will be converted to the path in documents folder. If the does not exist in the documents folder, but exists in the install folder, the resulting path will be in the install folder.

Parameters
paththe path (full or relative)
Returns
the path

◆ copyFile()

static void coat::io::copyFile ( const char * src,
const char * dest )
static

copy the file from src to dest. If the src or dest is relative, it is relative to the documents folder. This function works correctly with relative paths, so it is recommended over the standard copy files routine.

Parameters
srcthe source filename
destthe destination filename
Examples
TreesGenerator.cpp.

◆ copyFolder()

static void coat::io::copyFolder ( const char * src,
const char * dest )
static

copy the whole folder from src to dest. If the src or dest is relative, it is relative to the documents folder. This function works correctly with relative paths, so it is recommended over the standard copy folder routine.

Parameters
srcthe source folder
destthe destination folder

◆ createRedistributablePackageFromFolder()

static void coat::io::createRedistributablePackageFromFolder ( const char * folder,
const char * package_name,
const char * excluded_folders_names = "",
const char * excluded_extensions = "" )
static

Create the 3dcpack file from the folder placed in Documents.

Parameters
folderthe folder to pack, it should be relative to the 3DCoat's Documents folder
package_namethe package name, the extension is .3dcpack
excluded_folders_namesthe folders names to be excluded from the package, separated by semicolon
excluded_extensionsthe file extensions to be excluded from the package, separated by semicolon

◆ cursorPos()

static vec2 coat::io::cursorPos ( )
static

returns the current cursor position

Returns
the 2d vector

◆ dataPath()

static const char * coat::io::dataPath ( )
static

the 3DCoat data path

Returns
the path
Examples
Strings.cpp.

◆ documents()

static const char * coat::io::documents ( const char * path)
static

convert the relative path to the path in documents, if the path is absolute, just return the original path

Parameters
paththe relative or absolute path
Returns
the absolute path in user documents

◆ download()

static void coat::io::download ( const char * url,
std::function< void(const char *, const char *)> report_success )
static

download the file from the url

Parameters
urlthe url
report_successthe callback that gives you the source URL and the filename of the downloaded file

◆ exec()

static void coat::io::exec ( const char * command,
const char * arguments = nullptr )
static

execute command. It may be exe file, URL, batch command

Parameters
commandthe command to execute
argumentsoptional command line arguments

◆ execAndWait()

static const char * coat::io::execAndWait ( const char * command,
const char * arguments = nullptr )
static

execute and wait till finished, the console output will be returned as string

Parameters
commandthe command to execute
argumentsoptional arguments
Returns
the console output of the executed program

◆ executeScript()

static void coat::io::executeScript ( const char * path)
static

execute python (.py file) or angelscript (c++ like), or CoreAPI (native C++) script

Parameters
paththe full or relative path to the script file

◆ fileExists()

static bool coat::io::fileExists ( const char * path)
static

check if file exists

Parameters
paththe path may be full or relative. If it is relative, the documents will be checked first, the the install folder will be checked for file.
Returns
true if the file exists

◆ fromJsonFile()

static void coat::io::fromJsonFile ( pybind11::object & obj,
const char * filename )
static

Restore the object from the json file.

Parameters
objthe object to restore
filenamethe path to the json file, full or relative

◆ get_request()

static void coat::io::get_request ( const char * url,
const char * headers,
const std::function< void(const char *)> & report_success = nullptr,
const std::function< void(const char *)> & report_error = nullptr )
static

send the get request to the url

Parameters
urlthe url
headersthe headers of the request, separated by
report_successthe callback that gives you the response if the request was successful
report_errorthe callback that gives you the response if the request was failed

◆ getDownloadProgress()

static int coat::io::getDownloadProgress ( )
static

returns the overall download progress

Returns
the progress in percents

◆ getExtension()

static std::string coat::io::getExtension ( const char * filepath)
static

get the file extension (without .)

Parameters
filepaththe file path - full or relative
Returns
the extension

◆ getFileName()

static std::string coat::io::getFileName ( const char * filepath)
static

get the file name from the path

Parameters
filepaththe full or relative path
Returns
the filename without the path

◆ getFileNameWithoutExtension()

static std::string coat::io::getFileNameWithoutExtension ( const char * filepath)
static

remove the file extension from the filename

Parameters
filepaththe file name
Returns
the filename without extension

◆ getFilePath()

static std::string coat::io::getFilePath ( const char * filepath)
static

get the file path without the filename

Parameters
filepaththe filepath
Returns
the path that always ends with '/'

◆ getFileSize()

static size_t coat::io::getFileSize ( const char * filename)
static

get the file size

Parameters
filenamethe filename, relative or full
Returns
the file size

◆ installPath()

static const char * coat::io::installPath ( )
static

the 3DCoat installation path

Returns
the path

◆ installRequirements()

static void coat::io::installRequirements ( const char * path_to_requirements_txt)
static

Install all the requirements for the python script execution.

Parameters
path_to_requirements_txtte full or relative path to the requirements.txt

◆ listBlenderInstallFolders()

static std::vector< std::string > coat::io::listBlenderInstallFolders ( )
static

list the blender install folders

Returns
the list of the blender install folders

◆ ListFiles() [1/2]

static std::vector< std::string > coat::io::ListFiles ( const char * folder,
const char * mask,
bool recursive = true )
static

list files in the folder

Parameters
folderthe start folder. It may be absolute or relative to 3DCoat documents/install folder.
maskthe seek mask (wildcards)
recursiveset true if recursive
Returns
result the files list

◆ ListFiles() [2/2]

static void coat::io::ListFiles ( const char * folder,
const char * mask,
coat::list< coat::str > & result,
bool recursive = true )
static

list files in the folder

Parameters
folderthe start folder. It may be absolute or relative to 3DCoat documents/install folder.
maskthe seek mask (wildcards)
resultthe files list
recursiveset true if recursive

◆ ListFolders() [1/2]

static std::vector< std::string > coat::io::ListFolders ( const char * startFolder)
static

list folders within the folder, non-recursive, just plain list

Parameters
startFolderthe start folder
Returns
the resulting list

◆ ListFolders() [2/2]

static void coat::io::ListFolders ( const char * startFolder,
coat::list< coat::str > & result )
static

list folders within the folder, non-recursive, just plain list

Parameters
startFolderthe start folder
resultthe resulting list

◆ openFileDialog()

static bool coat::io::openFileDialog ( const char * extensions,
str & fileName )
static

show the file dialog

Parameters
extensionsthe list of supported extensions like *.txt;*.dat; etc...
fileNamethe resulting filename
Returns
true if user chosen the file successfully

◆ openFilesDialog() [1/2]

static std::vector< std::string > coat::io::openFilesDialog ( const char * extensions)
static

open multiple files dialog

Parameters
extensionsthe list of supported extensions like *.txt;*.dat; etc...
Returns
the resulting filenames list

◆ openFilesDialog() [2/2]

static bool coat::io::openFilesDialog ( const char * extensions,
list< str > & fileNames )
static

open multiple files dialog

Parameters
extensionsthe list of supported extensions like *.txt;*.dat; etc...
fileNamesthe resulting filename
Returns
true if user chosen the file successfully

◆ pipInstall()

static void coat::io::pipInstall ( const char * requirements)
static

install one or multiple python packages

Parameters
requirementsthe list of packages to install, this is all what you write after "pip install"

◆ post_request()

static void coat::io::post_request ( const char * url,
const char * data,
const char * headers,
const std::function< void(const char *)> & report_success = nullptr,
const std::function< void(const char *)> & report_error = nullptr )
static

send the post request to the url

Parameters
urlthe url
datathe body of the request
headersthe headers of the request, separated by
report_successthe callback that gives you the response if the request was successful
report_errorthe callback that gives you the response if the request was failed

◆ progressBar()

static void coat::io::progressBar ( float stage,
float max_stage,
const char * message )
static

Show the progress bar.

Parameters
stagethe current stage
max_stagethe maximal stage
messagethe text to display

◆ progressBarInWindowHeader()

static void coat::io::progressBarInWindowHeader ( float stage,
float max_stage,
const char * message )
static

Show the progress bar only in the 3DCoat's window header.

Parameters
stagethe current stage
max_stagethe maximal stage
messagethe text to display
Examples
meshes.cpp.

◆ pythonPath()

static std::string coat::io::pythonPath ( )
static

get the python libraries folder

Returns
the path

◆ removeFile()

static void coat::io::removeFile ( const char * filename)
static

remove the file. If the filename is relative, it is relative to the documents folder. If the path is in install folder, the corresponding file in documents will be removed. Files in the install folder can't be removed.

Parameters
filenamethe file path

◆ removeFolder()

static void coat::io::removeFolder ( const char * folder)
static

remove the folder. If the folder is relative, it is relative to the documents folder. If the path is in install folder, the corresponding folder in documents will be removed.

Parameters
folderthe path to the folder

◆ restoreObjectFormJsonString()

static void coat::io::restoreObjectFormJsonString ( pybind11::object & obj,
const char * data )
static

Restore the object from the json string.

Parameters
objthe object to restore
datathe json string

◆ saveFileDialog()

static bool coat::io::saveFileDialog ( const char * extensions,
str & fileName )
static

show the save file dialog

Parameters
extensionsextensions the list of supported extensions like *.txt;*.dat; etc...
fileNamethe resulting filename
Returns
true if user chosen the file successfully

◆ saveScreenshot()

static void coat::io::saveScreenshot ( const char * filename,
int x = 0,
int y = 0,
int width = 0,
int height = 0 )
static

save the screenshot to the file

Parameters
filenamethe filename
xthe x coordinate of the screenshot
ythe y coordinate of the screenshot
widththe width of the screenshot, if 0 all to the right will be captured
heightthe height of the screenshot, if 0 all to the bottom will be captured

◆ setWindowTitle()

static void coat::io::setWindowTitle ( const char * text,
float seconds )
static

Override the 3DCoat's window title for some amount of time.

Parameters
textthe text to show
secondsthe seconds to stay in title

◆ snappedCursorPos()

static vec2 coat::io::snappedCursorPos ( )
static

returns the snapped cursor position

Returns
the 2d vector

◆ step()

static void coat::io::step ( int count = 1)
static

perform rendering cycles

Parameters
countamount of cycles
Examples
meshes.cpp.

◆ strFromFile()

static std::string coat::io::strFromFile ( const char * filename)
static

read string from file.

Parameters
filenameThe path. If it is relative, it is relative to the documents folder. If there is no file, it will be taken from the install folder.
Returns
true if file read succesful

◆ strToFile()

static void coat::io::strToFile ( const char * text,
const char * filename )
static

write the string to file

Parameters
textthe text to save
filenameThe path. If it is relative, it is relative to the documents folder.

◆ supportedImagesFormats()

static const char * coat::io::supportedImagesFormats ( )
static

returns the currently supported mesh export formats

Returns
the list like "*.obj;*.fbx;..."

◆ supportedMeshesFormats()

static const char * coat::io::supportedMeshesFormats ( )
static

returns the list of supported images formats

Returns
the list like "*.png;*.jpg;..."

◆ toFullPathInDataFolder()

static std::string coat::io::toFullPathInDataFolder ( const char * path)
static

convert the relative path to full path in documents folder. If the path is full and placed in the install folder, it will be converted to path in documents.

Parameters
paththe path
Returns
the fill path in documents

◆ toFullPathInInstallFolder()

static std::string coat::io::toFullPathInInstallFolder ( const char * path)
static

convert the relative path to the full path in the install folder. If the path is full, it remains untouched.

Parameters
paththe relative path
Returns
the full path in the install folder

◆ toJson()

static std::string coat::io::toJson ( const pybind11::object & obj,
const char * filename = "" )
static

Store the object to the file or string as json.

Parameters
objthe python object reference
filenamethe filename to save, if empty, the string will be returned
Returns
the string that contains json data

◆ updateCoatPyi()

static void coat::io::updateCoatPyi ( const char * folderOrFile)
static

update the .pyi file for the given folder or py file

Parameters
folderOrFilethe full or relative path to the folder or py file

◆ wholeScreen()

static rect coat::io::wholeScreen ( )
static

get the whole screen rectangle

Returns
the rectangle, top-left is (0,0)

◆ workArea()

static rect coat::io::workArea ( )
static

get the work area rectangle

Returns
the rectangle, top-left is (0,0)

The documentation for this class was generated from the following file: