VBA getPoint和Lin帮助
好的,伙计们,除了Lisp,我还在使用VBA for Autocad。想象一下。我有一个带有1个文本框和2个按钮的表单(ok,cancel)。
当用户单击ok时,texBox中的数值存储在一个变量中,比如“a”。然后隐藏表单,用户在绘图空间内单击线条的起点-为此,我使用getpoint。然后,我在距离起点a(垂直方向)的距离处设置第二个点,并想要画一条线。我所做的有点像
Private Sub CommandButton1_Click()
'Declare the variable used for getting the info from the textBox
Dim ALength As Double
'Get the value from inside the textBox
ALength = CDbl(TextBox1.Text)
'Point declaration
Dim p0 As Variant
Dim p1 As Variant
'Hide the form
UserForm1.Hide
'Get point from user
p0 = ThisDrawing.Utility.GetPoint()
'Set second point
p1 = p0
p1(1) = p0(0) + ALength
'Draw the line
Dim p0p1Line As AcadLine
p0p1Line = ThisDrawing.Application.ActiveDocument.ModelSpace.AddLine(p0, p1)
End Sub
问题是,它不起作用。首先,我在getPoint方面有问题,但我认为我可以解决这些问题。第二,第二个点应该在Y轴上距离第一个点的长度处。这种情况不会发生。。如果p0(1)是50,长度是100,p1(1)应该是150,不是吗?在我的例子中是66或120或111.23。为什么?最后,当它到达p0p1Line=。。。。我得到一个错误(91),表示它的值为零,但如果单击“结束”,我仍然会在ACAD中绘制一条线。有什么帮助吗?
请注意将位移添加到p0点的坐标X。您的代码不应该改为:
'Set second point
p1 = p0
p1(1) = p(1) + ALength
此外,由于它与对象有关,因此应使用:
Set p0p1Line = ThisDrawing.Application.ActiveDocument.ModelSpace.AddLine(p0, p1)
当做
页:
[1]