Page 1 of 1

Serializing and deserializing a temporary body

Posted: Sat Dec 11, 2021 5:59 am
by laukejas
Hi,

I found this great article on CodeStack (https://www.codestack.net/solidworks-ap ... y-to-file/) on how to serialize a solid SOLIDWORKS body into a binary stream, and then save it to a local hard drive as a .dat file.

However, that article does not address on how to restore that file back into SOLIDWORKS (deserialize). In my macro, I need a following workflow:

1. Get solid bodies from an open part document;
2. Create temporary bodies from them;
3. Perform various geometric operations on these temporary bodies;
4. Save these temporary bodies into .dat files;
5. In another session, restore these temporary bodies back into the same (or different) model.

That last bit is what I can't figure out how to do. Any suggestions?

Re: Serializing and deserializing a temporary body

Posted: Sun Dec 12, 2021 11:33 pm
by artem
@laukejas , here is the counter-part of the above example: https://www.codestack.net/solidworks-ap ... from-file/. Also this example might be helpful (this stores/restores the body into the file's 3rd party stream): https://www.codestack.net/solidworks-ap ... tore-body/. And here is one of my old blog posts how this can be used for fun: https://blog.codestack.net/solidworks-3d-watermark

Re: Serializing and deserializing a temporary body

Posted: Mon Dec 13, 2021 9:19 am
by SPerman
What is the advantage of that over saving it as a parasolid, step or iges?

Re: Serializing and deserializing a temporary body

Posted: Tue Dec 14, 2021 8:14 am
by laukejas
artem wrote: Sun Dec 12, 2021 11:33 pm @laukejas , here is the counter-part of the above example: https://www.codestack.net/solidworks-ap ... from-file/. Also this example might be helpful (this stores/restores the body into the file's 3rd party stream): https://www.codestack.net/solidworks-ap ... tore-body/. And here is one of my old blog posts how this can be used for fun: https://blog.codestack.net/solidworks-3d-watermark
That's amazing, thank you. I have no idea how I missed that on the website...
SPerman wrote: Mon Dec 13, 2021 9:19 am What is the advantage of that over saving it as a parasolid, step or iges?
It should be faster (even than parasolid), besides, I'm not even sure if it is possible to save temporary bodies as parasolids... As for step/iges - these are non-native formats for SOLIDWORKS, so it would be slower, less accurate and prone to geometry errors upon re-import.