3

请参阅简短版本的编辑

一直在为此寻找 pythonOCC 文档。

我有以英寸为单位的 .step 文件。以下是 .step 文件中用于确认的行:

#50 =  ( CONVERSION_BASED_UNIT( 'INCH', #122 )LENGTH_UNIT(  )NAMED_UNIT( #125 ) );
#51 =  ( NAMED_UNIT( #127 )PLANE_ANGLE_UNIT(  )SI_UNIT( $, .RADIAN. ) );
#52 =  ( NAMED_UNIT( #127 )SI_UNIT( $, .STERADIAN. )SOLID_ANGLE_UNIT(  ) );
~~~
#122 = LENGTH_MEASURE_WITH_UNIT( LENGTH_MEASURE( 25.4000000000000 ), #267 );

文件读取并在窗口中显示: 展示窗

当我使用手动坐标制作边界框时,我发现我的框太离谱了:

小边框!

位置已关闭,因为 STEP 模型不在 0,0,0 处。

原来 pythonOCC 会自动将所有内容转换为 MM。当我在英寸中手动输入框尺寸时,它将它们读取为 MM。我也尝试过手动转换所有内容(英寸* 25.4)来处理,但这有问题且丑陋。

我知道 pythonOCC 使用 STEP 文件第 122 行作为转换率,因为我已将其从上面更改为:

#122 = LENGTH_MEASURE_WITH_UNIT( LENGTH_MEASURE( 1.0 ), #267 );

当我这样做时,我的边界框和步进模型完美地对齐......但我仍然知道 PythonOCC 认为它正在转换为 MM。

完美!...但在MM

任何人都有更改 pythonocc 的默认单位的经验吗?我试图在以下 occ 包中找到:OCC.STEPControl、OCC.Display、OCC.AIS 和许多其他包。

编辑:

当我使用自己的坐标绘制我的盒子时,如下所示:

minPoint = gp_Pnt(minCoords)
maxPoint = gp_Pnt(maxCoords)
my_box = AIS_Shape(BRepPrimAPI_MakeBox(minPoint, maxPoint).Shape())
display.Context.Display(my_box.GetHandle())

我的坐标以英寸为单位,但 pythonOCC 将它们读取为 MM。如果我能以英寸为单位读取自己的坐标,这将得到解决。在 OCC.Display 中找不到关于我的坐标是如何解释的任何内容。像“ OCC.Display.inputUnitsAre("INCHES") ”这样的东西?

编辑2:

在这里近距离观察:

https://dev.opencascade.org/doc/refman/html/class_units_a_p_i.html

在 UnitsAPI_SystemUnits 和 SetCurrentUnit 下...虽然我不确定如何在 python 中实现尚未测试。正在努力。

4

1 回答 1

1

你会发现文档units here

看一下OCC.Extended.DataExchange模块,你会看到以下功能:

def write_step_file(a_shape, filename, application_protocol="AP203"):
    """ exports a shape to a STEP file
    a_shape: the topods_shape to export (a compound, a solid etc.)
    filename: the filename
    application protocol: "AP203" or "AP214"
    """
    # a few checks
    assert not a_shape.IsNull()
    assert application_protocol in ["AP203", "AP214IS"]
    if os.path.isfile(filename):
        print("Warning: %s file already exists and will be replaced" % filename)
    # creates and initialise the step exporter
    step_writer = STEPControl_Writer()
    Interface_Static_SetCVal("write.step.schema", "AP203")

    # transfer shapes and write file
    step_writer.Transfer(a_shape, STEPControl_AsIs)
    status = step_writer.Write(filename)

    assert status == IFSelect_RetDone
    assert os.path.isfile(filename)

默认情况下,OCC以毫米为单位写入,所以我很好奇使用什么函数/方法来导出STEP文件。

Interface_Static_SetCVal("Interface_Static_SetCVal("write.step.unit","MM")

文档虽然声明了这个方法Defines a unit in which the STEP file should be written. If set to unit other than MM, the model is converted to these units during the translation.,所以必须显式设置这个单位是出乎意料的。

于 2018-05-25T19:24:55.693 回答