Import and Export

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
keithsloan52
Posts: 1031
Joined: Mon Feb 27, 2012 5:31 pm

Import and Export

Postby keithsloan52 » Fri Jul 19, 2019 4:12 pm

Okay I can define in say init.py an Import for a file type with FreeCAD.addImportType(string, string) and it looks for either an open() function
or an import() function in the named python file . I can also define an export type with FreeCAD. addExportType(string, string) and it looks for an export() function in a named python file.

Now if I make the import and export python files the same name can I use a global variable in the python file and have access for both import and export i.e. could I pass some data between import and export without storing the data in the FreeCAD doc.
vocx
Posts: 1870
Joined: Thu Oct 18, 2018 9:18 pm

Re: Import and Export

Postby vocx » Thu Aug 15, 2019 11:39 pm

keithsloan52 wrote:
Fri Jul 19, 2019 4:12 pm
...
...could I pass some data between import and export without storing the data in the FreeCAD doc.
I'm not sure what you would need to pass around. Maybe provide an example?
keithsloan52 wrote:
Fri Jul 19, 2019 4:12 pm
Now if I make the import and export python files the same name can I use a global variable in the python file and have access for both import and export...
The importFile.py is able to hold the import functions and export functions in the same file. There is no need to have two separate files, although this is probably better to better organize the code; see importIFC module refactor.

For example, in the Draft Workbench the importer and exported are under the same namespace.

Code: Select all

import importSVG

importSVG,open("/home/user/whatever.svg")

importSVG.export([object1, object2, object3], "/home/user/out.svg")