Matt__W 发表于 2008-10-7 14:27:01

多段线是否仅适用于阵列?

所以我'我对编程思想不熟悉。本人'我用LISP做了一些项目,并自定义了我的托盘命令。但是现在我想花一些时间来理解如何做Autocad能够做的更详细的事情。所以我从一个简单的任务开始…,我想在图形中选择一个点
弹出一个表单,给我三个选项
上升、运行和立管数量
然后点击;“魔术”
命令按钮
然后Poof,它将创建一条多段线,看起来像楼梯
我想这将是一个简单的项目,让我开始,它有所有伟大的元素。我读了很多不同的教程,看到了许多不同的例子,也学到了很多其他项目是如何工作的。所以现在我'我卡住了。我知道在哪里申报。我知道如何添加模块。我知道如何创建表单,以及如何将表单的结果显示在模块中。如果一切都公开了,为什么这些价值观没有从一个模块传递到另一个模块
Dim absairs为双精度&nbsp 所有声明均在本图纸的页面顶部作出,Dim Bbstairs As Double
Dim Cbstairs As Double>Dim R As Integer
Dim X As Double
Dim Y As doublep
Dim ptstair As Variant
Dim p As Collection
Dim i As Integer
Public Sub stair()ptstair=thisdrawing.Utility。GetPoint(,“选择点”)
MsgBox ptstair(0)&amp&引用&引用&ptstair(1)&amp&引用&引用&ptstair(2)
absairs=ptstair(0)Cbstairs=ptstair(2)
R=StrOpt。textboxR=StrOpt。textboxXY=StrOpt。text方形;在使用之前,你必须先对一个集合执行此操作
 设置p=新集合;我们需要r*2+1分,因为我们先上去;这给了我们r条水平线 对于i=1到R*2+1&nbsp 这行告诉我们它是否#039;s奇数或偶数;i Mod 2=0意味着i是偶数&nbsp (i除以2得到0的余数)&nbsp&nbsp 如果i Mod 2=0,则&nbsp&nbsp&nbsp&nbsp p、 添加;(“Abstrairs+X*(i-2)/2&amp&quot&引用&Bbstairs+Y*i/2&amp&quot&引用&Cbstairs&amp")&引用
&nbsp&nbsp 其他&nbsp&nbsp&nbsp&nbsp p、 添加;(“Abstrairs+X*(i-1)/2&amp&quot&引用&Bbstairs+Y*(i-1)/2&amp&quot&引用&Cbstairs&amp")&引用
&nbsp&nbsp 结束If&039;这只是将变量输出到电子表格,以便您可以检查它;你可能
&039 韩元#039;无法在AutoCAD中执行此操作;这是循环的结束;它告诉我增加1 下一个iMsgBox p(1)&p(2)&nbsp 此消息框显示p的值,但它不参考先前选择的点
我尝试了不同的语法,让addpolyline从集合中查找p的值,并将其用于应包含在多段线中的点。我在想,在这个庄园中,只有数组可以用于多段线。但不确定
如果有更好的方法,请结束Sub;我愿意接受新的方向。这是对我来说最有意义的一个。我遇到了这么多的路障,很明显我有这么多的家庭作业要做。也许有一天,我会变得足够熟悉,转而使用acad.net。那太好了
谢谢大家。

Matt__W 发表于 2008-10-7 14:55:10

首先……欢迎来到沼泽。其次……它对我很有用&nbsp
我唯一要更改的是将DIM设置为PUBLIC,因为您希望将这些变量提供给其他模块
现有代码…
Dim Abstairs As Double
Dim Bbstairs As Double
Dim Cbstairs As Double
Dim R As Integer
Dim X As Double
Dim Y As Double
Dim ptstair As Variant
Dim p As Collection
Dim i As Integer
更改的代码…
Public Abstairs As Double
Public Bbstairs As Double
Public Cbstairs As Double
Public R As Integer
Public X As Double
Public Y As Double
Public ptstair As Variant
Public p As Collection
Public i As Integer 哦,我总是使用Option Explicit,这意味着所有变量都必须声明。

Cathy 发表于 2008-10-7 16:10:05

我喜欢做的一件事是把我的公共变量移到一个代码模块(这个绘图在技术上是一个类模块)顺便说一句,这是一个'新家伙&#039。。。。。欢迎

Bryco 发表于 2008-10-7 16:12:49


这里也一样……想想吧……我可以'我不记得上一次我在这个绘图中有任何代码(除了一个早已消亡的旧ACAD.dvb文件)。

Cathy 发表于 2008-10-7 17:42:49


我认为你是对的 AddPolyline方法需要一个数组&nbsp VBA帮助还不错,应该有示例 数组需要声明为双精度(实数) 看起来您的集合是字符串的集合(其中包含数字的文本字符串看起来非常模糊)&nbsp 你'我有一个很好的开始,大部分工作都做得很好&nbsp

Cathy 发表于 2008-10-8 10:20:49

谢谢大家的好意;我会让你了解最终代码的最新信息。

Bryco 发表于 2008-10-8 16:06:34

到目前为止进展顺利。可以直到现在。谁能指出我的逻辑哪里错了,或者我的语法哪里坏了
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
我知道我可以得到一个点并提取这三个变体。我该怎么做呢。使用三个数字并使其成为单个变量的变体
谢谢大家

Matt__W 发表于 2008-10-8 17:29:11

我不知道'我在这里没有太多时间,但你知道在运行时有多少分
Dim pts()
Dim totalpts as integer
totalpts=x
redim pts(totalpts-1)
现在在您的循环中
pts(i*3)=:pts(i*3+1)=etc我只使用lwpline,因此数学与重样条不同

Cathy 发表于 2008-10-8 18:08:47

布莱科's的建议看起来不错 我会去掉这个集合,只使用点的redim数组 It#039;因为AddPolyline方法没有#039;t实际上使用点——它使用一个包含xyzxyzxyzxyz值的数组 对于重多段线,PT应为双精度
其中RR是多段线中的顶点数-1是因为出于某种荒谬的原因,VB开始从0开始计数;数组最终应包含(对于9个顶点)
pts(0)=x1pts(5)=z2。
pts(24)=x9=25)=y9<pts(26)=z9因此在循环中i=1到RR(笑声),当你有PLP(0)=plp00:PLP(1)=PLP0.1:PLP.2)=PLP.02时,你可以改变(或添加)点((i-1)*3)=plp00:点((i-1)*3+1)=PLP0.01:点((i-1))*3+2)=PLp0.02,因为你的z总是一样的,你可以考虑使用轻量级多段线——它们使用更少的空间
页: [1]
查看完整版本: 多段线是否仅适用于阵列?