Import and Export

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Import and Export

Post by keithsloan52 »

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
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Import and Export

Post by vocx »

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")
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply