Differences in behavior with units, xstep.cascade.unit and STEPControl_Writer from 7.5 -> 7.6

I am seeing some differences with the behavior of STEPControl_Writer and xstep.cascade.unit between OpenCASCADE 7.5.3 and 7.6.3.

In my application, I use xstep.cascade.unit to set the model's units, and write.step.unit to control the units written to the STP file. This seems to have worked fine with 7.5.3, but no longer with 7.6.3.

Below is a snippet which:

  • Creates a vertex at (1, 0, 0)
  • Specifies that the model units are in "MM" and the output units should be "M"
  • Writes the STEP file

Note, I am using the OCP bindings from Python.

from OCP import Interface, STEPControl, gp, BRepBuilderAPI

# make a point
pnt = gp.gp_Pnt(1, 0, 0)
vertex = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(pnt).Vertex()

# instantiate writer
w = STEPControl.STEPControl_Writer()

# set units
model_units = 'MM'
output_units = 'M'

if not Interface.Interface_Static.SetCVal_s('xstep.cascade.unit', model_units):
    raise ValueError

if not Interface.Interface_Static.SetCVal_s('write.step.unit', output_units):
    raise ValueError

# transfer shapes and write
w.Transfer(vertex, STEPControl.STEPControl_AsIs)
w.Write("test.stp")

I would expect the following to be true:

  1. The coordinates of the vertex are (1e-3, 0, 0) in the STP file
  2. The LENGTH_UNIT in the file is SI_UNIT($,.METRE.)

For both OpenCASCADE 7.5.3 and 7.6.3, #2 is true. However, with 7.6.3, the coordinates of the vertex are (1, 0, 0) - they are not converted.

Attached are the STEP files for both 7.5.3 and 7.6.3.

Is there a different API I should use if I wish to do unit conversion upon writing to STP?

Attachments: 
Dmitrii Pasukhin's picture

Hello,

Can you initialize static variable before creating of the writer?

If it helps or not, let me know.

Best regards, Dmitrii.

 

Dmitrii Pasukhin's picture

Additionally, please use the next code to be fully sure.
UnitsMethods::SetCasCadeLengthUnit(Interface_Static::IVal("xstep.cascade.unit"));

We use not static variable in the code, we use UnitsMethods.
To use a Static variable it is necessary to call XSAlgo::XSAlgo_AlgoContainer()->PrepareForTransfer() or the code before.
After init of static variable.

Best regards, Dmitrii.

Phillip Chiu's picture

Thanks Dmitrii! Based on your hint, I was able to get it working as expected, but it is a bit confusing.

  1. I cannot set xstep.cascade.unit or write.step.unit before creating any STEPControl_Writer instance - Interface_Static::SetCVal() returns False
  2. Therefore, I first create a dummy writer. Then I set xstep.casade.unitand write.step.unit. Finally I create the writer that I actually use.

Creating the dummy writer is only required for OpenCASCADE 7.6.

The complete working snippet is below

from OCP import Interface, STEPControl, gp, BRepBuilderAPI

# make a point
pnt = gp.gp_Pnt(1, 0, 0)
vertex = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(pnt).Vertex()

# set write options
dummy = STEPControl.STEPControl_Writer()  # this is required to set static variables
model_units = 'MM'
output_units = 'M'
Interface.Interface_Static.SetCVal_s('xstep.cascade.unit', model_units)
Interface.Interface_Static.SetCVal_s('write.step.unit', output_units)

# instantiate writer
w = STEPControl.STEPControl_Writer()

# transfer shapes and write
w.Transfer(vertex, STEPControl.STEPControl_AsIs)
w.Write("test.stp")

with open("test.stp", "r") as f:
    print(''.join(f.readlines()))
Dmitrii Pasukhin's picture

You just need to call  STEPCAFControl_Controller::Init(); That initialize all necessary variables. Or create a temp reader/writer.