How to dumpContent/restoreContent of part

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
JMG
Posts: 288
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

How to dumpContent/restoreContent of part

Post by JMG »

Hi!

Is there a way to restore a Part object and its children using the dumpContent / restoreContent methods?

As example, open the attached test.fcstd file and try:

Code: Select all

part_bin = FreeCAD.ActiveDocument.Part.dumpContent()
new_doc = FreeCAD.newDocument()
new_part = new_doc.addObject('App::Part','RESTORED_PART')
new_part.restoreContent( part_bin )
The result is a warning on the report view as follows:
Lost link to 'Body' while loading, maybe an object was not loaded correctly
From the documentation of "dumpContent" function:

Code: Select all

FreeCAD.ActiveDocument.Part.dumpContent.__doc__
'Dumps the content of the object, both the XML representation as well as the additional datafiles \nrequired, into a byte representation. It will be returned as byte array.\ndumpContent() -- returns a byte array with full content\ndumpContent(Compression=1-9) -- Sets the data compression from 0 (no) to 9 (max)\n
The docstring of the "restoreContent" function:

Code: Select all

 FreeCAD.ActiveDocument.Part.restoreContent.__doc__
'Restore the content of the object from a byte representation as stored by "dumpContent".\nIt could be restored from any python object implementing the buffer protocol.\nrestoreContent(buffer) -- restores from the given byte array\n '
What I want to achieve is to transfer some models inside the document through network and recreate them on another file (editable, parametric and all that), as a part of a version-control system.


I only found some unconnected info about this, and this possibly related thread from which I have extracted the example shown.

Thank you :)

Edited: forgot to add my FC info.

OS: Ubuntu 20.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4.
Build type: Release
Python version: 3.8.2
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.3.0
Locale: Spanish/Spain (es_ES)
Attachments
test.FCStd
Test file
(14.66 KiB) Downloaded 35 times
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
Post Reply