How do I write a step with GDT's ?

I have the following code two create a shape and adding a dimension measurement to it:


Standard_CString fname("somefile.step"); // create shape TopoDS_Shape box1 = BRepPrimAPI_MakeBox(100.0, 100.0, 50.0).Shape(); // Base box TopoDS_Shape box2 = BRepPrimAPI_MakeBox(gp_Pnt(100.0, 50.0, 0.0), 50.0, 100.0, 50.0).Shape(); // Vertical box TopoDS_Shape lShape = BRepAlgoAPI_Fuse(box1, box2).Shape(); // Create document Handle(TDocStd_Application) app = new TDocStd_Application; BinXCAFDrivers::DefineFormat(app); Handle(TDocStd_Document) doc; app->NewDocument("BinXCAF", doc); if (doc.IsNull()) { cout << "Document is null" << endl; return 1; } TDF_Label rootLab = doc->Main(); Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main()); //TDF_Label shapeLab = shapeTool->AddShape(lShape); // the same??? TDF_Label shapeLab = shapeTool->NewShape(); shapeTool->SetShape(shapeLab, lShape); // create dimension Handle(XCAFDoc_DimTolTool) dimTolTool = XCAFDoc_DocumentTool::DimTolTool(doc->Main()); TDF_Label dimLab = dimTolTool->AddDimension(); Handle(XCAFDoc_Dimension) dim; dimLab.FindAttribute(XCAFDoc_Dimension::GetID(), dim); if (dim.IsNull()) { cout << "Dimension is null" << endl; return 1; } Handle(XCAFDimTolObjects_DimensionObject) dimObj = dim->GetObject(); dimObj->SetType(XCAFDimTolObjects_DimensionType_Location_LinearDistance); dimObj->SetPoint(gp_Pnt(0.0, 0.0, 0.0)); dimObj->SetPoint2(gp_Pnt(150, 150, 150)); dimObj->SetValue(99.99); dim->SetObject(dimObj); // link dimension to shape dimTolTool->SetDimension(shapeLab, dimLab); // write file STEPCAFControl_Writer writer; if (!writer.Transfer(doc)) { cout << "Failed to transfer" << endl; return 1; } writer.Write(fname);

The problem however is that if I try to save the document, the pmi is not being written. What am I doing wrong? The opencascade guide doesn't explain it. Please help.