[solved] Creating a new .FCStd from Document.xml

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
realthunder
Posts: 1204
Joined: Tue Jan 03, 2017 10:55 am

Re: [solved] Creating a new .FCStd from Document.xml

Postby realthunder » Mon Oct 14, 2019 2:28 am

foadsf wrote: ↑
Sat Oct 12, 2019 10:20 am
hmmm, πŸ€” both have their own benefits. The current version is fast to load, especially if your design is really big and complicated. But the XML version is small. I wouldn't consider it as a form of compression or a huge advantage though. The main advantage IMO is the fact that one can use conventional version control such a git, mercurial, subversion ... which seems to be a huge feature lacking in the FC ecosystem at the moment. besides if there is any possibility to import/include/nest XMLs recursively into one another and if there are any possibilities to define parameters across the scop of an XML file, then theoretically one should be able to achieve full programmatic CAD using just XMLs.

I would say there should be an option in the FreeCAD settings to save files as it is right now or pure XML format. Also, this should be added to the import-export instead of the peculiar Tools β†’ Project utility.
I have already implemented this feature in my branch. I plan to merge this in near future. You can save the project into a directory without compression and fully text based suitable for version control. Not all of them are XML though, because FC uses a lot of external libraries, not all of them support XML output.
Try Assembly3 (latest version 0.10.2) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
reox
Posts: 664
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [solved] Creating a new .FCStd from Document.xml

Postby reox » Mon Oct 14, 2019 11:55 am

so I came here from this post: https://forum.freecadweb.org/viewtopic. ... 49#p340949
according to what foadsf described, I should be able to recover a file just from Document.xml? I doubt that and the error message I get seems to be pretty clear:

Code: Select all

Traceback (most recent call last):
  File "<string>", line 66, in <module>
  File "<string>", line 51, in createDocument
  File "/usr/lib/python3.7/zipfile.py", line 1713, in write
    zinfo = ZipInfo.from_file(filename, arcname)
  File "/usr/lib/python3.7/zipfile.py", line 506, in from_file
    st = os.stat(filename)
<class 'FileNotFoundError'>: [Errno 2] No such file or directory: '/home/reox/CAD/tmp/PartShape.brp'
Unhandled Base::Exception caught in GUIApplication::notify.
The error message is: [Errno 2] No such file or directory: '/home/reox/CAD/tmp/PartShape.brp'
What I did: Create some object (attached), unpack it, delete everything except Document.xml, try to use Project utility to create a document.
Does Project Utility does something different when extracting the document? It does not look like it.

Another question is, if the changes of realthunder are already in master (It looks like it) - I'm running:

Code: Select all

OS: Debian GNU/Linux bullseye/sid (i3/i3)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18527 (Git)
Build type: Release
Branch: master
Hash: 1f5f00e655b573489c3e897efd5d87e93cf77f15
Python version: 3.7.5rc1
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: C/Default (C)
Attachments
foobar.FCStd
(60.1 KiB) Downloaded 9 times
foadsf
Posts: 88
Joined: Fri Mar 06, 2015 10:02 pm
Contact:

Re: [solved] Creating a new .FCStd from Document.xml

Postby foadsf » Mon Oct 14, 2019 12:31 pm

reox wrote: ↑
Mon Oct 14, 2019 11:55 am
I doubt that
except for some small issues, it worked pretty well for me!

Image


my environment is

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16131 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 3129ae4296e40ed20e7b3d460b86e6969acbe1c3
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Last edited by foadsf on Tue Oct 15, 2019 10:01 am, edited 1 time in total.
reox
Posts: 664
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [solved] Creating a new .FCStd from Document.xml

Postby reox » Tue Oct 15, 2019 8:49 am

Have you tested that with the file I attached?
Is the brep code inserted into the Document.xml or how does this work?
foadsf
Posts: 88
Joined: Fri Mar 06, 2015 10:02 pm
Contact:

Re: [solved] Creating a new .FCStd from Document.xml

Postby foadsf » Tue Oct 15, 2019 10:05 am

reox wrote: ↑
Tue Oct 15, 2019 8:49 am
Have you tested that with the file I attached?
Is the brep code inserted into the Document.xml or how does this work?
Sorry, the embedded gif link was broken. I uploaded a new one. please see the steps as I did it. I unarchived your file, deleted everything except Document.XML and then the above steps.
reox
Posts: 664
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: [solved] Creating a new .FCStd from Document.xml

Postby reox » Tue Oct 15, 2019 11:43 am

Ah you get the same error - look in the status bar.
So, this error means success then :lol:
foadsf
Posts: 88
Joined: Fri Mar 06, 2015 10:02 pm
Contact:

Re: [solved] Creating a new .FCStd from Document.xml

Postby foadsf » Tue Oct 15, 2019 8:53 pm

reox wrote: ↑
Tue Oct 15, 2019 11:43 am
Ah you get the same error - look in the status bar.
So, this error means success then :lol:

I tried this on my mac and I now notice the error message. It works after recomputing the subparts but not as smoothly as on Windows and stable version:

OS: macOS Mojave (10.14)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18403 (Git)
Build type: Release
Branch: master
Hash: 0717b4fc23ef1db70964c3977d25e2fe46a739d1
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)


This actually could be a bug report.
realthunder
Posts: 1204
Joined: Tue Jan 03, 2017 10:55 am

Re: [solved] Creating a new .FCStd from Document.xml

Postby realthunder » Wed Oct 16, 2019 2:02 am

foadsf wrote: ↑
Tue Oct 15, 2019 8:53 pm
I tried this on my mac and I now notice the error message. It works after recomputing the subparts but not as smoothly as on Windows and stable version:
I don't think that counts as a bug. The Document.xml contains the essential recipe for building all the objects, but you are leaving out all the built result and visual setting. So when you reload it, you are expected to do a full recomputation. So while loading is faster, it is not really useful until you recompute everything, which will be much slower than a full loading. Moreover, depending on the original version the file is authored, and the version you loading this 'partial' project file, you may get recomputation error, because of different versions of libraries used to create all the intermediate results.

My patch (not in upstream yet) offers several saving options. One of them allows you to store everything (including the intermediate results) into two xml files, Document.xml and GuiDocument.xml. So no recomputation required when loading. But the size of the file will be big. The intention is for version control, not space saving.
Try Assembly3 (latest version 0.10.2) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal