多段线只适用于数组吗?
所以我是编程的新手。我在LISP中做过项目,并定制了我的托盘命令份额。但是现在我想花一些时间来了解如何做Autocad能够做的更详细的事情。所以我从简单的任务开始...我想在绘图中选择一个点。
弹出一个表单,并为我提供三个选项。
上升、运行和上升数量。
然后单击“魔法”
命令按钮。
噗,它将创建一个多段线,看起来像楼梯。
我想这将是一个让我开始的简单项目,它包含所有很棒的元素。我读过许多不同的教程,看过许多不同的例子,并且了解了很多其他项目是如何工作的。所以现在我卡住了。我知道在哪里发表声明。我知道如何添加模块。我知道如何创建表单以及如何将表单的结果显示在模块中。如果一切都公开了,为什么这些值不能从一个模块传递到另一个模块?
所有声明都在本图的页面顶部进行
Dim Bb楼梯As Double
Dim Cb楼梯As Double
Dim R As Intger
Dim X As Double
Dim Y As Double
Dim ptstair As Variant
Dim p As Collection
Dim i As Intger
Public Sub stair()
ptstair=ThisDrawing.Utility.GetPoint(,"Select a point")
MsgBox ptstair(0) & ";" & ptstair(1) & ";" & ptstair(2)
Abstair=ptstair(0)
Bbstair=ptstair(1)
Cbstair=ptstair(2)
MsgBox Abstair&Bbstair&Cbstair
StrOpt.Show
='这是我的form.EndSub
在表单中的选项之后的名称输入并按下魔法按钮...它应该开始这个模块
Public Sub makestair()
MsgBox Ab楼梯 & ";" & Bb楼梯 & ";" & 每次出现这个消息框,值都是空白的。
R=StrOpt.textboxR
X=StrOpt.textboxX
Y=StrOpt.textboxY
'在使用集合之前,您总是必须对集合执行此操作。
设置p=新集合
'我们需要r*2+1点,因为我们先上去;这给我们r水平线
对于i=1到R*2+1
'这一行告诉我们它是奇数还是偶数;i Mod 2=0表示i是即使
'(i除以2得到0的余数)
如果i Mod 2=0,那么
p.Add "(" & Ab楼梯+X*(i-2)/2 & "," & Bb楼梯+Y*i/2 & "," & Cb楼梯 & ")"
其他
p.Add "(" & Ab楼梯+X*(i-1)/2 & "," & Bb楼梯+Y*(i-1)/2 & "," & Cb楼梯 & ")"
结束如果
'这只是将变量输出到电子表格,以便您可以检查它;您可能
'将无法在AutoCAD
'这是循环的结尾;它告诉i增加1
下一个i
MsgBox p(1)&p(2)此消息框显示p的值,但它不引用之前选择的点。
我尝试了不同的语法来让addmultiline从集合中查找p的值并将它们用于应该包含在多段线中的点。我在想这个庄园中只能使用数组来进行多段线。但不确定。
结束子
如果有更好的方法来做到这一点,我愿意接受新的方向。这是对我最有意义的一个。我遇到了这么多路障,这变得越来越明显,以至于我有这么多的家庭作业要做。然后也许有一天我会变得足够熟悉,可以继续acad.net.那太好了。
谢谢大家。
**** Hidden Message ***** 首先...欢迎来到沼泽。
其次...它对我有用。
我唯一要更改的是DIM到PUBLIC,因为您希望将这些变量提供给其他模块。
现有代码...
更改的代码...
哦,我总是使用Option Explute,这意味着必须声明所有变量。 我*喜欢*做的一件事是将我的公共变量移动到一个代码模块(从技术上讲,这个绘图是一个类模块)
顺便说一句,对于一个“新人”来说,这是一些漂亮的代码……欢迎!
这里也是一样……想想看……我不记得这幅画里最后一次有代码是什么时候了(除了一个早已消失的旧ACAD.dvb文件)。
我认为你是对的。 方法需要一个数组。VBA 帮助不是太糟糕,应该有示例。 数组需要声明为双精度(实数)。 看起来您的集合是字符串的集合(其中带有数字的文本字符串恰好看起来非常随意)。你已经有了一个非常好的开始,让它的大部分工作都很好!
感谢大家的411。我会让您了解最新的最终代码。 到目前为止,一切都很顺利。有人可以指出我的逻辑在哪里是错误的,或者我的语法在哪里变坏了。
Option Explicit
Dim pt As Variant
Public Ab0 As Double
Public Bb0 As Double
Public Cb0 As Double
Public abc As Double
Public R As Integer
Public X As Double
Public Y As Double
Dim ptstair As Variant
Dim p As Variant
Dim i As Integer
Dim RR
Dim PLP(0 To 2) As Double
Dim plpoints
Dim plp00 As Double
Dim plp01 As Double
Dim plp02 As Double
Public Sub SelPoint()
pt = ThisDrawing.Utility.GetPoint(, "Select Point:")
MsgBox pt(0) & ";" & pt(1) & ";" & pt(2)
Ab0 = pt(0)
Bb0 = pt(1)
Cb0 = pt(2)
StrOpt.Show 'this calls the form StrOpt. Where I input the values for the rise, run, and number of risers.
End Sub
Public Sub makestair()
R = StrOpt.textboxR 'This is the number of risers
X = StrOpt.textboxX 'This is the Run of the riser
Y = StrOpt.textboxY 'This is the Rise of the riser
RR = (R * 2) + 1 ' This is the number of times the step needs to repeat. 4 Risers will require
'9 points in the polyline
' You always have to do this with a collection before you can use it.
Set p = New Collection
' i is equal to integers 1 thru RR,(number of points needed for polyline)
For i = 1 To RR Step 1
If i Mod 2 = 0 Then 'if i divided by 2 has a remainder of 0, an even number, then I would
'like for the following formula.
plp00 = Ab0 + X * ((i - 2) / 2)
plp01 = Bb0 + Y * (i / 2)
plp02 = Cb0
MsgBox plp00 & plp01 & plp02
PLP(0) = plp00: PLP(1) = plp01: PLP(2) = plp02 ' here is where I would like to take the three values and
'and turn them back into a variant that will be used in the
' add polyline command.
p.Add (PLP())
Else 'if i divided by 2 hasa remainder not equal to 0, odd number, then I
'would like the following formula.
plp00 = Ab0 + X * ((i - 1) / 2)
plp01 = Bb0 + Y * ((i - 1) / 2)
plp02 = Cb0
MsgBox plp00 & plp01 & plp02
PLP(0) = plp00: PLP(1) = plp01: PLP(2) = plp02
p.Add (PLP())
End If
Next i
' now I should have a collection of items that are variants.
plpoints = p.Item(PLP(4))
MsgBox plpoints
End Sub
我知道我可以得到一个点并提取三个变体。我该怎么做才能反其道而行之。使用三个数字并使其成为单个变量的变体?
谢谢大家 我在这里没有太多时间,但您知道在运行时有多少点。
dim ts()
dim汇总为整数
汇总=x
重新设置(汇总-1)
现在在您的循环中
ts(i*3)=: ts(i*3+1)=etc
我只会使用lwplines,因此数学与重的不同
Bryco的建议看起来不错。 我会摆脱集合,只使用一个redim点数组。 这令人困惑,因为 AddPolyline 方法实际上并不使用点 - 它使用包含 xyzxyz 值的数组。 对于重折线,pts 应该是
redim pts(RR*3-1) 作为双精度
值,其中 RR 是折线中的顶点数。 您的数组最终应包含(对于 9 个顶点)
pts(0) = x1
pts(1) = y1
pts(2) = z1
pts(3) = x2
pts(4) = y2
pts(5) = z2
...
pts(24) = x9
pts(25) = y9
pts(26) = z9
所以在你的循环中 i = 1 到 RR,其中你有
PLP(0) = plp00: PLP(1) = plp01: PLP(2) = plp02
你可以改变 (或 add)
pts((i-1)*3) = plp00: pts((i-1)*3+1) = plp01: pts((i-1)*3+2) = plp02
由于你的 z 总是一样的, 你可以考虑使用轻量级的折线 - 它们使用更少的空间。
页:
[1]