- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I'm trying to chnage the text of the sheet number and total sheet number attributes for each layout in my drawing. I have code that adds and deletes the specified pages, now I need to edit the attributes to reflect the correct page and correct total amount of pages. Here is my code, based on my old VBA version. Please forgive my ignorance, but I'm teaching myself as I go. Any commenst within the code describing what it does really helps me learn.
I know there is a problem with the line:
For Each item In myBTR.ObjectId
I just threw something in there as I searched the internet for help. I've used a njumber of websites and books, but I would really like to find something that teaches about block tables, block table references, block table IDs so I can get a better understanding of breaking stuff down to get the info I need. Any suggestions are welcome.
Public Sub updatePageNumbers()
Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document
Dim myDB As Autodesk.AutoCAD.DatabaseServices.Database
Dim myTransManForPageNumbers As Autodesk.AutoCAD.DatabaseServices.TransactionManager
Dim myTransForPageNumbers As Transaction
Dim myLM As DatabaseServices.LayoutManager
Dim myLMCount As Integer
Dim myLayout As DatabaseServices.Layout
Dim myBT As DatabaseServices.BlockTable
Dim myBTR As DatabaseServices.BlockTableRecord
Dim myBTRE As DatabaseServices.SymbolTableEnumerator
myDWG = DocumentManager.MdiActiveDocument
'myDB = myDWG.Database
myTransManForPageNumbers = myDWG.TransactionManager
myTransForPageNumbers = myTransManForPageNumbers.StartTransaction
myBT = myDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
myBTRE = myBT.GetEnumerator
myLM = DatabaseServices.LayoutManager.Current
myLMCount = myLM.LayoutCount - 1
Dim strLayoutTotal As String
Dim strLayoutCounter As Integer
Dim strLayoutNumber As String
Dim strLayoutTabName As String
While myBTRE.MoveNext
myBTR = myBTRE.Current.GetObject(DatabaseServices.OpenMode.ForRead)
If myBTR.IsLayout Then
If Not myBTR.Name = "*Model_Space" Then
myLayout = myBTR.LayoutId.GetObject(DatabaseServices.OpenMode.ForRead)
strLayoutNumber = myLayout.TabOrder
Dim item As Object
For Each item In myBTR.ObjectId
'Get Each Block Reference
If TypeOf item Is AcadBlockReference Then
'Check for Attributes
If item.HasAttributes Then
Dim atts As Object
atts = item.GetAttributes
'Verify Range is valid
If isValid(atts) Then
Dim AttributeCounter As Integer
For AttributeCounter = LBound(atts) To UBound(atts)
'Check if attribute has the correct Tag, then change it to the last sheet number
If atts(AttributeCounter).TagString = "TOTAL_SHEET_NO" Then
'Set Value
atts(AttributeCounter).TextString = strLayoutTotal
End If
'Update the sheet number to be the current or new sheet number
If atts(AttributeCounter).TagString = "SHEET_NO" Then
'Set Value
atts(AttributeCounter).TextString = strLayoutNumber
End If
Next
End If
End If
End If
Next
End If
End If
End While
myDWG.Editor.Regen()
myTransForPageNumbers.Commit()
myTransForPageNumbers.Dispose()
myTransManForPageNumbers.Dispose()
End SubThanks,
Mark
Solved! Go to Solution.