Load shapes from STEP file and save them to invidual files

Hi everyone,

I want to do the following:

-Load a step file containing several Shapes.
-Look in every shape for the color and save it to a individual file.
In the filename there should be an flag if the color is golden (rgb 192, 255, 0)

This is what I have now:

STEPControl_Reader reader;
IFSelect_ReturnStatus stat = reader.ReadFile("C:\\Users\\User\\Desktop\\Tool\\527009.stp");

Standard_Integer NbRoots = reader.NbRootsForTransfer(); // gets the number of transferable roots 
std::cout << "Number of roots in STEP file : " << NbRoots << std::endl;

Standard_Integer NbTrans = reader.TransferRoots(); // translates all transferable roots, and returns the number of successful translations 
std::cout << "STEP roots transferred : " << NbTrans << std::endl;
std::cout << "Number of resulting shapes is : " << reader.NbShapes() << std::endl;

// Here I should have a set or something else of the shapes (instance of TopoDS_Shape)
std::set<TopoDS> setOfShapes;
setOfShapes = ? ? ? ;

unsigned int idx = 0;
for (auto it = begin(vector); it != end(vector); ++it) {


	TopoDS_Shape single_shape = it;

	// In this part I must compare the color and save to a boolean if it´s gold
	bool isGolden = ? ? ? ;

	// Write to the file.
	STEPControl_Writer aWriter;
	IFSelect_ReturnStatus aStat = aWriter.Transfer(singleShape, STEPControl_AsIs);

	std::stringstream path;
	if (isGolden) {
		path << "C:\\Users\\User\\Desktop\\Tool\\527009_" << idx << "_g.stp";
	else {
		path << "C:\\Users\\User\\Desktop\\Tool\\527009_" << idx << ".stp";
	Standard_CString sPath = path.str().c_str();
	aStat = aWriter.Write(sPath);
	if (aStat != IFSelect_RetDone)
		cout << "Writing error" << endl;
Please forgive me my cpp skills. Normally, I program java.

Thanks in advance!!

Hugues Delorme's picture

To handle STEP colors you should use STEPCAF_ControlReader/STEPCAF_ControlWriter instead.

You can have a look at those files from my Mayo project :



Member functions XdeDocumentItem::rebuildAssemblyTree() and XdeDocumentItem::shapeColor()

tschwenk_142989's picture

Hello Permalink,

Thank you for your efforts but that seems to be complicated for me.

Best regards

Timo Schwenk