明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: dhxf

[编程申请]字符串中间点选增加空格

  [复制链接]
 楼主| 发表于 2004-4-17 23:29 | 显示全部楼层
怎么说呢:5行变单行是文休里面的命令,变的时候不加空格;
发表于 2004-4-18 07:51 | 显示全部楼层
用这个程序处理怎样(还没加详细处理,只完成功能性):
注意直接处理多行文字。
  1. Sub MtextToText()
  2.        Dim ent As AcadEntity
  3.        Dim pnt As Variant
  4.        Dim cnt As Long
  5.        ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
  6.        ThisDrawing.SendCommand "Explode" & vbCr & "(handent " & Chr(34) _
  7.                                                        & ent.Handle & Chr(34) & ")" & vbCr & vbCr
  8.        Dim ss As AcadSelectionSet
  9.        On Error Resume Next
  10.        ThisDrawing.SelectionSets("CURRENT").Delete
  11.        Set ss = ThisDrawing.ActiveSelectionSet
  12.        Debug.Print ss.Name
  13.        Dim i As Long
  14.        Dim Ents(0) As AcadEntity
  15.        For i = 0 To ss.Count - 1
  16.                If i <> 0 Then ss(0).TextString = ss(0).TextString & " " & ss(i).TextString
  17.        Next
  18.        Set Ents(0) = ss(0)
  19.        ss.RemoveItems Ents
  20.        ss.Erase
  21. End Sub
发表于 2004-4-18 09:54 | 显示全部楼层
本帖最后由 作者 于 2004-4-18 19:52:19 编辑

多行变单行将字符串中"\P"替换为空格,多行文本宽度设为0就可以了多行炸开有点问题:如果一行上有几种字体,会分隔成几部分
  1. Sub MToS()
  2.        Dim ent As AcadEntity
  3.        Dim pnt As Variant, a As Variant
  4.        Dim cnt As Long
  5.        Dim b As String
  6.        ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
  7.        a = Split(ent.TextString, "\P")
  8.        For i = 0 To UBound(a) - 1
  9.                b = b & a(i) & " "
  10.        Next i
  11.        b = b & a(i)
  12.        ent.Width = 0
  13.        ent.TextString = b
  14. End Sub
发表于 2004-4-18 20:11 | 显示全部楼层
来更简单的:
  1. Sub MtextToText2()
  2.        Dim pnt, ent As AcadEntity
  3.         ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
  4.        ent.TextString = Replace(ent.TextString, "\P", " ")
  5.        ent.Width = 0
  6. End Sub
正在考虑怎样用程序来取消多行文字的中格式设置。
发表于 2004-4-18 20:36 | 显示全部楼层
把我的两个程序结合起来,就可以很多的解决多行文字中的格式设置问题:
  1. Sub MtextToText2()
  2.        Dim ent As AcadEntity
  3.        Dim pnt As Variant
  4.        Dim cnt As Long
  5.        ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
  6.        ent.TextString = Replace(ent.TextString, "\P", " ")
  7.        ent.Width = 0
  8.        ThisDrawing.SendCommand "Explode" & vbCr & "(handent " & Chr(34) _
  9.                                                        & ent.Handle & Chr(34) & ")" & vbCr & vbCr
  10.        Dim ss As AcadSelectionSet
  11.        On Error Resume Next
  12.        ThisDrawing.SelectionSets("CURRENT").Delete
  13.        Set ss = ThisDrawing.ActiveSelectionSet
  14.        Dim i As Long
  15.        Dim Ents(0) As AcadEntity
  16.        For i = 0 To ss.Count - 1
  17.                If i <> 0 Then ss(0).TextString = ss(0).TextString & ss(i).TextString
  18.        Next
  19.        Set Ents(0) = ss(0)
  20.        ss.RemoveItems Ents
  21.        ss.Erase
  22. End Sub
发表于 2004-4-18 20:40 | 显示全部楼层
本帖最后由 作者 于 2004-4-20 11:45:07 编辑

取消多行文字的中格式设置,只有再把它炸开再合并
  1. Sub MToS()
  2.        Dim pnt, ent As AcadMText
  3.        Dim m As Integer, n As Integer
  4.        ThisDrawing.Utility.GetEntity ent, pnt, vbCr & "请选择多行文字:"
  5.        ent.TextString = Replace(ent.TextString, "\P", " ")
  6.        ent.Width = 0
  7.        m = ThisDrawing.ModelSpace.Count
  8.        ThisDrawing.SendCommand "Explode" & vbCr & "(handent " & Chr(34) _
  9.                                                        & ent.Handle & Chr(34) & ")" & vbCr & vbCr
  10.        n = ThisDrawing.ModelSpace.Count
  11.        If m = n Then Exit Sub
  12.        For i = m + 1 To n
  13.                ThisDrawing.ModelSpace(m - 1).TextString = _
  14.                                                        ThisDrawing.ModelSpace(m - 1).TextString + _
  15.                                                        ThisDrawing.ModelSpace(m).TextString
  16.                ThisDrawing.ModelSpace(m).Delete
  17.        Next i
  18. End Sub
发表于 2004-4-18 20:45 | 显示全部楼层
^_^


居然跟明总抢进度起来了,该死,该死
 楼主| 发表于 2004-4-22 22:01 | 显示全部楼层
进来才看到---抱歉


看了几段程序,怎么用呢?汗,还得请教各位老大;


马后炮说一句,我只是做[单行文字]点选位置增加空格,看各位老大都进步做到[多行文字],谢谢谢谢;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-21 10:19 , Processed in 0.195693 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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