Module, containing utilities, complementing basic Python API. Many of these functions are essential for development and can not be implemented only with public APIs.
Data Reader Cache
Performance helper when only reading actions are done on multiple objects and they are linked with objects hierarchy or attributes. It can also be used when non enum attributes are changed.
class DataReaderCacheContext
Context manger, that enables data reader cache on entering and automatically disables it on exiting. Nesting contexts is allowed.
To query, whether Data Reader cache is active now, API function pyark._IsDataReaderCacheEnabled() is used. It returns boolean value.
Network packaging (bulk mode)
arKItect operates on project data by sending requests to the data server. When modifying large number of objects (including creation, linking, attribute/property/choice modification), one request per modification is sent, which causes significant overhead and low performance. To improve performance, bulk mode is provided in arKitect.
When bulk mode is enabled, arKItect accumulates requests in memory instead of immediately sending them to server. Requests are sent later in a single or several shots, depending on whether the bulk mode is finished or 200 requests are accumulated.
The important consequence is, when bulk mode is enabled, some errors that can only be detected on server, are not detected immediately. Currently, unique constraint violation on attributes fall in this category. Programmer must check for such errors separately after exiting context.
class BulkModeContext
Context manager, that enables bulk mode on entering and automatically disables it on exiting. Nesting contexts is allowed.
Methods
- __init__( verbose=False, onConflictRaiseError=True )
if verbose flag is True, then context manager prints text messages, when enabled or disabled.
if onConflictRaiseError is True, then on leaving context, the manager will raise an exception of type arki.utils.arkinternal.ArkiUniqueConstraintException, if there were any conflicts, reported by server. Currently, only violations of unique constraint on attributes are reported, but this can be changed in future.
class ArkiUniqueConstraintException( Exception )
Exception type, raised by BulkModeContext, if errors were reported from server after committing requests.
Methods
raiseNested()
If code block, executed in BulkModeContext, raised some exception, and there were conflicts, reported after committing changes to server, then ArkiUniqueConstraintException is raised, "shadowing" the original exception. Information about the original exception is stored in this object. Programmer may call raiseNested to ensure that shadowed exception is not lost.
Code sample:
Local Script Execution
Sometimes it is needed that some actions are done locally on the data model (in the memory) and not sent to the database, e.g. Functional chains. It means that these changes are important for visualization but not for storing them. It happens with scripts (API) when on some event we need to color objects or show / hide some objects. So, information about object colors or objects presence in some chains is stored in some attributes and later when user navigates into specific diagrams, special events are triggered so that needed information is propagated to objects of the diagram and objects are shown/hidden/colored. Clearly there is no need to save applied modifications.
Another useful application of local script execution is to debug some import operations until you got the satisfying result. As soon as import looks ok you may
- replace LocalScriptContext() with BulkModeContext() and run the script again OR
- in case you fill the empty project - export project to arkz and create a new project from that arkz
Starting from arKItect 4.0.3 it has become possible to apply some modifications only locally. This should drastically decrease network load for many actions which are from user point of view are not operations at all.
class LocalScriptContext
Context manager, that enables Local Script Execution on entering and automatically disables it on exiting. Nesting contexts is allowed.
Generate Documentation (Export data) and GUI elements updates
One of advantages of the arKItect solution is that it allows generating reports from the data model. Very often this requires iterative navigation of diagrams so that images are generated and exported. Sometimes thousands of objects are navigated one by one with diagrams being calculated, shown and saved externally. From arKItect point of view this is a specific operation and arKItect should be informed about it somehow. Why?
When user navigates objects manually, arKItect takes care of updating multiple GUI elements: properties, options, location, palette, project tools, displaying treeviews etc. so that they correspond to actual object selection.
When a script navigates through objects it is definitely not the GUI elements which are of interest but usually the diagrams. So it looks logically to disable GUI updates when a script works in this way (navigation).
class ExportContext
Context manager, that enables Generate Documentation mode on entering and automatically disables on exiting. Nesting contexts is allowed. Available in arKItect 4.0.3