VBA如何得到具体哪个布局中的数据
For i = 0 To ThisDrawing.Layouts.Count '在各布局各中循环<BR> Set lay1 = ThisDrawing.Layouts.Item(i)<BR> If lay1.Name <> "model" Then<BR> ' filterdata = "A" & (10 * i)<BR> ' On Error Resume Next<BR> lay1.Name = filterdata<BR> ' On Error Resume Next<BR> End If<BR> ' MsgBox lay1.Name '得到所有布局的名称<BR>Nextsti = 0<BR> For j = 0 To ThisDrawing.PaperSpace.Count - 1 '在当前图纸空间内循环<BR> Set a = ThisDrawing.PaperSpace.Item(j)<BR> If a.ObjectName = "AcDbText" Then<BR> st(sti) = a.TextString<BR> If st(sti) = "图号:1" Then<BR> MsgBox st(sti)<BR> st(sti) = "图号:2" '替换字符串<BR> a.TextString = st(sti)<BR> End If<BR> sti = sti + 1<BR> End If<BR> Next
我想把到如A0,A10,A20布局中的"图号:1"都替换成"图号:2"要如何做,请老大们指点下
我前面的程序只能一个个的改. 你要替换的文字是在模型空间还是图纸空间? 是图纸空间 用选择集来操作吧,分别设置当前的布局为A0、A10等,然后选择符合条件的文字,并且进行替换。 我就是不知如何用程序来设置,能写简单的VBA代码给我吗. 用以下程序就可以得到所有布局中的文字:Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())
Dim fType() As Integer, fData()
Dim index As Long, i As Long
index = LBound(gCodes) - 1
For i = LBound(gCodes) To UBound(gCodes) Step 2
index = index + 1
ReDim Preserve fType(0 To index)
ReDim Preserve fData(0 To index)
fType(index) = CInt(gCodes(i))
fData(index) = gCodes(i + 1)
Next
typeArray = fType: dataArray = fData
End Sub
Function CreateSelectionSet(Optional SSetName As String = "mjtd") As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets(SSetName).Delete
Set CreateSelectionSet = ThisDrawing.SelectionSets.Add(SSetName)
End Function
Sub SelectAllLayoutText()
Dim ss As AcadSelectionSet
Set ss = CreateSelectionSet
Dim typeArray As Variant
Dim dataArray As Variant
BuildFilter typeArray, dataArray, 0, "TEXT"
ss.Select acSelectionSetAll, , , typeArray, dataArray
Debug.Print ss.Count
End Sub特别提示:Select 的 acSelectionSetAll 项所选择的是所有图形中的对象,不管对象是在哪个空间或布局中。
如果需要过滤出某个布局中的对象,则使用实用函数中的以下函数解决:
http://www.mjtd.com/function/list.asp?id=304&ordertype=bysort&orderkey=33 非常感谢,可以用了
页:
[1]