明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1627|回复: 1

[VBA]

[复制链接]
发表于 2005-6-5 22:16:00 | 显示全部楼层 |阅读模式
我编有关旋转的程序运行不了,下面是我编的源程序,请高手指点. Sub addline1()
Dim lineobj As AcadLine
Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double
pt1(0) = 1000: pt1(1) = 1000: pt1(2) = 0
pt2(0) = 1200: pt1(1) = 1000: pt1(2) = 0
Set lineobj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
End Sub
Sub rotateline()
Dim lineobj As AcadLine
Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double
pt1(0) = 1000: pt1(1) = 1000: pt1(2) = 0
pt2(0) = 1200: pt1(1) = 1000: pt1(2) = 0
Set lineobj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
ZoomAll
Dim basepoint(0 To 2) As Double
Dim rotationangle As Double
dim angle as double
basepoint(0) = pt1(0): basepoint(1) = pt1(1): basepoint(2) = pt1(2)
rotationangle = ThisDrawing.Utility.GetAngle(, "指定角度")
Angle = Angle *3.1415926/180
tbangle = Round(angle, 2)
rotationangle=tbangle
linobj.Rotate basepoint, rotationangle
lineobj.Update
End Sub
发表于 2005-6-5 22:50:00 | 显示全部楼层
第一个 pt2(0) = 1200: pt1(1) = 1000: pt1(2) = 0
看楼主的意思应该是 pt2(0) = 1200: pt2(1) = 1000: pt2(2) = 0
还有这个 rotationangle = ThisDrawing.Utility.GetAngle(, "指定角度")
angle = angle * 3.1415926 / 180
tbangle = Round(angle, 2)
rotationangle = tbangle 后面三句删除。 getangle出来的是弧度,不需要转换了。 而且转换的也不对 还有 linobj.Rotate basepoint, rotationangle 应为 lineobj.Rotate basepoint, rotationangle 改正后可以运行 Sub rotateline()
Dim lineobj As AcadLine
Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double
pt1(0) = 1000: pt1(1) = 1000: pt1(2) = 0
pt2(0) = 1200: pt2(1) = 1000: pt2(2) = 0
Set lineobj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
ZoomAll
Dim basepoint(0 To 2) As Double
Dim rotationangle As Double
Dim angle As Double
basepoint(0) = pt1(0): basepoint(1) = pt1(1): basepoint(2) = pt1(2)
rotationangle = ThisDrawing.Utility.GetAngle(, "指定角度")
'angle = angle * 3.1415926 / 180
'tbangle = Round(angle, 2)
'rotationangle = tbangle
lineobj.Rotate basepoint, rotationangle
lineobj.Update
End Sub
建议,变量定义中应有大写字母,输入时只用小写输入,程序会自动把相应字母变成大写,这样可以知道变量是否输入错误,如lineobj最好定义成lineObj
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 15:41 , Processed in 0.148368 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表