manuel-koch
Looking around for some CAD
I'm trying build a STEP file. While building content of the XCAF document I'm assigning strings to labels.
After loading the exported STEP in CAD Assistant I can see that some of the labels contain strange characters
that were originally umlaut characters.
I guess this is some kind of encoding issue regarding label strings.
How can I fix this encoding issue, i.e. how is this done properly ?
My code is build from various samples I found. It's python using pythonocc-core=7.7.2 but I guess it is compatible with C++ writings.
# Create XDE document
app = TDocStd_Application()
binxcafdrivers.DefineFormat(app)
doc = TDocStd_Document(f"example")
app.NewDocument("BinXCAF", doc)
# Tools
shape_tool = XCAFDoc_DocumentTool.ShapeTool(doc.Main()) # XCAFDoc_ShapeTool
color_tool = XCAFDoc_DocumentTool.ColorTool(doc.Main()) # XCAFDoc_ColorTool
compound = TopoDS_Compound()
brep_builder = BRep_Builder()
brep_builder.MakeCompound(compound)
shape = BRepPrimAPI_MakeBox(10, 10, 10).Shape()
label = shape_tool.AddShape(shape, False)
# Set custom name on label ( i.e. the shape it refers to )
TDataStd_Name.Set(label, "Some text with umlauts äöü") # FIXME this causes the encoding issue
# add moved instance instance of a prototype to our compound shape
brep_builder.Add(compound, shape)
compund_label = shape_tool.AddShape(compound, True)
# Set custom name on label ( i.e. the shape it refers to )
TDataStd_Name.Set(compund_label, "compound")
# Initialize the STEP exporter
step_writer = STEPCAFControl_Writer()
# To make sub-shape names work, we have to turn on the following static
# variable of OpenCascade.
Interface_Static.SetIVal("write.stepcaf.subshapes.name", 1)
Interface_Static.SetCVal("write.step.schema", "AP214")
Interface_Static.SetCVal("write.step.product.name", "my product")
# transfer compound shape and write STEP file
step_writer.Transfer(doc, STEPControl_AsIs)
output_step_path = ASSETS_DIR / "compound_with_umlaut_label.step"
status = step_writer.Write(output_step_path.as_posix())
if status != IFSelect_RetDone:
raise AssertionError("write failed")
After loading the exported STEP in CAD Assistant I can see that some of the labels contain strange characters
that were originally umlaut characters.
I guess this is some kind of encoding issue regarding label strings.
How can I fix this encoding issue, i.e. how is this done properly ?
My code is build from various samples I found. It's python using pythonocc-core=7.7.2 but I guess it is compatible with C++ writings.
# Create XDE document
app = TDocStd_Application()
binxcafdrivers.DefineFormat(app)
doc = TDocStd_Document(f"example")
app.NewDocument("BinXCAF", doc)
# Tools
shape_tool = XCAFDoc_DocumentTool.ShapeTool(doc.Main()) # XCAFDoc_ShapeTool
color_tool = XCAFDoc_DocumentTool.ColorTool(doc.Main()) # XCAFDoc_ColorTool
compound = TopoDS_Compound()
brep_builder = BRep_Builder()
brep_builder.MakeCompound(compound)
shape = BRepPrimAPI_MakeBox(10, 10, 10).Shape()
label = shape_tool.AddShape(shape, False)
# Set custom name on label ( i.e. the shape it refers to )
TDataStd_Name.Set(label, "Some text with umlauts äöü") # FIXME this causes the encoding issue
# add moved instance instance of a prototype to our compound shape
brep_builder.Add(compound, shape)
compund_label = shape_tool.AddShape(compound, True)
# Set custom name on label ( i.e. the shape it refers to )
TDataStd_Name.Set(compund_label, "compound")
# Initialize the STEP exporter
step_writer = STEPCAFControl_Writer()
# To make sub-shape names work, we have to turn on the following static
# variable of OpenCascade.
Interface_Static.SetIVal("write.stepcaf.subshapes.name", 1)
Interface_Static.SetCVal("write.step.schema", "AP214")
Interface_Static.SetCVal("write.step.product.name", "my product")
# transfer compound shape and write STEP file
step_writer.Transfer(doc, STEPControl_AsIs)
output_step_path = ASSETS_DIR / "compound_with_umlaut_label.step"
status = step_writer.Write(output_step_path.as_posix())
if status != IFSelect_RetDone:
raise AssertionError("write failed")