Thanks ! Something like below ?realthunder wrote: ↑Thu Sep 10, 2020 1:32 am Can you elaborate how you uses these two attributes in the original FeaturePython? If you need to save those attributes to document, then you can simply addProperty to link. If it is only for runtime use, just create a bigger dictionary in the original FeaturePython and key on link. You can include original object as key too,
Code: Select all
self.links[linkObj] = ({}, '') #or use more fancy objects like namedtuple and default dict # MyStorage = namedtuple('MyStorage', ('objDict', 'objTag'), defaults=({}, '')) self.links = defaultdict(MyStorage) # then simply use it like self.links[linkObj].objDict.get('something')
Code: Select all
>>> LinkedObject.Proxy.links={}
>>> Link.Name
'Link'
>>> LinkedObject.Proxy.links[Link]=({},'')
...
>>> LinkedObject.Proxy.links[Link][0]
{'2f112fc5-57b4-4034-ab17-0e8da7d328af': {'index': 0}, 'bd1e063d-a95e-4a39-96c6-1e458bde9454': {'index': 1}}
PropertyPythonObject::toString(): failed for <class 'ArchSketchObject.ArchSketch'>
Traceback (most recent call last):
File "/home/paullee/Downloads/FreeCAD_0.19-21329-Linux-Conda_glibc2.12-x86_64/squashfs-root/usr/lib/python3.8/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/home/paullee/Downloads/FreeCAD_0.19-21329-Linux-Conda_glibc2.12-x86_64/squashfs-root/usr/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/paullee/Downloads/FreeCAD_0.19-21329-Linux-Conda_glibc2.12-x86_64/squashfs-root/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
<class 'TypeError'>: keys must be str, int, float, bool or None, not App.DocumentObject
- The dict containing DocumentObject can't be saved to file ?
- Wondering : The dict rely on the the Link Object as a key. If the original Link Object is somehow deleted, the dict entry is not deleted to my understanding. Then, when a new Link is formed, the value with the key of original Link would be wrongly be associated with the new Link Object ? ... searching how to test a Dict entry for the Link object has existed ...?
Code: Select all
{'2f112fc5-57b4-4034-ab17-0e8da7d328af': {'index': 0}, 'bd1e063d-a95e-4a39-96c6-1e458bde9454': {'index': 1}}
Code: Select all
self.Type = "Wall"
# "ArchSketch" in my test