![]() |
![]() |
![]() |
---|---|---|
Plugin Configuration | Plugins | Export Filters |
Sketch uses import filters to read vector drawings from files.
For import filter configuration, Sketch uses the following variables:
type
The type must be Import
. This identifier is defined in the
globals() dictionary.
class_name
A string containing the name of a Python class defined in the module. See below for the interface this class has to provide.
rx_magic
A string containing a regular expression suitable for the re module. This regular expression is matched against the first line of the file. if it matches, the import mechanism assumes that the filter understands the file's format and then procedes to use that filter to load the file. So, if possible, this regular expression should match those files the filter can handle and only those.
While this method of identifying files is not really sufficient to handle all file types, it works well enough for now. In the future we will probably have to extend this mechanism.
tk_file_type
A tuple containing two elements. The first is the name of the file format presented to the user in the file open dialog. The second element is eithe a string or a tuple of strings. Each of the strings defines a file name extension used for that filename.
Examples:
#tk_file_type = ('Sketch Document', '.sk')
#tk_file_type = ('PostScript file', ('.ps', '.eps'))
unload
(optional)A boolean. True means that the filter module should be unloaded after use, false means that it shouldn't be unloaded. If the module is unloaded it will be imported again the next time the filter is needed. Infrequently used filters should set this to true, frequently used filters (like the filter for Sketch's own format) should set it to true.
If omitted, it defaults to false.
It's a good idea to set this variable to true at least while developing a filter because that way the filter will be automatically reloaded when the source file changes.
format_name
The name of the format as a string. This name is currently used internally to find out whether a document was loaded from a file in Sketch's format or from a different format (in the latter case `Save' is treated like `Save As...', i.e. the user has to provide a filename).
The interface a loader class presents to the document loading mechanism is quite simple. The loading mechanism works roughly as follows: