首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pythonOCC将默认单位设置为英寸

pythonOCC将默认单位设置为英寸
EN

Stack Overflow用户
提问于 2018-05-24 23:09:30
回答 1查看 585关注 0票数 3

请参阅编辑的短版本。

一直在通过pythonOCC文档进行搜索。

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

代码语言:javascript
复制
#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 );

文件在窗口中读取和显示:

当我使用手动坐标来制作一个边框时,我发现我的盒子是不正常的:

因为步长模型不在0,0,0,所以位置关闭。

原来pythonOCC会自动将所有内容转换为MM.。当我手动输入方框尺寸(英寸)时,它会将它们读取为MM.。我也尝试过手动转换所有内容(英寸* 25.4),但这是有问题的,而且很难看。

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

代码语言:javascript
复制
#122 = LENGTH_MEASURE_WITH_UNIT( LENGTH_MEASURE( 1.0 ), #267 );

当我这样做的时候,我的包围盒和台阶模型完美地排列在一起.但我仍然知道PythonOCC认为它正在转换为MM.。

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

编辑:

当我用我自己的坐标画我的盒子时:

代码语言:javascript
复制
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(”英寸“)”?

编辑2:

近距离看这里:

i.html

在UnitsAPI_SystemUnits和SetCurrentUnit..。虽然我不知道如何在python中实现,但还没有进行测试。我正在努力。

EN

回答 1

Stack Overflow用户

发布于 2018-05-25 19:24:55

您可以找到units here的文档

看看OCC.Extended.DataExchange模块,您将看到以下函数:

代码语言:javascript
复制
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文件的函数/方法是什么。

代码语言:javascript
复制
Interface_Static_SetCVal("Interface_Static_SetCVal("write.step.unit","MM")

但是docs声明这个方法是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.的,所以必须显式设置这个单元是出乎意料的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50519393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档