Siemens-NXUG二次开发-创建平面(无界非关联)、固定基准面[Python UF][20240614]

Siemens-NXUG二次开发-创建平面(无界非关联)、固定基准面[Python UF][20240614]

  • 1.python uf函数
    • 1.1 NXOpen.UF.Modeling.CreatePlane
    • 1.2 NXOpen.UF.ModlFeatures.CreateFixedDplane
  • 2.示例代码
    • 2.1 pyuf_plane.py
  • 3.运行结果
    • 3.1 内部模式
      • 3.1.1 NXOpen.UF.Modeling.CreatePlane在NXUG界面上等价对话框
      • 3.1.2 NXOpen.UF.ModlFeatures.CreateFixedDplane在NXUG界面上等价对话框
    • 3.2 外部模式

1.python uf函数

1.1 NXOpen.UF.Modeling.CreatePlane

# 内部和外部模式可用
"""
返回值:一个元组,元素类型为python的int类型,块特征的feature tag标识。
"""             
def NXOpen.UF.Modeling.CreatePlane(self, origin_point, plane_normal)
	'''
	origin_point-float list[x,y,z]:平面上某点坐标,plane_normal-float list[x,y,z]:平面法向向量
    返回值:平面特征tag标识
	'''

1.2 NXOpen.UF.ModlFeatures.CreateFixedDplane

# 内部和外部模式可用
"""
返回值:一个tag,固定基准面特征tag。
"""             
def NXOpen.UF.ModlFeatures.CreateFixedDplane(self, point, direction)
	'''
    point-float list[x,y,z]:平面上的一个点,direction-float list[x,y,z]:平面法线向量
    返回值:一个整数:固定基准平面特征tag标识
	'''

2.示例代码

2.1 pyuf_plane.py

import NXOpen
import NXOpen.UF as UF


def get_uf_session():
    # 获取当前python UF会话
    return UF.UFSession.GetUFSession()

def get_py_session():
    # 获取当前python会话
    return NXOpen.Session.GetSession()

def pyuf_new_prt(the_pyuf_session, new_prt_file_name, units = 1):
    """
    功能:创建一个指定文件路径和文件名的.prt文件,默认单位制是米(m)
    """

    # 由于要对Part进行操作,因此需要获取Part实例对象
    pyuf_part_instance = the_pyuf_session.Part

    # New方法位于Part类对象中
    new_prt_file_tag = pyuf_part_instance.New(new_prt_file_name, units)
    return new_prt_file_tag

def pyuf_save_prt(the_pyuf_session):
    """
    功能:保存当前工作part
    """
    # 由于要对Part进行操作,因此需要获取Part实例对象
    pyuf_part_instance = the_pyuf_session.Part

    # Save方法位于Part类对象中
    return pyuf_part_instance.Save()

def pyuf_close_prt(the_pyuf_session, part_tag, scope, mode):
    """
    功能:关闭当前工作part
    """
    # 由于要对Part进行操作,因此需要获取Part实例对象
    pyuf_part_instance = the_pyuf_session.Part

    # Close方法位于Part类对象中
    return pyuf_part_instance.Close(part_tag, scope, mode)


def createPlane(the_pyuf_session, origin_point, plane_normal):
    """
    功能:python uf创建平面(无界面、非关联)
    origin_point-float list[x,y,z]:平面上某点坐标,plane_normal-float list[x,y,z]:平面法向向量
    返回值:平面特征tag标识
    """
    uf_modeling_instance = the_pyuf_session.Modeling
    return uf_modeling_instance.CreatePlane(origin_point, plane_normal)

def createFixedDplane(the_pyuf_session, point, direction):
    """
    功能:python uf创建固定基准平面
    point-float list[x,y,z]:平面上的一个点,direction-float list[x,y,z]:平面法线向量
    返回值:一个整数:固定基准平面特征tag标识
    """

    uf_modlfeatures_instance = the_pyuf_session.ModlFeatures
    return uf_modlfeatures_instance.CreateFixedDplane(point, direction)


if __name__ == '__main__':
    # 获取uf session
    the_pyuf_session = get_uf_session()

    # 获取python session
    the_py_session = get_py_session()

    # 新建prt文件路径与名称
    new_prt_file_name = 'D:\\pyuf_plane.prt'
    new_prt_file_tag = pyuf_new_prt(the_pyuf_session, new_prt_file_name)
	
	# 创建无界、非关联平面
    plane_feature_tag = createPlane(the_pyuf_session, [10.0, 10.0, 10.0], [0.5, 1.0, 0.0])
	# 创建固定基准面
    fixed_plane_feature_tag = createFixedDplane(the_pyuf_session, [0.0, 10.0, 10.0], [1.0, 1.0, 0.0])

    # 保存.prt
    pyuf_save_prt(the_pyuf_session)
    # 关闭.prt
    pyuf_close_prt(the_pyuf_session, new_prt_file_tag, 0, 1)

3.运行结果

3.1 内部模式

选中要运行的.py文件后,点击“管道通路”即可。
在这里插入图片描述

运行结果:
在这里插入图片描述

3.1.1 NXOpen.UF.Modeling.CreatePlane在NXUG界面上等价对话框

“菜单”->“插入”->“平面”
在这里插入图片描述
对话框界面
在这里插入图片描述

3.1.2 NXOpen.UF.ModlFeatures.CreateFixedDplane在NXUG界面上等价对话框

“主页”->“特征”->“基准平面”,下拉选择“点和方向”、非关联,若是勾选了“关联”则创建出来的“基准平面”不是“固定基准平面”
在这里插入图片描述

3.2 外部模式

cmd命令:“D:\Siemens\NX 12.0\NXBIN\run_journal.exe” pyuf_plane.py
powershell命令:&“D:\Siemens\NX 12.0\NXBIN\run_journal.exe” pyuf_plane.py

运行结果:同上

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值