[VBA函数]:在线上以一定的y值变化插点
Type point2dx As Double
y As Double
z As Double
End Type
Sub addpoint()
Dim pt1(2000) As point2d
Dim pl As AcadEntity
Dim dx As Double
Dim dy As Double
Dim dz As Double
Dim k As Double
Dim point(5000) As AcadPoint
Dim pt3() As Double
Dim minpoint As Variant
Dim maxpoint As Variant
Dim pp(0 To 2) As Double
Dim d As Double
Dim e, g As Double
On Error Resume Next
ThisDrawing.Utility.GetEntity pl, pt, "选择轻质多段线:"
'*********************
'处理Esc或者Enter键的事件
If Err Then
Err.Clear
Exit Sub
End If
'*********************
Dim coords As Variant
coords = pl.Coordinates
n = UBound(coords)
q = (n + 1) \ 2 - 1 '代表一条PL线分q段
pl.GetBoundingBox minpoint, maxpoint
For i = 0 To q
pt1(i).x = coords(2 * i): pt1(i).y = coords(2 * i + 1): pt1(i).z = 0
Next
Dim m As Integer
Dim x, y As Double
Dim a, b As Double
For m = 0 To q - 1
y = minpoint(1)
dx = pt1(m + 1).x - pt1(m).x
dy = pt1(m + 1).y - pt1(m).y
k = dy / dx
d = pt1(m).y - k * pt1(m).x
If (pt1(m).y < pt1(m + 1).y) Then
a = pt1(m).y: b = pt1(m + 1).y
Else
a = pt1(m + 1).y: b = pt1(m).y
End If
'MsgBox a & " h" & b
While (y < maxpoint(1))
If (y < b And y > a) Then
e = y - d
x = e / k
pp(0) = x: pp(1) = y: pp(2) = 0
Set point(m) = ThisDrawing.ModelSpace.addpoint(pp)
point(m).color = acRed
End If
y = y + 100
Wend
Next
y = minpoint(1)
dx = pt1(0).x - pt1(q).x
dy = pt1(0).y - pt1(q).y
k = dy / dx
d = pt1(0).y - k * pt1(0).x
If (pt1(0).y < pt1(q).y) Then
a = pt1(0).y: b = pt1(q).y
Else
a = pt1(q).y: b = pt1(0).y
End If
'MsgBox a & " h" & b
While (y < maxpoint(1))
If (y < b And y > a) Then
e = y - d
x = e / k
pp(0) = x: pp(1) = y: pp(2) = 0
Set point(m) = ThisDrawing.ModelSpace.addpoint(pp)
point(m).color = acRed
End If
y = y + 100
Wend
'Set point = ThisDrawing.ModelSpace.addpoint(pt2)
'point.color = acGreen
'Next j
'pl.Delete
'Set ll = ThisDrawing.ModelSpace.Add3DPoly(pt3)
'll.color = acRed
'End If
'Next m
'ThisDrawing.SetVariable "pdmode", 34
'ThisDrawing.SetVariable "pdsize", 2
'pl.Delete
End Sub
页:
[1]