明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1405|回复: 1

为什么在以下情况不能够画线?请各位指教!

[复制链接]
发表于 2005-5-12 12:43:00 | 显示全部楼层 |阅读模式
Private Sub ChOrDPath3_Click()
Form1.Hide On Error Resume Next
Dim objlayer As AcadLayer If IsNull(ThisDrawing.Layers.Item("ExtrudePath")) Then
Set objlayer = ThisDrawing.Layers.Add("ExtrudePath")
ThisDrawing.ActiveLayer = objlayer Else
For Each objlayer In ThisDrawing.Layers
If objlayer.Name = "ExtrudePath" Then
ThisDrawing.ActiveLayer = objlayer
Exit For
End If
Next
End If Dim sset As AcadSelectionSet
Dim i As Integer
i = ThisDrawing.SelectionSets.Count While (i > 0)
Set sset = ThisDrawing.SelectionSets.Item(i - 1)
If sset.Name = "3dPLine" Then
sset.Delete
End If
i = i - 1
Wend
Set sset = ThisDrawing.SelectionSets.Add("3dPLine") Dim gpcode(1) As Integer
Dim datavalue(1) As Variant
gpcode(0) = 0
datavalue(0) = "PolyLine"
gpcode(1) = 8
datavalue(1) = "ExtrudePath" Dim objline As Acad3DPolyline Dim topoint1(0 To 2) As Variant
topoint1(0) = Val(Form2.XPoint.Text)
topoint1(1) = Val(Form2.YPoint.Text)
topoint1(2) = Val(Form2.ZPoint.Text) sset.Select acSelectionSetAll, , , gpcode, datavalue
If sset.Count > 1 Then
MsgBox "满足条件的拉伸路径存在多条,请选择一条!"
sset.Clear
sset.SelectOnScreen gpcode, datavalue
Set objline = sset.Item(0) objline.Move objline.Coordinate(0), topoint1
Else
If sset.Count = 1 Then
Set objline = sset.Item(0)
objline.Move objline.Coordinate(0), topoint1
Else
For Each objlayer In ThisDrawing.Layers
If objlayer.Name = "ExtrudePath" Then
ThisDrawing.ActiveLayer = objlayer
End If
Exit For
Next
On Error GoTo ErrHandle
Dim p2 As Variant
p2 = ThisDrawing.Utility.GetPoint(, vbCr & "请输入下一点:")
Dim pnt(5) As Double
pnt(0) = Val(Form2.XPoint.Text): pnt(1) = Val(Form2.YPoint.Text): pnt(2) = Val(Form2.ZPoint.Text)
pnt(3) = p2(0): pnt(4) = p2(1): pnt(5) = p2(2) Set objline = ThisDrawing.ModelSpace.Add3DPoly(pnt)
Do While True
p2 = ThisDrawing.Utility.GetPoint(p2, vbCr & "请输入下一点:")
objline.AppendVertex p2
Loop
ErrHandle:
End If
End If (以上代码实现了“如果层ExtrudePath里面有超过一条3维多段线时,要求用户确定其中一条作为拉伸路径;如果恰好有条的话就自动作为拉伸路径;如果没有的话,就要求用户绘制一条3维多段线作为拉伸路径“。接下来的代码是为了获得当前三维多段线的相关参数,另外画一条三维多段线。可为什么运行的时候总是说过程无效?line1为空值) Dim endpoint1(0 To 5) As Variant
Dim coord1 As Variant
Dim coord2 As Variant
coord1 = objline.Coordinate(1)
coord2 = objline.Coordinate(0)
Dim line1 As Acad3DPolyline
endpoint1(0) = 0: endpoint1(1) = coord1(1): endpoint1(2) = coord2(2)
endpoint1(3) = coord1(0): endpoint1(4) = coord1(1): endpoint1(5) = coord1(2)
Set line1 = ThisDrawing.ModelSpace.Add3DPoly(endpoint1)
End Sub
发表于 2005-5-12 14:16:00 | 显示全部楼层
把程序注释一下吧,让大家很快能明白你的意思。


整段代码没有一句注释,大家读起来就要费很多时间,所以说老实话,很难有人耐心看完你的代码。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-27 16:34 , Processed in 0.158961 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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