Siemens-NXUG二次开发-创建倒斜角特征、边倒圆角特征、设置对象颜色、获取面信息[Python UF][20240605]
1.python uf函数
1.1 NXOpen.UF.Modeling.AskFaceData
# 内部和外部模式可用
"""
返回值:一个元组,元素类型为python的int类型,块特征的feature tag标识。
"""
def NXOpen.UF.Modeling.AskFaceData(self, face_tag)
'''
face_tag:面的tag标识
[返回值]一个元组 (type-int,
face point-list of float,
dir-list of float,
Face boundary-list of float,
Face major radius-float,
Face minor radius-float,
Face normal direction-int)
其中元组0位置:
cylinder-16、cone-17 、sphere-18 、revolved (toroidal)-19
extruded-20 、bounded plane-22 、fillet (blend)-23 、b-surface-43
offset surface-65 、foreign surface-66、Convergent surface-67
'''
1.2 NXOpen.UF.Modeling.CreateChamfer
# 内部和外部模式可用
"""
返回值:一个tag,倒斜角特征tag。
"""
def NXOpen.UF.Modeling.CreateChamfer(self, subtype, offset1, offset2, theta, edges)
'''
subtype-int:1-单向偏置、2-双向偏置、3-偏置和角度、4-自由单向偏置、5-自由双向偏置,
offset1-str:偏置值1,
offset2-str:偏置值2,
theta-str:倒斜角角度值,
edges-int list:要倒斜角实体边的tag列表
[返回值]一个整数,倒角特征tag标识
'''
1.3 NXOpen.UF.ModlFeatures.CreateBlend
# 内部和外部模式可用
"""
返回值:一个tag,倒圆角特征tag。
"""
def NXOpen.UF.ModlFeatures.CreateBlend(self, radius, edge_list, smooth_overflow, cliff_overflow, notch_overflow, vrb_tool)
'''
radius-str:倒圆角半径,
edge_list-int list:要倒圆角实体边的tag列表,
smooth_overflow-int:倒圆角平滑溢出值、0-允许这种类型倒圆、1-防止这种类型倒圆,
cliff_overflow-int:倒圆角峭壁溢出值、0-允许这种类型倒圆、1-防止这种类型倒圆,
notch_overflow-int:倒圆角凹槽溢出值、0-允许这种类型倒圆、1-防止这种类型倒圆,
vrb_tool-float:倒圆角公差
[返回值]一个整数,倒圆角特征tag标识
'''
1.4 NXOpen.UF.Obj.SetColor
# 内部和外部模式可用
"""
返回值:一个整数,0-成功执行,非零正整数-错误大代码。
"""
def NXOpen.UF.Obj.SetColor(self, object_tag, color_id)
'''
object_tag:正整数,对象tag标识
color_id:正整数-颜色号
'''
2.实体目标面边识别
2.1 识别平行于Z轴的竖直边(倒圆角)
- 从块特征tag获取该特征所属的实体tag
- 从实体tag获取所有的边tag
- 循环边tag,判断其所在向量是否平行于Z轴,即找到Z竖直边
识别开始时,当前3D实体状态:
识别完成后,倒圆角操作后,当前3D实体状态:
2.1 识别垂直于Z轴的平面(倒斜角)
- 从块特征tag获取该特征所属的实体tag
- 从实体tag获取所有的面tag
- 循环面tag,判断是否是平面且法线平行于Z轴,即平面垂直于Z轴,找到竖直边倒圆角后实体的上下两个平面
识别开始时,当前3D实体状态:
识别完成后,倒斜角操作后,当前3D实体状态:
3.示例代码
3.1 pyuf_chamfer_blend.py
import NXOpen
import NXOpen.UF as UF
import math
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