常用spaceclaim脚本(二)

#创建一个草图

#第一个参数传入一个Frame对象

#通过一个点和两个向量创建Frame

#Frame的类成员函数Create被重载

#重载函数1Frame.Create(Point, Direction)

#第一个参数为一个点

#第二个参数为面法向向量

#重载函数2Frame. Create(Point, Direction, Direction)

#第一个参数为面上的一个点

#第二个和第三个参数为面上的向量

 

#调用ViewHelper.SetSketchPlane函数在选中对象的基础上创建一个草图

#该函数也重载了两个函数

#重载函数1SetSketchPlane(ISelection)

#参数为一个Selection的对象

#重载函数2SetSketchPlane(Plane, ScriptObject)

#第一个参数为前面创建的平面

#第二个参数为可选参数,默认为null

 

#返回一个SetViewModeCommandResult对象

 

plane = Plane.Create(Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 0, 1), Direction.Create(1, 0, 0)))

result = ViewHelper.SetSketchPlane(plane)

 

#旋转草图

rotationAxis = Line.Create(

   Point.Create(MM(0), MM(0), MM(0)),

   Direction.Create(1, 0, 0)) #定义旋转轴

matrix = Matrix.Identity #定义一个矩阵

matrix = matrix * Matrix.CreateRotation(rotationAxis, DEG(90)) #创建一个旋转矩阵

ViewHelper.TransformSketchPlane(matrix) #将草图旋转一个角度

 

#平移草图

plane = Plane.Create(Frame.Create(Point.Create(MM(0), MM(20), MM(0)), Direction.Create(0, 0, 1), Direction.Create(1, 0, 0)))

result = ViewHelper.SetSketchPlane(plane)

matrix = Matrix.Identity

matrix = matrix * Matrix.CreateTranslation(Vector.Create(MM(0), MM(20), MM(0)))

ViewHelper.TransformSketchPlane(matrix)

 

#草图转换为三维模式

#转换函数重载了两个函数

#重载函数1 ViewHelper.SetViewMode(InteractionMode, IScriptObject)

#第一个参数为交互模式,分别为草图模式,剖面模式,三维模式

#第二个参数为可选参数,附加参数,默认值为null

#重载函数2ViewHelper.SetViewMode(InteractionMode, Plane, IScriptObject)

#第一个参数为交互模式,分别为草图模式,剖面模式,三维模式

#第二个参数为草图平面

#第三个参数为可选参数,附加参数,默认值为null

 

#返回值为一个SetViewModeCommandResult对象

交互模式可选参数

名称

描述

Sketch

0

草图模式

Section

1

剖面模式

Solid

2

三维模式

 

result = ViewHelper.SetViewMode(InteractionMode.Solid)

 

#草图当中创建一条直线

#创建直线函数重载了三个函数

#重载函数1SketchLine.Create(Point2D, Point2D)

#第一个参数为直线的起点

#第二个参数为直线的终点,起点和终点的坐标皆为激活平面上的二维坐标

#重载函数2SketchLine. Create(Point, Point, Plane)

#第一个参数为起点坐标

#第二个参数为终点坐标

#第三个参数为可选参数,默认为null,即当前草图

 

#返回一个SketchCurveResult对象

 

重载函数1示例:

frame= Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0))

plane= Plane.Create(frame)

ViewHelper.SetSketchPlane(plane)

start = Point2D.Create(MM(-8), MM(17))

end = Point2D.Create(MM(-8), MM(-21))

result = SketchLine.Create(start, end)

 

重载函数2示例:

start = Point.Create(MM(-8), MM(17),MM(0))

end = Point.Create(MM(-8), MM(-21) ,MM(0))

result = SketchLine.Create(start, end)

 

#草图当中创建一个矩形

#创建矩形的函数重载了三个函数

#重载函数1SketchRectangle. Create(Point, Point, Point)

#三个参数分别为矩形的三个角上的坐标,从而确定矩形

#重载函数2SketchRectangle.Create(Point2D, Point2D, Point2D)

#三个参数为矩形的三个角上的坐标,但这个坐标为当前激活平面上的二维坐标

#重载函数3SketchRectangle. Create(IRectangle)

#参数为IRectangle对象

 

#返回一个SketchCurveResult对象

 

重载函数1示例:

point1 = Point.Create(MM(15),MM(-15),MM(0))

point2 = Point.Create(MM(-15),MM(-15),MM(0))

point3 = Point.Create(MM(-15),MM(15),MM(0))

result = SketchRectangle.Create(point1, point2, point3)

 

重载函数2示例:

plane = Plane.Create(Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0)))

result = ViewHelper.SetSketchPlane(plane)

point1 = Point2D.Create(MM(15),MM(-15))

point2 = Point2D.Create(MM(-15),MM(-15))

point3 = Point2D.Create(MM(-15),MM(15))

result = SketchRectangle.Create(point1, point2, point3)

 

#草图当中创建一个圆形

#创建矩形的函数重载了三个函数

#重载函数1SketchCircle.Create(Point2D, Double)

#第一个参数为圆心坐标,该坐标位于当前激活的平面上

#第二个参数为半径

#重载函数2SketchCircle. Create(Point, Double, Plane)

#第一个参数为圆心

#第二个参数为半径

#第三个参数为可选参数,用来指定圆所在平面,默认为null,为当前平面

#重载函数3SketchCircle.Create(Circle, Plane)

#第一个参数为Circle对象

#第二个参数为可选参数,用来指定圆所在平面,默认为null,为当前平面

 

#返回一个SketchCurveResult对象

 

重载函数1示例:

