- 积分
- 252
- 明经币
- 个
- 注册时间
- 2003-6-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2003-6-13 14:49:00
|
显示全部楼层
还有个问题,我运行程序有漏洞,请大家看看
大家给看看,我这段程序呢目的是要把字识别出来,然后分别按y,x排序,但是举个例子,比如我识别出268个字也就是268个坐标,但是在排序的时候,按x排会出现568个坐标,按y排会有789个坐标。请大家研究一下,小弟刚上手没多久,多多帮忙
Option Explicit
Private Sub CommandButton1_Click()
Dim totalczx As Integer
Dim czx, spx As Integer
Dim textobj As AcadEntity
Dim point1 As Variant
Dim point2 As Variant
Dim a(1 To 10000) As Double
Dim b(1 To 10000) As Double
Dim i, j As Integer
i = 1
j = 1
czx = 0
Open "e:\1.txt" For Output As #1 '
For Each textobj In ThisDrawing.ModelSpace '找字
If textobj.ObjectName = "AcDbText" Then
point1 = textobj.InsertionPoint
a(i) = point1(0)
b(j) = point1(1)
i = i + 1
j = j + 1
czx = czx + 1
Write #1, czx, point1(0), point1(1), point1(2)
End If
Next
totalczx = czx
Close #1
'############################首先按x坐标排序####################################333
Dim im As Integer
Dim t As Double
Dim n As Integer
n = totalczx
For i = 1 To n - 1 '排序
im = i
For j = i + 1 To n
If a(j) < a(im) Then im = j
Next j
t = a(i)
a(i) = a(im)
a(im) = t
Next i
For i = 1 To czx
Next i
Close #2
czx = 0
Open "e:\字的排序按x坐标.txt" For Output As #3
For i = 1 To totalczx
For Each textobj In ThisDrawing.ModelSpace
If textobj.ObjectName = "AcDbText" Then
point1 = textobj.InsertionPoint
If a(i) = point1(0) Then
czx = czx + 1
Write #3, czx, point1(0), point1(1), point1(2)
End If
End If
Next
Next i
Close #3
'######################然后按y坐标排序########################333
n = totalczx '假设水平线的数目为100
For i = 1 To n - 1 '排序
im = i
For j = i + 1 To n
If b(j) < b(im) Then im = j
Next j
t = b(i)
b(i) = b(im)
b(im) = t
Next i
For i = 1 To czx
Next i
Close #6
czx = 0
Open "e:\字的排序按y坐标排序.txt" For Output As #4
For i = 1 To totalczx
For Each textobj In ThisDrawing.ModelSpace
If textobj.ObjectName = "AcDbText" Then
point1 = textobj.InsertionPoint
If b(i) = point1(1) Then
czx = czx + 1
Write #4, czx, point1(0), point1(1), point1(2)
End If
End If
Next
Next i
Close #4
End Sub |
|