[VBA]
我编有关旋转的程序运行不了,下面是我编的源程序,请高手指点.Sub addline1()<BR>Dim lineobj As AcadLine<BR>Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double<BR>pt1(0) = 1000: pt1(1) = 1000: pt1(2) = 0<BR>pt2(0) = 1200: pt1(1) = 1000: pt1(2) = 0<BR>Set lineobj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)<BR>End Sub<BR>Sub rotateline()<BR>Dim lineobj As AcadLine<BR>Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double<BR>pt1(0) = 1000: pt1(1) = 1000: pt1(2) = 0<BR>pt2(0) = 1200: pt1(1) = 1000: pt1(2) = 0<BR>Set lineobj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)<BR>ZoomAll<BR>Dim basepoint(0 To 2) As Double<BR>Dim rotationangle As Double<BR>dim angle as double<BR>basepoint(0) = pt1(0): basepoint(1) = pt1(1): basepoint(2) = pt1(2)<BR>rotationangle = ThisDrawing.Utility.GetAngle(, "指定角度")<BR>Angle = Angle *3.1415926/180<BR>tbangle = Round(angle, 2)<BR>rotationangle=tbangle<BR>linobj.Rotate basepoint, rotationangle<BR>lineobj.Update<BR>End Sub<BR> 第一个
pt2(0) = 1200: pt1(1) = 1000: pt1(2) = 0<BR>
看楼主的意思应该是
pt2(0) = 1200: pt2(1) = 1000: pt2(2) = 0<BR>
还有这个
rotationangle = ThisDrawing.Utility.GetAngle(, "指定角度")<BR>angle = angle * 3.1415926 / 180<BR>tbangle = Round(angle, 2)<BR>rotationangle = tbangle
后面三句删除。
getangle出来的是弧度,不需要转换了。
而且转换的也不对
还有
linobj.Rotate basepoint, rotationangle
应为
lineobj.Rotate basepoint, rotationangle
改正后可以运行
Sub rotateline()<BR>Dim lineobj As AcadLine<BR>Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double<BR>pt1(0) = 1000: pt1(1) = 1000: pt1(2) = 0<BR>pt2(0) = 1200: pt2(1) = 1000: pt2(2) = 0<BR>Set lineobj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)<BR>ZoomAll<BR>Dim basepoint(0 To 2) As Double<BR>Dim rotationangle As Double<BR>Dim angle As Double<BR>basepoint(0) = pt1(0): basepoint(1) = pt1(1): basepoint(2) = pt1(2)<BR>rotationangle = ThisDrawing.Utility.GetAngle(, "指定角度")<BR>'angle = angle * 3.1415926 / 180<BR>'tbangle = Round(angle, 2)<BR>'rotationangle = tbangle<BR>lineobj.Rotate basepoint, rotationangle<BR>lineobj.Update<BR>End Sub<BR>
建议,变量定义中应有大写字母,输入时只用小写输入,程序会自动把相应字母变成大写,这样可以知道变量是否输入错误,如lineobj最好定义成lineObj
页:
[1]