Reading units from stp file

I'd like to find the units that a step file was saved with.

I can get the conversion factor to SI using http://www.opencascade.org/org/forum/thread_7149

However I would rather get the actual unit name. I'm using this code:

STEPCAFControl_Reader reader;
reader.ReadFile("test.stp");
Standard_CString unitname = Interface_Static::CVal("xstep.cascade.unit");
cout

However it's always MM even when the step file has different units.

How should I be doing this?

Thanks ...

Markus Rhein's picture

As I understand it the paramter "xstep.cascade.unit" is the target unit in OpenCASCADE which should be converted to. So you will always get the default value "MM" here if you don´t change the parameter yourself.

The forum post you linked to uses the method po_model->GlobalSection().UnitValue() already, perhaps you should try using
po_model->GlobalSection().UnitValue() instead to receive the unit name you are looking for.
See IGESData_GlobalSection Class Reference in doxygen for details.

I hope this works. Didn´t try it though.

Markus Rhein's picture

Sorry, I just realized you asked for STEP and not IGES.
In this case I think you could try something like this:

STEPControl_Reader reader;
reader.ReadFile (s_file_name);
DeclareAndCast (StepData_StepModel, model, reader.Model());
for (int i = 1; i < model->NbEntities(); ++i)
{
if (model->Entity(i)->IsKind (STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)))
{
DeclareAndCast (StepBasic_ConversionBasedUnitAndLengthUnit, convUnit, model->Entity(i));
TCollection_HAsciiString unitName = convUnit->Name ();
unitName.Print (cout);
break;
}
}

Forum supervisor's picture

Dear Wayne,
OCCT 6.5.3 provides a dedicated tool allowing to consult units found in the STEP file.
See Release Notes, issue 23009 on page 28.
Regards