Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, this part of my code is supposed to look for a layout I just added, search through it's blocks that have attributes, and if the block with the specific attributes is found, it should open a dialog box and populate the two text boxes with the attribute text. When the user changes the text in the dialog box and picks ok, I want it to go back and change the attribute values in the block.
I'm just not sure how to change the text value for the attributes. Do I create an identical code that will search all over again only to write the values instad of read? There has to be an easier way since I have the block located already.
Public Sub replaceTitleText(ByVal pageNumber As Integer)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim layoutCount As Integer = LayoutManager.Current.LayoutCount - 1
Dim getTexttrans As Transaction = db.TransactionManager.StartTransaction()
Try
Dim myBT As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
For Each btrID As ObjectId In myBT
Dim myBTR As BlockTableRecord = btrID.GetObject(OpenMode.ForRead)
' If the block table record is a layout
If myBTR.IsLayout Then
Dim layOut As Layout = myBTR.LayoutId.GetObject(OpenMode.ForRead)
' If the layout is the new layout
If layOut.TabOrder = pageNumber Then
For Each id As ObjectId In myBTR
Dim obj As DBObject = id.GetObject(OpenMode.ForRead)
' If the object is a block reference
If TypeOf obj Is BlockReference Then
Dim bref As BlockReference = DirectCast(obj, BlockReference)
' If the block reference has attributes
If bref.AttributeCollection.Count <> 0 Then
For Each attId As ObjectId In bref.AttributeCollection
Dim attRef As AttributeReference = attId.GetObject(OpenMode.ForRead)
' If the title block has the "PAGE_TITLE" or "DIE_SIDE_VIEW" attribute
' get the current text values for the attributes
Dim textTitle As String = ""
Dim textDieSide As String = ""
If attRef.Tag = "PAGE_TITLE" Then
textTitle = attRef.TextString
End If
If attRef.Tag = "DIE_SIDE_VIEW" Then
textDieSide = attRef.TextString
'diaTitleText.txtDieSide.Visible = True
End If
' If the block has either one of these attributes
If Not textTitle = "" Or Not textDieSide = "" Then
Dim diaTitleText As dialogTitleText = New dialogTitleText(textTitle, textDieSide)
'diaTitleText.ShowDialog()
If diaTitleText.ShowDialog = System.Windows.Forms.DialogResult.OK Then
textTitle = diaTitleText.newTextTitle
textDieSide = diaTitleText.newTextDieSide
End If
End If
Next
End If
End If
Next
End If
End If
Next
Catch
ed.WriteMessage("Error!")
Finally
getTexttrans.Commit()
End Try
End Sub
Solved! Go to Solution.