明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1950|回复: 2

求助:多段线的拟合问题 !!!!

[复制链接]
发表于 2006-3-28 23:37:00 | 显示全部楼层 |阅读模式

'怎样拟合下面程序建立的多段线

' 获得用户输入的宽度值
Public Function GetWidth() As Double
On Error Resume Next
Dim width As Double
width = ThisDrawing.Utility.GetReal("输入线宽:")
If err Then width = -1
GetWidth = width
End Function

' 获得用户输入的颜色索引值
Public Function GetColorIndex() As Integer
On Error Resume Next
Dim colorIndex As Integer
colorIndex = ThisDrawing.Utility.GetInteger("输入颜色索引值:")
If err Then
colorIndex = -1
End If

    GetColorIndex = colorIndex
    End Function

' 模拟创建多段线的过程
Public Sub CreatePolyline()
On Error Resume Next
Dim colorIndex As Integer       ' 多段线的颜色索引号
Dim width As Double             ' 多段线的线宽
colorIndex = 0
width = 0
Dim index As Integer            ' 当前输入点的次数
index = 2          ' 提示用户输入第一点
Dim pt1 As Variant
pt1 = ThisDrawing.Utility.GetPoint(, "输入第一点:")
If err Then
err.Clear
Exit Sub
End If

    Dim ptPrevious As Variant, ptCurrent As Variant         ' 拾取点过程中,存储上一点和当前点的变量
    ptPrevious = pt1          ' 定义有效的关键字
    Dim strKeyWords As String
    strKeyWords = "W C O"

NEXTPOINT:         ' 设置关键字
ThisDrawing.Utility.InitializeUserInput 128, strKeyWords
ptCurrent = ThisDrawing.Utility.GetPoint(ptPrevious, "输入下一点 [宽度(W)/颜色(C)]<完成(O)>:")
If err Then                 ' 在错误处理中判断用户输入的关键字
If StrComp(err.Description, "用户输入的是关键字", 1) = 0 Then
Dim strInput As String
strInput = ThisDrawing.Utility.GetInput
err.Clear                          ' 根据输入的关键字进行相应的处理
If StrComp(strInput, "W", vbTextCompare) = 0 Then                 ' 获得用户输入的宽度值
width = GetWidth
GoTo NEXTPOINT
ElseIf StrComp(strInput, "C", vbTextCompare) = 0 Then                 ' 获得用户输入的颜色索引值
colorIndex = GetColorIndex
GoTo NEXTPOINT
ElseIf StrComp(strInput, "O", vbTextCompare) = 0 Or Len(strInput) = 0 Then                 ' 完成多段线的创建

'ThisDrawing.SendCommand "_Pedit" & vbCr & "m" & vbCr & vbCr & "f" & vbCr & vbCr


Exit Sub
End If
Else
err.Clear
End If
End If
Dim objPLine As AcadLWPolyline
If index = 2 Then         ' 创建多段线
Dim points(0 To 3) As Double
points(0) = ptPrevious(0)
points(1) = ptPrevious(1)
points(2) = ptCurrent(0)
points(3) = ptCurrent(1)
Set objPLine = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
ElseIf index > 2 Then
Dim ptVert(0 To 1) As Double
ptVert(0) = ptCurrent(0)
ptVert(1) = ptCurrent(1)
objPLine.AddVertex index - 1, ptVert
End If          ' 修改多段线的线宽和颜色
If width <> -1 Then
objPLine.ConstantWidth = width
End If
If colorIndex <> -1 Then
Dim color As New AcadAcCmColor
color.colorIndex = colorIndex
objPLine.TrueColor = color
End If
index = index + 1
ptPrevious = ptCurrent

    GoTo NEXTPOINT

End Sub

发表于 2006-4-1 18:03:00 | 显示全部楼层
只能用SendCommand来完成。
发表于 2006-4-17 23:15:00 | 显示全部楼层

很好的.

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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