You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With pythonocc-core=7.7.2 , trying to export XCAF to STEP, using label names.
There is an encoding issue with names that contain e.g. umlaut characters.
Trying to workaround the issue by using TCollection_ExtendedString fails with a crash at runtime.
How can I fix this encoding issue, how to use pythonocc-core properly ?
Minimal working sample code
fromOCC.CoreimportTopoDS, TopAbsfromOCC.Core.BRepimportBRep_BuilderfromOCC.Core.BRepPrimAPIimportBRepPrimAPI_MakeBoxfromOCC.Core.BinXCAFDriversimportbinxcafdriversfromOCC.Core.QuantityimportQuantity_Color, Quantity_TOC_RGBfromOCC.Core.STEPCAFControlimportSTEPCAFControl_WriterfromOCC.Core.TCollectionimportTCollection_ExtendedStringfromOCC.Core.TDFimportTDF_LabelfromOCC.Core.TDataStdimportTDataStd_NamefromOCC.Core.TDocStdimportTDocStd_Application, TDocStd_DocumentfromOCC.Core.TopoDSimportTopoDS_Shape, TopoDS_CompoundfromOCC.Core.XCAFDocimportXCAFDoc_DocumentTool, XCAFDoc_ColorGenfromOCC.Extend.DataExchangeimportread_step_filefromOCC.Core.TopLocimportTopLoc_LocationfromOCC.Core.gpimportgp_Trsf, gp_Vec, gp_QuaternionfromOCC.Core.STEPControlimport (
STEPControl_AsIs,
)
fromOCC.Core.InterfaceimportInterface_StaticfromOCC.Core.IFSelectimportIFSelect_RetDone# Create XDE documentapp=TDocStd_Application()
binxcafdrivers.DefineFormat(app)
doc=TDocStd_Document(f"example")
app.NewDocument("BinXCAF", doc)
# Toolsshape_tool=XCAFDoc_DocumentTool.ShapeTool(doc.Main()) # XCAFDoc_ShapeToolcolor_tool=XCAFDoc_DocumentTool.ColorTool(doc.Main()) # XCAFDoc_ColorToolcompound=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 )# this has encoding issues# TDataStd_Name.Set(label, "Some text with umlauts äöü")# BUT the following crashes with# TypeError: Wrong number or type of arguments for overloaded function 'TDataStd_Name_Set'.# Possible C/C++ prototypes are:# TDataStd_Name::Set(TDF_Label const &,TCollection_ExtendedString)# TDataStd_Name::Set(TDF_Label const &,Standard_GUID const &,TCollection_ExtendedString)# TDataStd_Name::Set(TCollection_ExtendedString)extended_string=TCollection_ExtendedString("Some text with umlauts äöü", True)
TDataStd_Name.Set(label, extended_string)
# add moved instance instance of a prototype to our compound shapebrep_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 exporterstep_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 filestep_writer.Transfer(doc, STEPControl_AsIs)
status=step_writer.Write("compound_with_umlaut_label.step")
ifstatus!=IFSelect_RetDone:
raiseAssertionError("write failed")
The generated STEP looks like the following in CAD Assistent:
Will there be a new release available for conda or regular python environments ? I tried to build pythonocc-core for my regular python environment but failed due to build problems of dependencies.
With pythonocc-core=7.7.2 , trying to export XCAF to STEP, using label names.
There is an encoding issue with names that contain e.g. umlaut characters.
Trying to workaround the issue by using
TCollection_ExtendedString
fails with a crash at runtime.How can I fix this encoding issue, how to use pythonocc-core properly ?
Minimal working sample code
The generated STEP looks like the following in CAD Assistent:
The generated STEP ( with the encoding issue ):
compound_with_umlaut_label.step.txt
The text was updated successfully, but these errors were encountered: