Load STEP from memory instead of file

Hi,

Is it possible to open a file directly from a byte array instead of reading a file?

thanks,

Alfonso

 

Kirill Gavrilov's picture

There is not such functionality (yet).
The feature status can be tracked within issue #0027342 on bug tracker (don't be confused by current status "resolved", existing patch is not ready for using).

Alfonso Tamés's picture

Thanks for the update, I hope it supports C++ streams soon.

All the best,

Alfonso

Martin Walter's picture

Is there any insight on when this will be available for writing step files?

Best regards,

Martin

Kirill Gavrilov's picture

OCCT 7.5.0 has been introduced support for reading STEP files from a C++ stream.
So far, nobody reported the feature request for writing STEP file into stream on OCCT Bugtracker - you can be first:
https://dev.opencascade.org/index.php?q=home/get_involved

haidong ma's picture

add this write stream feature in here: #0032350

Jan Selchow's picture

Hello it seems like the write to Stream Issue has also bin resolved for OCC v7.7.0
Could someone post a working example for both reading from and writing to byte[]?
Also is this only for STEP or can I also import and export for example GLTFs from/to byte[]?
Thank you.

gkv311 n's picture

Jan Selchow wrote

it seems like the write to Stream Issue has also bin resolved for OCC v7.7.0

"resolved" bug state doesn't mean integration, it means that somebody provided a patch for review.

Dmitrii Pasukhin's picture

Hello,

Writing a STEP file to a stream is integrated into ver. 7.7

// Reading to XCAF
STEPCAFControl_Reader aReader;
std::ifstream aStream;
OSD_OpenStream (aStream, aFilePath, std::ios::in | std::ios::binary);
aReader.ReadStream (aFileNameShort, aStream);
aReader.Transfer (aDoc);

// Writing from XCAF
STEPCAFControl_Writer aWriter;
aWriter.Transfer (aDoc);
std::ofstream aStream;
OSD_OpenStream (aStream, aFilePath, std::ios::out | std::ios::binary);
aWriter.WriteStream (aStream);

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

Additionally, to work with "buffer" you can use a special C++ class - std::ostringstream.

std::ostringstream anOutputStream;
aWriter.WriteStream (anOutputStream);
std::string aRes = anOutputStream.str();

Unfortunately, you can't export/import GLTF to/from any buffers yet. Only file. If it is necessary, we can create a ticket to impliment ability to work RWMesh ToolKit (Gltf, Obj, Ply) with stream.

Best regards, Dmitrii.