本帖最后由 yshf 于 2013-7-22 22:49 编辑
试用以下函数(注意:在VB中则将ThisDrawing修改为acadapp.ActiveDocument):- Public Function AddPline(Col)
- '画多段线,并返回其长度
- Dim p1 As Variant
- Dim p2 As Variant
- Dim n As Integer
- Dim m As Integer
- Dim pt() As Double
- Dim Ent As AcadLWPolyline '在VB中改为 Dim Ent As Object
- Dim Pdbz As Boolean
- Dim Fhz
-
- On Error Resume Next
-
- p1 = ThisDrawing.Utility.GetPoint(, vbCrLf + "第1点:")
- p2 = ThisDrawing.Utility.GetPoint(p1, vbCrLf & "下一点<或结束>:")
-
- If TypeName(p2) = "Empty" Then
- 'MsgBox "只有输入一点,不能画多段线"
- Fhz = "只有输入一点,不能画多段线"
- Else
- n = 2: m = 2 * n - 1
- ReDim Preserve pt(m)
-
- pt(0) = p1(0): pt(1) = p1(1)
- pt(m - 1) = p2(0): pt(m) = p2(1)
-
- Set Ent = ThisDrawing.ModelSpace.AddLightWeightPolyline(pt)
- Ent.color = Col
- Ent.Update
-
- Pdbz = True
-
- Do While Pdbz = True
- p1 = p2: p2 = Empty
- p2 = ThisDrawing.Utility.GetPoint(p1, vbCrLf & "下一点<或结束>:")
-
- If TypeName(p2) = "Empty" Then
- Pdbz = False
- Exit Do
- Else
-
- n = n + 1: m = n * 2 - 1
- ReDim Preserve pt(m)
-
- pt(m - 1) = p2(0): pt(m) = p2(1)
- Ent.Coordinates = pt
- Ent.Update
- End If
- Loop
- Fhz = Ent.Length
-
- End If
-
- AddPline = Fhz
- End Function
|