Message 1 of 3
eWasErased
Not applicable
12-22-2010
08:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
HI I am new to VB.NET.
I am trying to use the code provided on:
http://through-the-interface.typepad.com/through_the_interface/2007/07/updating-a-sp-1.html
The only thing is I have translated it to VB.NET instead. (this could be the problem I am sure)
I am opening the Database of all the drawings (from the file) stepping thru each object and then looking for the attribute to change.
If I have a drawing with 1 object (a block with the attributes I want to edit) in it the code works fine. But if I add a line to the file it fails.
It fails just after the first For each entid....
Dim Ent As Entity = TR.GetObject(entId, OpenMode.ForRead)
Private Function UpdateAttributesInBlock(Byref DB As Database, ByVal btrID As ObjectId) As Integer
Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
Dim Ed As Editor = Doc.Editor
Dim ChangeIndex As Integer, Intchanged As Integer
Dim TR As Transaction = DB.TransactionManager.StartTransaction
Using TR
Dim btr As BlockTableRecord = TR.GetObject(btrID, OpenMode.ForRead)
For Each entId As ObjectId In btr
Dim Ent As Entity = TR.GetObject(entId, OpenMode.ForRead)
If Ent <> Nothing Then 'And Ent.GetType.ToString = "Autodesk.AutoCAD.DatabaseServices.BlockReference" Then
Dim br As BlockReference = Ent
If br <> Nothing Then
Dim bd As BlockTableRecord = TR.GetObject(br.BlockTableRecord, OpenMode.ForRead)
'does the mSheet array contain current Block Name
If mSheets.Contains(bd.Name.ToUpper) = True Then
'step thru all sheet
For Each Sheet As String In mSheets
'if next sheet contains block name
If Sheet.ToUpper = bd.Name.ToUpper Then
'step thru all attributes
For Each arid As ObjectId In br.AttributeCollection
Dim obj As DBObject = TR.GetObject(arid, OpenMode.ForRead)
Dim ar As AttributeReference = obj
'if current sheet change, and attribute matches then change text value
If ar.Tag.ToUpper = mAttributes.GetValue(ChangeIndex).ToString.ToUpper Then
ar.UpgradeOpen()
ar.TextString = mChangeValues.GetValue(ChangeIndex).ToString
'added to fix alignment issue
Dim WDB As Database = HostApplicationServices.WorkingDatabase
HostApplicationServices.WorkingDatabase = DB
ar.AdjustAlignment(DB)
HostApplicationServices.WorkingDatabase = WDB
ar.DowngradeOpen()
Intchanged = 1
End If
Next
End If
ChangeIndex = ChangeIndex + 1
Next
ChangeIndex = 0
End If
End If
End If
Next
TR.Commit()
End Using
Ed.WriteMessage(Intchanged.ToString + " ITEMS CHANGED!" + vbCrLf)
Return Intchanged
End Function
Some help would be greatly appreciated.
Merry Christmas.
Stephan