About
Filename is a special class to handle filenames and paths. It is used to easily construct and edit paths, filenames and suffixes. It also allows to open dialogs to select files and directories.
- Warning
- To handle files with the Maxon API see also Url Manual.
- Note
- To convert a Filname to a maxon::Url use MaxonConvert().
Access
Filename objects can be created on demand or can be obtained from other entities.
To retrieve and modify Filename objects stored in a BaseContainer respectively use:
- BaseContainer::GetFilename(): Returns the Filename stored at the given ID.
- BaseContainer::SetFilename(): Sets the Filename stored at the given ID.
See also BaseContainer Manual.
To retrieve and modify Filename objects stored in a GeData object (GeData type is ::DA_FILENAME) respectively use:
- GeData::GetFilename(): Returns the Filename object.
- GeData::SetFilename(): Stores the Filename object.
See also GeData Manual.
Important paths are obtained from:
BaseObject*
const object =
doc->GetActiveObject();
GeData data;
@ ALEMBIC_PATH
Definition: Oalembicgenerator.h:6
NONE
Definition: asset_browser.h:1
#define Oalembicgenerator
Alembic generator.
Definition: ge_prepass.h:1165
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
#define ConstDescID(...)
Definition: lib_description.h:592
const char * doc
Definition: pyerrors.h:226
Combine
A Filename can be constructed with basic operators:
- Note
- Only the last part (typically the file) of the given Filename is added.
Filename selectFolder;
const Filename fullFilePath = selectFolder + "cube.c4d";
else
DIRECTORY
Folder selection dialog.
Definition: ge_prepass.h:2
ANYTHING
Any file.
Definition: ge_prepass.h:0
return OK
Definition: apibase.h:2740
Bool GeFExist(const Filename &name, Bool isdir=false)
const Filename imageFile =
GeGetPluginPath() + Filename(
"res") + Filename(
"arbitrary_icon.tif");
AutoAlloc<BaseBitmap> bitmap;
if (bitmap == nullptr)
OK
User has selected a font.
Definition: customgui_fontchooser.h:0
const Filename GeGetPluginPath()
Bool ShowBitmap(const Filename &fn)
Copy
A Filename object can easily be copied:
- Filename::operator=(): Assigns the right-operand filename to the left-operand filename.
- Filename::CopyTo(): Copies the filename into the given Filename object.
Properties
String
The content of a Filename object can be represented by a String:
- Filename::IsPopulated(): Returns true if the filename has been set.
- Filename::GetString(): Returns the full filename as a String.
- Filename::SetString(): Sets the filename with the given String.
See also String Manual (Cinema API).
const String filenameString = selectedFile.GetString();
File and Directory
A filename may be composed of a directory part and a file part. Each part can be edited independently:
- Filename::GetDirectory(): Returns the directory of the filename.
- Filename::SetDirectory(): Sets the directory of the filename.
- Filename::GetFile(): Returns the file part of the filename.
- Filename::SetFile(): Sets the file part of the filename.
- Filename::GetFileString(): Returns the file part of the filename as a String.
const String
file = selectedFile.GetFileString();
const String directory = selectedFile.GetDirectory().GetString();
const char const char const char * file
Definition: object.h:439
Suffix
Part of the filename may also be the file suffix. This suffix can be edited separately:
- Filename::GetSuffix(): Returns the suffix as a String.
- Filename::SetSuffix(): Sets the suffix to the given string.
- Filename::ClearSuffix(): Clears the suffix.
- Filename::ClearSuffixComplete(): Clears also suffixes longer than seven characters.
- Filename::CheckSuffix(): Checks if the suffix is equal to the given string.
if (selectedFile.CheckSuffix("c4d"_s))
else
It is possible to get the suffix for a given image file type:
#define FILTER_JPG
JPEG.
Definition: ge_prepass.h:189
Filename GeFilterSetSuffix(const Filename &name, Int32 id)
Memory Mode
The memory mode allows to perform read and write operations on a memory block instead of a file on the hard drive. This is typically used to encrypt or compress the resulting data.
- Filename::SetMemoryReadMode(): Sets the filename to read from a memory block.
- Filename::SetMemoryWriteMode(): Sets the filename to write to a memory block.
AutoAlloc<MemoryFileStruct> mfs;
if (mfs == nullptr)
Filename fn;
fn.SetMemoryWriteMode(mfs);
void* data = nullptr;
hyperFile->WriteInt32(123);
hyperFile->WriteString("foo"_s);
hyperFile->WriteString("bar"_s);
hyperFile->WriteInt32(456);
hyperFile->Close();
mfs->GetData(data,
size,
false);
Py_ssize_t size
Definition: bytesobject.h:86
WRITE
Problems writing the file.
Definition: ge_prepass.h:4
maxon::Int Int
Definition: ge_sys_math.h:55
- Note
- The data stored in memory may be written to a file using HyperFile::WriteMemory().
Functionality
Select Files and Folders
A Filename object is also useful to open dialogs to select files and folders:
- Filename::FileSelect(): Opens a dialog to select a file or a folder.
- Filename::FileSelectMultiple(): Opens a dialog to select multiple files or folders.
The files that can be selected in a dialog can be filtered with these flags:
The type of dialog is defined with this flag:
Filename loadFile;
Filename saveFile;
Filename folder;
LOAD
Load.
Definition: c4d_filterdata.h:1
SAVE
::Bool Get/Set. Determines if the layer is saved with the image or not if SAVEBIT::USESELECTEDLAYERS ...
Definition: ge_prepass.h:1
maxon::Id callerId(
"net.mycompany.myplugin.fileselectdialog");
Bool res = Filename::FileSelectMultiple(
{
{
}
}
Definition: basearray.h:415
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Appends a new element at the end of the array and constructs it using the forwarded value.
Definition: basearray.h:627
Definition: apibaseid.h:243
Definition: string.h:1287
Py_UCS4 * res
Definition: unicodeobject.h:1113
maxon::Bool Bool
Definition: ge_sys_math.h:46
#define iferr_scope
Definition: resultbase.h:1396
#define iferr_return
Definition: resultbase.h:1531
Preset Browser
A Filename object may also be used to reference a file located in Cinema 4D's content browser.
- Filename::IsBrowserUrl(): Returns true if the Filename contains a content browser url.
GeData geData;
{
const Filename
filename = geData.GetFilename();
}
PyCompilerFlags const char * filename
Definition: ast.h:15
Compare
Two Filename objects can be compared easily:
Filename folder;
{
if (folder == desktop)
else
}
#define C4D_PATH_DESKTOP
OS desktop directory.
Definition: c4d_file.h:1921
const Filename GeGetC4DPath(Int32 whichpath)
Disc I/O
A Filename object can be stored in a BaseFile or a HyperFile using:
- BaseFile::ReadFilename(): Reads the Filename from the BaseFile.
- BaseFile::WriteFilename(): Writes the Filename to the BaseFile.
AutoAlloc<BaseFile> bf;
if (bf == nullptr)
bf->WriteFilename(filenameData);
bf->Close();
ANY
Definition: lib_substance.h:28
AutoAlloc<BaseFile> bf;
if (bf == nullptr)
Filename filenameData;
bf->ReadFilename(&filenameData);
bf->Close();
READ
Problems reading the file.
Definition: ge_prepass.h:3
- HyperFile::ReadFilename(): Reads the Filename from the HyperFile.
- HyperFile::WriteFilename(): Writes the Filename to the HyperFile.
AutoAlloc<HyperFile> hf;
if (hf == nullptr)
hf->WriteFilename(filenameData);
hf->Close();
AutoAlloc<HyperFile> hf;
if (hf == nullptr)
Filename filenameData;
hf->ReadFilename(&filenameData);
Further Reading