Mesh read from string vs read from file

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
jbi
Posts: 117
Joined: Sun Apr 24, 2016 3:28 pm

Mesh read from string vs read from file

Post by jbi »

Hello,

Usually meshes are read from file with for example

Code: Select all

top_cad=Mesh.Mesh()
top_cad.read(sourcetopcadfile)
Is there a way to read from string? I have tried:

Code: Select all

with open(sourcetopcadfile,'r') as f:
	ds = f.read()

top_cad=Mesh.Mesh()
top_cad.read(ds)
but this ends with Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: must be string without null bytes, not str

The reason for this is I would like to have flexiblity to pass this mesh around as string which I can pickle and send out to other processes as well. Maybe I will put the mesh in a database as well.
Is there a way?

best regards jbi
User avatar
onekk
Veteran
Posts: 6197
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Mesh read from string vs read from file

Post by onekk »

did you see:

https://wiki.freecadweb.org/Mesh_Scripting

It seems that you could pas the vertex of the mesh as a list of points, from this, you could create a temporary list and then populate it with only the desired vertex.

Your problem in reading objects could be generated by the fact that maybe the stl file you are reading is compressed, so you must decompress it to obtain the string structure.

According to this page although not authoritative, STL file could be in ASCII or binary format https://en.wikipedia.org/wiki/STL_%28file_format%29.


Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply