toosimple 发表于 2006-8-2 15:52:00

历遍多个布局求助

<P>Option Explicit</P>
<P>Private Sub CommandButton1_Click()<BR>Dim layo As AcadLayout<BR>Dim sset As AcadSelectionSet<BR>Dim str1 As String<BR>Dim oldstr As String<BR>Dim newstr As String<BR>Dim ftype(0) As Integer<BR>Dim fdata(0) As Variant<BR>Dim point1(0 To 2) As Double<BR>Dim point2(0 To 2) As Double<BR>Dim i As Integer<BR>Dim abc As Object</P>
<P>ftype(0) = 0<BR>fdata(0) = "TEXT"<BR>oldstr = "a"<BR>newstr = "e"<BR>point1(0) = 343<BR>point1(1) = 272.5<BR>point1(2) = 0<BR>point2(0) = 403<BR>point2(1) = 280<BR>point2(2) = 0<BR>UserForm1.Hide</P>
<P>'以下建立选择集<BR>On Error Resume Next<BR>&nbsp;&nbsp; If Not IsNull(ThisDrawing.SelectionSets.Item("ss1")) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Item("ss1")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sset.Delete<BR>&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Add("ss1")<BR>&nbsp;&nbsp;&nbsp; sset.Clear<BR>'选择集建立完毕<BR>'%%%%%%%%%%%%%%%%%之间的部分有问题<BR>For i = 0 To ThisDrawing.Layouts.Count - 1 Step 1<BR>Set abc = ThisDrawing.Layouts.Item(0)<BR>&nbsp;&nbsp;&nbsp; sset.Clear<BR>&nbsp;&nbsp;&nbsp; sset.Select acSelectionSetWindow, point1, point2, ftype, fdata<BR>&nbsp;&nbsp;&nbsp; str1 = sset.Item(0).TextString<BR>&nbsp;&nbsp;&nbsp; If InStr(str1, oldstr) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sset.Item(0).TextString = replacestr(str1, oldstr, newstr, False)'调用下面函数<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'sset.Item(0).Update<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.Regen acAllViewports</P>
<P>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp; Next i<BR>'%%%%%%%%%%%%%%%%%%%%%以上有问题<BR>End Sub<BR>'以下函数执行替换==========================================================================<BR>Public Function replacestr(ByVal searchstr As String, ByVal oldstr As String, ByVal newstr As String, ByVal firstonly As Boolean) As String<BR>If searchstr = "" Then Exit Function<BR>If oldstr = "" Then Exit Function<BR>Dim i As Integer, oldstrlen As Integer, holdstr As String, strloc As Integer<BR>replacestr = ""<BR>oldstrlen = Len(oldstr)<BR>strloc = InStr(searchstr, oldstr)<BR>While strloc &gt; 0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; holdstr = holdstr &amp; Left(searchstr, strloc - 1) &amp; newstr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; searchstr = Mid(searchstr, strloc + oldstrlen)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strloc = InStr(searchstr, oldstr)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If firstonly Then replacestr = holdstr &amp; searchstr: Exit Function<BR>Wend<BR>replacestr = holdstr &amp; searchstr<BR>End Function<BR>'===================================================</P>
<P>图形有2个布局,在每个布局中,在(343,272.5)与(403,280)范围内有一个text:内容为"hah",我想把他变成"heh",可是上面的程序只能对当前显示的布局有效,对其他布局没作用不知道为什么,麻烦各位给看看吧</P>

fjfhgdwfn 发表于 2006-8-2 19:08:00

<P>&nbsp;ThisDrawing.SetVariable "CTAB", Layout.Name</P>
<P>加上这一句,使他变成当前布局.</P>
页: [1]
查看完整版本: 历遍多个布局求助