ANSYS Workbench二次开发–SpaceClaim Python脚本知识-实体对象的编辑(平移与旋转)

ANSYS Workbench二次开发–SpaceClaim Python脚本知识-实体对象的编辑(平移与旋转)

Please Share Us

点击此处查看 ✿水哥原创ANSYS视频教程清单 ✿

水哥专属答疑服务已开通,点此此处查看详情

本文为 WB二次开发 专篇的第 11 篇。专栏文章索引详见下文:

ANSYS WB二次开发专栏文章索引

查看移动大类的函数 Move ,使用频率最高的 Move.Translate以及Move.Rotate

一、对于平移而言:

1、首先要选择对象,如面、曲线、几何体等

2、指定方向,如果不是沿着坐标轴移动,可通过Direction.Create通过方向向量进行创建

3、通过控制MoveOptions的选项Copy值(True\False)来确定是否是平移复制,默认为False, 也即是移动

4、默认平移方向是以对象的几何中心作为参考点,但也可选择其他曲线作为移动轨迹

5、通过指定达到点来移动,这种方式通常情况下需要指定参考点,以及到达点,默认参考点为对象几何中心。

指定参考点可手动创建,也即通过位置坐标定义选择集,但是参考点一定要用Move.GetAnchorPoint进行定义。

# 平移 X 手柄

selection = BodySelection.Create(GetRootPart().Bodies[0])

direction = Direction.DirX

options = MoveOptions()

result = Move.Translate(selection, direction, MM(13.49), options)

# EndBlock

#按指定方向进行平移复制

# 平移 X 手柄

selection = BodySelection.Create(GetRootPart().Bodies[0])

direction = Direction.DirX

options = MoveOptions()

options.Copy=True

result = Move.Translate(selection, direction, MM(13.49), options)

# EndBlock

# 沿迹线移动—距离是通过输入与曲线长度的比例值来确定

selection = BodySelection.Create(GetRootPart().Bodies[0])

trajectory = EdgeSelection.Create(GetRootPart().Bodies[0].Edges[11])

options = MoveOptions()

result = Move.AlongTrajectory(selection, trajectory, 0.5, options)

# EndBlock

# 向上移动至所选对象

selection = BodySelection.Create(GetRootPart().Bodies[0])

upToSelection = Selection.Create(GetRootPart().Bodies[0].Edges[12].GetChildren[ICurvePoint]()[1])

anchorPoint = Move.GetAnchorPoint(Selection.Create(GetRootPart().Bodies[0].Edges[13].GetChildren[ICurvePoint]()[1]))

options = MoveOptions()

result = Move.UpTo(selection, upToSelection, anchorPoint, options)

# EndBlock

二、对于旋转而言:

操作思路:

通过选择几何体指定旋转中心

如果是指定的几何线,则直接通过GetAxis指定旋转轴

# 旋转 Z 手柄

selection = BodySelection.Create(GetRootPart().Bodies[0])

anchor = EdgeSelection.Create(GetRootPart().Bodies[0].Edges[11])

axis = Move.GetAxis(anchor)

options = MoveOptions()

result = Move.Rotate(selection, axis, DEG(89), options)

# EndBlock

选择一个面,然后获取该面的几何中心,创建旋转轴

# 旋转 Y 手柄

selection = BodySelection.Create(GetRootPart().Bodies[0])

anchor = FaceSelection.Create(GetRootPart().Bodies[0].Faces[6])

anchorPoint = Move.GetAnchorPoint(anchor)

axis = Line.Create(anchorPoint, Direction.DirY)

options = MoveOptions()

result = Move.Rotate(selection, axis, DEG(36), options)

# EndBlock

选择一个几何点,然后创建旋转轴

# 旋转 Y 手柄

selection = BodySelection.Create(GetRootPart().Bodies[0])

anchor = Selection.Create(GetRootPart().Bodies[0].Edges[13].GetChildren[ICurvePoint]()[1])

anchorPoint = Move.GetAnchorPoint(anchor)

axis = Line.Create(anchorPoint, Direction.DirY)

options = MoveOptions()

result = Move.Rotate(selection, axis, DEG(63), options)

创建一个三维点和旋转轴,适用于旋转的基点不在几何体本身上面

# Toggle 3D Sketch

# 创建一个三维点作为旋转的基点

Sketch3D.Set3DSketchMode(True)

P1=Point.Create(MM(50),MM(0),MM(0))

Re=SketchPoint.Create(P1)

Re=InteractionMode.Solid

Re=ViewHelper.SetViewMode(Re)

#选择基点和需要旋转的体

sel2=Selection.Create(GetRootPart().Curves[0])

sel1= BodySelection.Create(GetRootPart().Bodies[0])

anchorPoint = Move.GetAnchorPoint(sel2)

axis = Line.Create(anchorPoint, Direction.DirY)

options = MoveOptions()

result = Move.Rotate(sel1, axis, DEG(60), options)

#将options中的copy值设为true,则可利用循环创建类似阵列的效果

Options.Copy=True

for i in range(1,5):

   AA=60*i

   result = Move.Rotate(sel1, axis, DEG(AA), options)

#对创建的多余的三维点及时的删除

Re=Delete.Execute(sel2)

为更加方便大家系统学习WB脚本知识及软件二次开发流程,水哥特推出《基于Python脚本ANSYS Workbench 软件二次开发专题教程》,本教程分为6篇,分别为Python语言基础知识篇、SpaceClaim脚本知识篇、Mechanical脚本知识篇、Workbench项目管理脚本知识篇、项目脚本调试篇以及项目软件二次开发篇,本套课程总计约100课时,平均每个课时30~50分钟,全套课程总计约 70小时通过本教程,学员可系统性的掌握利用Python语言进行ansys workbench二次开发的相关技巧,课程详情请点击下方文章了解:

基于Python脚本ANSYS Workbench软件二次开发专题教程

欢迎扫描如下二维码关注本站微信公众号:ANSYS结构院

有时间麻烦帮忙点击下公众号文末的广告哦, 权当码字的辛苦费,感谢大家!

Please Share Us
© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码

    暂无评论内容

YOU MAY LIKE…