|
发表于 2004-8-2 14:41:00
|
显示全部楼层
代码如下:
Sub rename()
'定义变量
Dim elem As Object '定义一个对象
Dim varAttributes As Variant '定义一个属性变量
Dim OldName As String
Dim NewName As String
Dim CgName As String
Dim L As Integer
Dim LL As Integer
Dim LLL As Integer
Dim number As Integer
Dim I As Integer
Dim found As Boolean
Static sset As AcadSelectionSet
Dim sss1 As AcadSelectionSet
Dim ObjSelectionSet As AcadSelectionSet
found = False
I = 0
'获取当前文件名
NewName = ThisDrawing.Name
L = Len(NewName)
NewName = Left(NewName, L - 4)
'获取当前文档标题栏中的图号
On Error Resume Next
Dim fft(1) As Integer, ffd(1)
ThisDrawing.SelectionSets("ss").Delete
Set sset = ThisDrawing.SelectionSets.Add("ss")
fft(0) = 0: ffd(0) = "Insert"
fft(1) = 2: ffd(1) = "PC_TITLE_BLOCK"
sset.Select acSelectionSetAll, , , fft, ffd
varAttributes = sset.Item(0).GetAttributes
OldName = varAttributes(4).TextString
'选择明细表
On Error Resume Next
Dim ss1 As AcadSelectionSet
Dim ft(1) As Integer, fd(1)
ThisDrawing.SelectionSets("*TlsTest*").Delete
Set ss1 = ThisDrawing.SelectionSets.Add("*TlsTest*")
ft(0) = 0: fd(0) = "Insert"
ft(1) = 2: fd(1) = "PC_MXB_BLOCK"
ss1.Select acSelectionSetAll, , , ft, fd
'修改明细表和标题
For Each elem In ss1
varAttributes = elem.GetAttributes
CgName = varAttributes(1).TextString
L = Len(NewName)
LL = Len(OldName)
LLL = Len(CgName)
If OldName = Left(CgName, LL) Then
CgName = Right(CgName, LLL - LL)
CgName = NewName & CgName
varAttributes(1).TextString = CgName
elem.Update
End If
Next
For Each elem In sset
varAttributes = elem.GetAttributes
varAttributes(4).TextString = NewName
Next
'删除标题栏和明细表选择集
ThisDrawing.SelectionSets("*TlsTest*").Delete
ThisDrawing.SelectionSets("ss").Delete
End Sub
举例说明一下该代码主要目的:
有一dwg文件,文件保存为ZJ40DBST,则文件的图样代号也为ZJ40DBST,明细表中代号也以ZJ40DBST开头来排序,但当我想把ZJ40DBST改为ZJ70LDB时,只需改一下保存的文件名,然后打开ZJ70LDB文件,运行上面的代码即可,但修改是针对天河PCCAD2002所写代码,故需在PCCAD2002下才能发现该情况,谢谢! |
|