plane = Plane.Create(Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0)))

result = ViewHelper.SetSketchPlane(plane)

circlepoint= Point2D.Create(MM(0),MM(0))

SketchCircle.Create(circlepoint, MM(10))

 

重载函数2示例:

plane = Plane.Create(Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0)))

result = ViewHelper.SetSketchPlane(plane)

circlepoint= Point.Create(MM(0),MM(0),MM(0))

SketchCircle.Create(circlepoint, MM(10),plane)

 

重载函数3示例:

frame= Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0))

plane= Plane.Create(frame)

radius= MM(10)

circle= Circle.Create(frame,radius)

SketchCircle.Create(circle,plane)

 

#草图当中创建一个多边形

#只有一个参数,用Polygon对象在草图上创建一个多边形

#返回一个SketchCurveResult对象

frame= Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0))

innerRadius = MM(18) #内接圆的半径

numSides = 6 #多边形的边数

#创建一个多边形的对象

polygon = Polygon.Create(frame, innerRadius, numSides)

result = SketchPolygon.Create(polygon)

 

#草图当中创建一段圆弧

#创建圆弧的函数重载了三个函数

#重载函数1SketchArc.Create(Point, Point, Point)

#第一个参数是圆弧的圆心坐标

#第二个参数是圆弧的起点坐标

#第三个参数是圆弧的终点坐标

#重载函数2SketchArc.Create(Point2D, Point2D, Point2D)

#三个参数与上面同,但这个坐标为当前激活平面上的二维坐标

#重载函数3SketchArc.Create(Circle, Interval)

#第一个参数为Circle的对象

#第二个参数为Interval的对象

 

#返回一个SketchCurveResult对象

 

重载函数1示例:

origin = Point.Create(MM(0), MM(0), MM(0))

start = Point.Create(MM(15), MM(0), MM(0))

end = Point.Create(MM(0), MM(15), MM(0))

SketchArc.Create(origin, start, end)

 

重载函数2示例:

frame= Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0))

plane= Plane.Create(frame)

ViewHelper.SetSketchPlane(plane)

origin = Point2D.Create(MM(0), MM(0))

start = Point2D.Create(MM(15), MM(0))

end = Point2D.Create(MM(0), MM(15))

result = SketchArc.Create(origin, start, end)

 

#草图当中创建样条曲线

#第一个参数设置样条曲线是否是周期性,也就是样条曲线是否闭合

#第二个参数传入一个点坐标的列表

#返回一个SketchCurveResult的对象

frame= Frame.Create(Point.Create(MM(0), MM(0), MM(0)), Direction.Create(0, 1, 0), Direction.Create(1, 0, 0))

plane= Plane.Create(frame)

ViewHelper.SetSketchPlane(plane)

points = List[Point2D]()

points.Add(Point2D.Create(MM(-17), MM(-14)))

points.Add(Point2D.Create(MM(-1), MM(-7)))

points.Add(Point2D.Create(MM(6), MM(11)))

points.Add(Point2D.Create(MM(23), MM(19)))

points.Add(Point2D.Create(MM(29), MM(27)))

result = SketchNurbs.CreateFrom2DPoints(False, points) 

 

#移动一个选中的对象

#MM表示的是以毫米作为单位

#该函数共有三个重载函数

#重载函数1Move.Execute(ISelection, Vector, MoveOptions)

#第一个参数为选中的对象,可通过Selection.GetActive()获取

#第二个参数为移动的向量

#第三个参数为移动选项

#重载函数2Move.Execute(ISelection, Frame, TransformType, Vector, MoveOptions)

#第一个参数为选中的对象,可通过Selection.GetActive()获取

#第二个为框架坐标系

#第三个为移动的类型

#第四个参数为移动的向量

#第五个为移动的选项

#重载函数3Move.Execute(ISelection, Frame, TransformType, Double, MoveOptions)

#第一个参数为选中的对象,可通过Selection.GetActive()获取

#第二个为框架坐标系

#第三个为移动的类型

#第四个参数为移动距离

#第五个为移动的选项

#返回的是一个MoveResult的对象

注:

TransformType参数的取值如下:

名称

描述

TranslateX

0

沿x轴移动

TranslateY

1

沿y轴移动

TranslateZ

2

沿z轴移动

RotateX

3

x轴旋转

RotateY

4

y轴旋转

RotateZ

5

z轴旋转

TranslateXY

6

沿xy平面移动

TranslateXZ

7

沿xz平面移动

TranslateYZ

8

沿yz平面移动

 

重载函数1

Move.Execute(Selection.GetActive(),Vector.Create(MM(40),MM(0),MM(0)), MoveOptions())

 

重载函数2

Move.Execute(Selection.GetActive(), Frame.World, TransformType.TranslateX, Vector.Create(MM(40),MM(0),MM(0)), MoveOptions())

 

重载函数3

Move.Execute(Selection.GetActive(), Frame.World, TransformType.TranslateX, MM(40), MoveOptions())

#填充一个选中的对象

#第一个参数为填充的对象

#第二个参数为可选参数,默认值为null

#第三个参数为可选参数,填充选项,默认值为null

#第四个参数为可选参数,填充模式,默认值为null

#第五个参数为可选参数,默认值为null

#返回一个CommandResult的对象

第四个参数的取值如下:

名称

描述

Sketch

0

Sketch mode

Section

1

Section mode

Layout

2

Layout mode

ThreeD

3

3D mode

 

result = Fill.Execute(Selection.GetActive()) 

 

转载于:https://www.cnblogs.com/liusuanyatong/p/11259686.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值