appdata
Utility functions for creating data files within pyRevit environment.
Most times, scripts need to save some data to share between different scripts that work on a similar topic or between script executions. This module provides the necessary and consistent mechanism for creating and maintaining such files.
Examples:
Attributes
mlogger = logger.get_logger(__name__)
module-attribute
TEMP_FILE_EXT = 'tmp'
module-attribute
Functions
get_universal_data_file(file_id, file_ext, name_only=False)
Get path to file that is shared between all host versions.
These data files are not cleaned up at Revit restart. e.g pyrevit_pyrevitlabs_file_id.file_ext
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_id |
str
|
Unique identifier for the file |
required |
file_ext |
str
|
File extension |
required |
name_only |
bool
|
If true, function returns file name only |
False
|
Returns:
Type | Description |
---|---|
str
|
File name or full file path (depending on name_only) |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
get_data_file(file_id, file_ext, name_only=False)
Get path to file that will not be cleaned up at Revit load.
e.g pyrevit_2016_pyrevitlabs_file_id.file_ext
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_id |
str
|
Unique identifier for the file |
required |
file_ext |
str
|
File extension |
required |
name_only |
bool
|
If true, function returns file name only |
False
|
Returns:
Type | Description |
---|---|
str
|
File name or full file path (depending on name_only) |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
get_instance_data_file(file_id, file_ext=TEMP_FILE_EXT, name_only=False)
Get path to file that should be used by current instance only.
These data files will be cleaned up at Revit restart. e.g pyrevit_2016_pyrevitlabs_2353_file_id.file_ext
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_id |
str
|
Unique identifier for the file |
required |
file_ext |
str
|
File extension |
TEMP_FILE_EXT
|
name_only |
bool
|
If true, function returns file name only |
False
|
Returns:
Type | Description |
---|---|
str
|
File name or full file path (depending on name_only) |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
is_pyrevit_data_file(file_name)
Check if given file is a pyRevit data file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
str
|
file name |
required |
Returns:
Type | Description |
---|---|
bool
|
True if file is a pyRevit data file |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
is_file_available(file_name, file_ext, universal=False)
Check if given file is available within appdata directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
str
|
file name |
required |
file_ext |
str
|
file extension |
required |
universal |
bool
|
Check against universal data files |
False
|
Returns:
Type | Description |
---|---|
str | bool
|
file path if file is available |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
is_data_file_available(file_id, file_ext)
Check if given file is available within appdata directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_id |
str
|
data file id |
required |
file_ext |
str
|
file extension |
required |
Returns:
Type | Description |
---|---|
str
|
file path if file is available |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
list_data_files(file_ext, universal=False)
List all data files with given extension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_ext |
str
|
file extension |
required |
universal |
bool
|
Check against universal data files |
False
|
Returns:
Type | Description |
---|---|
list[str]
|
list of files |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
list_instance_data_files(file_ext)
List all data files associated with current session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_ext |
str
|
data files with this extension will be listed only. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list of data files |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
find_data_files(file_ext)
Find data files in all data files directories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_ext |
str
|
data files with this extension will be listed only |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list of files |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
find_instance_data_files(file_ext, instance_id)
Find instance data files in all data files directories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_ext |
str
|
data files with this extension will be listed only |
required |
instance_id |
int
|
list data files for this instance id only |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list of files |
Source code in pyrevitlib/pyrevit/coreutils/appdata.py
garbage_data_file(file_path)
Mark and remove the given appdata file.
Current implementation removes the file immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
path to the target file |
required |
cleanup_appdata_folder()
Cleanup appdata folder of all temporary appdata files.