Hello,
an important functionality for assemblies is a BOM: Bill Of Materials. In order to work well, parts need to have some fields set, like ID, reference number, name, supplier, material ... these info fields are specific to people and projects, so I would like to have the possibility to create and apply templates to objects. The basic idea is that objects have additional properties added to it (with obj.addProperty()) and to have these properties set in a template somewhere, such that this template can be applied which would pre-fill the object's properties.
I've seen that the Path WB does allow to do this for tools, and stores the templates (or tool definitions) in the user's FreeCAD settings folder as JSON files.
Is there some documentation somewhere on the use of JSON files are, how to create and how to read them ? Thanx
object properties from template
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: object properties from template
JSON files are fairly easy to deal with. Code is untested.
Code: Select all
import json
some_dictionary = {"a":1,"b":2,"c":3}
filename = "json.txt"
with open(filename,"w") as outfile:
json.dump(some_dictionary,outfile)
f = open(filename)
some_other_dictionary = json.load(f)
f.close()
Re: object properties from template
great, thanx, will try.TheMarkster wrote: ↑Sat Sep 18, 2021 3:49 am JSON files are fairly easy to deal with. Code is untested.
as a second question, I'd like to save the JSON templates into the user config directory (where the user.cfg file is): what is the way to retrieve the pah to that directory ?
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: object properties from template
Zolko wrote: ↑Sun Sep 19, 2021 2:47 pmgreat, thanx, will try.TheMarkster wrote: ↑Sat Sep 18, 2021 3:49 am JSON files are fairly easy to deal with. Code is untested.
as a second question, I'd like to save the JSON templates into the user config directory (where the user.cfg file is): what is the way to retrieve the pah to that directory ?
Code: Select all
App.getUserAppDataDir()