
Tue, 01/10/2023 - 18:23
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:
- The coordinates of the vertex are (1e-3, 0, 0) in the STP file
- 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?
Tue, 01/10/2023 - 19:20
Hello,
Can you initialize static variable before creating of the writer?
If it helps or not, let me know.
Best regards, Dmitrii.
Tue, 01/10/2023 - 19:24
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.
Tue, 01/10/2023 - 19:33
Thanks Dmitrii! Based on your hint, I was able to get it working as expected, but it is a bit confusing.
xstep.cascade.unit
orwrite.step.unit
before creating any STEPControl_Writer instance -Interface_Static::SetCVal()
returnsFalse
xstep.casade.unit
andwrite.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
Tue, 01/10/2023 - 20:02
You just need to call STEPCAFControl_Controller::Init(); That initialize all necessary variables. Or create a temp reader/writer.