Serializing and deserializing a temporary body

Programming and macros
laukejas
Posts: 133
Joined: Sun Sep 05, 2021 8:27 am
Answers: 0
x 33
x 84

Serializing and deserializing a temporary body

Unread post 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?
artem
Posts: 26
Joined: Thu Mar 18, 2021 1:31 pm
Answers: 3
x 9
x 73

Re: Serializing and deserializing a temporary body

Unread post 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
Thanks,
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
User avatar
SPerman
Posts: 1869
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2044
x 1706
Contact:

Re: Serializing and deserializing a temporary body

Unread post by SPerman »

What is the advantage of that over saving it as a parasolid, step or iges?
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
laukejas
Posts: 133
Joined: Sun Sep 05, 2021 8:27 am
Answers: 0
x 33
x 84

Re: Serializing and deserializing a temporary body

Unread post 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.
Post Reply