- 积分
- 34652
- 明经币
- 个
- 注册时间
- 2003-11-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
先祝各位早年愉快!
我想做一个将同一直线上的两条线段合并的程序,基本思路如下:
1.选择两个实体,如果是line或polyline则继续
2.将两条线段的四个端点分别赋值给pnt1,pnt2,pnt3,pnt4
3.将pnt1~4重新排列,使pnt1为x坐标最小的点,pnt4为x坐标最大的点.
4.若pnt1,pnt2的角度与pnt3,pnt4的角度相等,则说明四个点在一条直线上,继续.否则退出.
5.将第一个实体的两个端点分别设为pnt1和pnt4
6.删除第二个实体.结束
下面是部分未完成的代码:
Sub uniteline()
Dim line1 As AcadEntity, line2 As AcadEntity
Dim pnt1 As Variant, pnt2 As Variant, pnt3 As Variant, pnt4 As Variant, basepnt As Variant
choose1:
ActiveDocument.Utility.GetEntity line1, basepnt, "选择第一根线段:"
If line1.ObjectName = "AcDbLine" Then
pnt1 = line1.StartPoint: pnt2 = line1.EndPoint
Else
GoTo choose1
End If
choose2:
ActiveDocument.Utility.GetEntity line2, basepnt, "选择第二根线段:"
If line2.Handle = line1.Handle Then
ActiveDocument.Utility.Prompt "线段二与线段一重复,请重新选择"
GoTo choose2
Else
End If
If line2.ObjectName = "AcDbLine" Then
pnt3 = line2.StartPoint: pnt4 = line2.EndPoint
Else
GoTo choose1
End If
If pnt1(0) > pnt2(0) Then
basepnt = pnt1
pnt1 = pnt2
pnt2 = basepnt
End If
If pnt1(0) > pnt3(0) Then
basepnt = pnt1
pnt1 = pnt3
pnt3 = basepnt
End If
If pnt1(0) > pnt4(0) Then
basepnt = pnt1
pnt1 = pnt4
pnt4 = basepnt
End If
If pnt4(0) < pnt3(0) Then
basepnt = pnt4
pnt4 = pnt3
pnt3 = basepnt
End If
If pnt4(0) < pnt2(0) Then
basepnt = pnt4
pnt4 = pnt2
pnt2 = basepnt
End If
If Abs(((pnt2(1) - pnt1(1)) / (pnt2(0) - pnt1(0))) - ((pnt4(1) - pnt3(1)) / (pnt4(0) - pnt3(0)))) < 0.000001 Then '待改进
line1.StartPoint = pnt1: line1.EndPoint = pnt4
line2.Delete
Else
ActiveDocument.Utility.Prompt "线段一与线段二不在同一直线上,无法合并."
End If
End Sub
执行过程中遇到几个问题:
1.由于不知道选择的是line还是polyline,所以将line1.line2定义为acadentity,但这样无法获得线段的startpoint和endpoint(但可以通过监视窗口看到),如果定义为acadline则可以获得其端点.
2.如何判断获得的polyline是直线还是曲线,包括多顶点的polyline.
3.如何在加载dvb时在命令行执行一个命令定义代码,如明总那个对齐程序,加载时执行(defun c:eo()(vl-vbarun "arrangeent")(princ))(princ) |
|