Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am writing a script that will renumber the pages(layouts) in the dwg. The page numbers are a block attribute in the title block. So I for each through the layouts, getting the block table for each layout. Then I for each through the objectid's in the block table getting the block table reference from each. Then I for each through the objectid's in the block table reference wanting to get the block reference; but this results in a system.accessviolationexception. This post refers to the block table reference as the block, but I don't know how to modify the attributes using this technique. Am I on the right path?
#Region " Emp_RenumberPages"
<CadRun.CommandMethod("Emp_RenumberPages")>
Public Sub Emp_RenumberPages()
' Layouts are sorted by taborder during the globals.GetLayouts sub
Initiate()
Try
' Start transaction
Dim Trans As CadDBS.Transaction = g_AcDatBas.TransactionManager.StartTransaction()
DB.WriteLine(vbNewLine & "Class1 | ServiceCommands | Emp_RenumberPages | ")
' In each layout
For Each Layt As CadDBS.Layout In g_Layouts
Layt.TabSelected = True
DB.WriteLine("..." & vbTab & $"Layout: {Layt.LayoutName}")
' Open the Block table for read
Dim BlkTable As CadDBS.BlockTable = Trans.GetObject(Layt.Database.BlockTableId, CadDBS.OpenMode.ForRead)
For Each TblObjID As CadDBS.ObjectId In BlkTable
'If Not TblObjID.ObjectClass.Name = "AcDbBlockReference" Then : Continue For : DB.WriteLine("..." & vbTab & $"Skipping block, not AcDbBlockReference: {TblObjID.ObjectClass.Name}") : End If '<-- skip if this isn't a block reference
'DB.WriteLine("..." & vbTab & $"Looking at block table record object handle: {MyObjId.Handle} | Old id: {MyObjId.OldId}")
Dim BlTblRec As CadDBS.BlockTableRecord = CType(Trans.GetObject(TblObjID, CadDBS.OpenMode.ForRead), CadDBS.BlockTableRecord)
For Each ObjID As CadDBS.ObjectId In BlTblRec
Dim MyBlockRef As CadDBS.BlockReference = CType(Trans.GetObject(ObjID, CadDBS.OpenMode.ForRead), CadDBS.BlockReference)
If MyBlockRef.Name.ToString.Contains("-title") Then
'DB.WriteLine("..." & vbTab & "Block Reference is a titleblock.")
DB.WriteLine("..." & vbTab & $"Block Reference Name: {MyBlockRef.Name}")
' Display the tags and values of the attached attributes
Dim AttCol As CadDBS.AttributeCollection = MyBlockRef.AttributeCollection
For Each AttObjId As CadDBS.ObjectId In AttCol
Dim DbObj As CadDBS.DBObject = Trans.GetObject(AttObjId, CadDBS.OpenMode.ForRead)
Dim AttRef As CadDBS.AttributeReference = DbObj
DB.WriteLine("..." & vbTab & vbTab & "Tag: " & AttRef.Tag & "Value: " & AttRef.TextString)
' Change the value of the attribute
' AttRef.TextString = "NEW VALUE!"
Next
End If
Next
Next
DB.WriteLine(vbNewLine)
' Save the new object to the database
Trans.Commit()
Catch ex As Exception
Return
End Try
End Sub
#End Region
Solved! Go to Solution.