- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I get an eNullObjectId error. I thought I found the answer here, but I couldn't get it to work. Please don't answer in C#. I've used code converters and they don't work well.
Public Function FindReplace(ldate As String, fn As String, strFind As List(Of String), strReplace As List(Of String)) Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Core.Application.DocumentManager.MdiActiveDocument.Editor, db As Database = New Database(False, True), dwgDir As String = IO.Path.GetDirectoryName(fn), dwgName As String = IO.Path.GetFileName(fn), dwgfullname As String = dwgDir & "\" & dwgName, log As New List(Of String) Using db Try 'FileOpenMode.OpenForReadAndAllShare db.ReadDwgFile(fn, FileOpenMode.OpenForReadAndAllShare, False, Nothing) Catch __unusedException1__ As System.Exception ed.WriteMessage(vbLf & "Unable to read drawing file.") End Try Dim lg As New List(Of String())(), txtClass = RXObject.GetClass(GetType(DBText)), mtxtClass = RXObject.GetClass(GetType(MText)), blkrefClass = RXObject.GetClass(GetType(BlockReference)) Using tr = db.TransactionManager.StartTransaction Dim loDic As DBDictionary = CType(tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead, False), DBDictionary) For Each entry As DBDictionaryEntry In loDic Dim layout = CType(tr.GetObject(entry.Value, OpenMode.ForRead), Layout) Dim btr As BlockTableRecord = CType(tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead), BlockTableRecord) For Each objID As ObjectId In btr If objID.ObjectClass.IsDerivedFrom(blkrefClass) Then Dim blkRef As BlockReference = CType(tr.GetObject(objID, OpenMode.ForRead), BlockReference), acblkName As String = blkRef.Name, ' Error is here nbtr As BlockTableRecord = CType(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord), attCol As AttributeCollection = blkRef.AttributeCollection If attCol IsNot Nothing Then For Each attId As ObjectId In attCol Dim att As AttributeReference = CType(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference), wksp As String = att.BlockName.ToString, hand As String = att.Handle.ToString, val As String = att.TextString, locX As String = att.Position.X.ToString, locY As String = att.Position.Y.ToString, locZ As String = att.Position.Z.ToString For i = 0 To strFind.Count - 1 If val.Contains(strFind(i)) = True Then att.TextString = val.Replace(strFind(i), strReplace(i)) att.RecordGraphicsModified(True) att.AdjustAlignment(db) log.Add(ldate & "," & att.TextString & "," & val & "," & "Attribute" & "," & dwgName & "," & wksp & "," & hand & "," & locX & "," & locY & "," & locZ) Dim wbd As Database = HostApplicationServices.WorkingDatabase HostApplicationServices.WorkingDatabase = db att.AdjustAlignment(db) End If Next Next End If End If Next Next tr.Commit() End Using db.SaveAs(fn, DwgVersion.AC1027) End Using Return log End Function
Solved! Go to Solution.
Link copied