注意直接处理多行文字。Sub MtextToText()
Dim ent As AcadEntity
Dim pnt As Variant
Dim cnt As Long
ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
ThisDrawing.SendCommand "Explode" & vbCr & "(handent " & Chr(34) _
& ent.Handle & Chr(34) & ")" & vbCr & vbCr
Dim ss As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets("CURRENT").Delete
Set ss = ThisDrawing.ActiveSelectionSet
Debug.Print ss.Name
Dim i As Long
Dim Ents(0) As AcadEntity
For i = 0 To ss.Count - 1
If i <> 0 Then ss(0).TextString = ss(0).TextString & " " & ss(i).TextString
Next
Set Ents(0) = ss(0)
ss.RemoveItems Ents
ss.Erase
End Sub
本帖最后由 作者 于 2004-4-18 19:52:19 编辑
多行变单行将字符串中"\P"替换为空格,多行文本宽度设为0就可以了多行炸开有点问题:如果一行上有几种字体,会分隔成几部分Sub MToS()
Dim ent As AcadEntity
Dim pnt As Variant, a As Variant
Dim cnt As Long
Dim b As String
ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
a = Split(ent.TextString, "\P")
For i = 0 To UBound(a) - 1
b = b & a(i) & " "
Next i
b = b & a(i)
ent.Width = 0
ent.TextString = b
End Sub 来更简单的:Sub MtextToText2()
Dim pnt, ent As AcadEntity
ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
ent.TextString = Replace(ent.TextString, "\P", " ")
ent.Width = 0
End Sub
正在考虑怎样用程序来取消多行文字的中格式设置。 把我的两个程序结合起来,就可以很多的解决多行文字中的格式设置问题:
Sub MtextToText2()
Dim ent As AcadEntity
Dim pnt As Variant
Dim cnt As Long
ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
ent.TextString = Replace(ent.TextString, "\P", " ")
ent.Width = 0
ThisDrawing.SendCommand "Explode" & vbCr & "(handent " & Chr(34) _
& ent.Handle & Chr(34) & ")" & vbCr & vbCr
Dim ss As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets("CURRENT").Delete
Set ss = ThisDrawing.ActiveSelectionSet
Dim i As Long
Dim Ents(0) As AcadEntity
For i = 0 To ss.Count - 1
If i <> 0 Then ss(0).TextString = ss(0).TextString & ss(i).TextString
Next
Set Ents(0) = ss(0)
ss.RemoveItems Ents
ss.Erase
End Sub
本帖最后由 作者 于 2004-4-20 11:45:07 编辑
取消多行文字的中格式设置,只有再把它炸开再合并Sub MToS()
Dim pnt, ent As AcadMText
Dim m As Integer, n As Integer
ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
ent.TextString = Replace(ent.TextString, "\P", " ")
ent.Width = 0
m = ThisDrawing.ModelSpace.Count
ThisDrawing.SendCommand "Explode" & vbCr & "(handent " & Chr(34) _
& ent.Handle & Chr(34) & ")" & vbCr & vbCr
n = ThisDrawing.ModelSpace.Count
If m = n Then Exit Sub
For i = m + 1 To n
ThisDrawing.ModelSpace(m - 1).TextString = _
ThisDrawing.ModelSpace(m - 1).TextString + _
ThisDrawing.ModelSpace(m).TextString
ThisDrawing.ModelSpace(m).Delete
Next i
End Sub ^_^
居然跟明总抢进度起来了,该死,该死 进来才看到---抱歉
看了几段程序,怎么用呢?汗,还得请教各位老大;
马后炮说一句,我只是做[单行文字]点选位置增加空格,看各位老大都进步做到[多行文字],谢谢谢谢;
页:
1
[2]