找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1615|回复: 0

[VBA函数]:在线上以一定的y值变化插点

[复制链接]
发表于 2006-5-21 09:21:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Type point2d
x 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
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-24 10:19 , Processed in 0.238277 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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