eNullObjectID
我得到了一个enullobject错误。我想我找到了答案herehttp://www.theswamp.org/index.php?topic=47128.msg521607#msg521607,但我无法让它工作。我还试图锁定绘图,但没用。它轰炸的文件已锁定其中的视口。出于某些原因,代码会编辑视口大小和位置。根据错误消息,是否是锁定的视口导致了错误原始代码:
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
尝试修复它:
Public Function FindReplace(ldate As String, fn As String, strFind As List(Of String), strReplace As List(Of String))
' Using docLock As DocumentLock = Core.Application.DocumentManager.MdiActiveDocument.LockDocument()
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(txtClass) Then
Dim txt As DBText = CType(tr.GetObject(objID, OpenMode.ForWrite), DBText),
wksp As String = txt.BlockName.ToString,
hand As String = txt.Handle.ToString,
val As String = txt.TextString,
locX As String = txt.Position.X.ToString,
locY As String = txt.Position.Y.ToString,
locZ As String = txt.Position.Z.ToString
For i = 0 To strFind.Count - 1
If val.Contains(strFind(i)) Then
txt.TextString = val.Replace(strFind(i), strReplace(i))
txt.RecordGraphicsModified(True)
log.Add(ldate & "," & txt.TextString & "," & val & "," & "DBText" & "," & dwgName & "," & wksp & "," & hand & "," & locX & "," & locY & "," & locZ)
' Need this code in order to insure that the attributes alignment remains
txt.AdjustAlignment(db)
End If
Next
End If
If objID.ObjectClass.IsDerivedFrom(mtxtClass) Then
Dim mtxt As MText = CType(tr.GetObject(objID, OpenMode.ForWrite), MText),
wksp As String = mtxt.BlockName.ToString,
hand As String = mtxt.Handle.ToString,
val As String = mtxt.Contents.ToString,
locX As String = mtxt.Location.X.ToString,
locY As String = mtxt.Location.Y.ToString,
locZ As String = mtxt.Location.Z.ToString
For i = 0 To strFind.Count - 1
If val.Contains(strFind(i)) = True Then
mtxt.Contents = val.Replace(strFind(i), strReplace(i))
mtxt.RecordGraphicsModified(True)
log.Add(ldate & "," & mtxt.Contents & "," & val & "," & "MText" & "," & dwgName & "," & wksp & "," & hand & "," & locX & "," & locY & "," & locZ)
End If
Next
End If
If objID.ObjectClass.IsDerivedFrom(blkrefClass) Then
Dim blkRef As BlockReference = CType(tr.GetObject(objID, OpenMode.ForRead), BlockReference)
If blkRef IsNot Nothing Then
Dim nbtr As BlockTableRecord = CType(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord), ' This is line 430
acblkName As String = blkRef.Name,
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
End If
Next
Next
tr.Commit()
End Using
db.SaveAs(fn, DwgVersion.AC1027)
'db.SaveAs(fn, Autodesk.AutoCAD.DatabaseServices.DwgVersion.Current)
End Using
Return log
' End Using
End Function
错误消息:
应用程序不支持实时(JIT)
调试。有关详细信息,请参阅此消息的结尾
**********例外文本************
Autodesk.AutoCAD.Runtime。例外:Autodesk.AutoCAD.DatabaseServices.TransactionManager中的EnulObjectId
。GetObjectInternal(AcDbTransactionManager*pTM、ObjectId、OpenMode模式、布尔openErased、布尔强制OpenOnLockedLayer)
位于Autodesk.AutoCAD.DatabaseServices.Transaction。Joshua.frmPermianBasinWellSiteFacilityGenerator上的GetObject(ObjectId,OpenMode模式)
。在E:\Joshua\16APR18\Joshua \frmPermianBasinWellSiteFacilityGenerator中查找替换(字符串ldate,字符串fn,列表'1 strFind,列表'1strReplace)。vb:Joshua.frmPermianBasinWellSiteFacilityGenerator的第430行。cmdGenerate_Click(对象发送者,事件参数e)在e:\Joshua\16APR18\Joshua \frmPermianBasinWellSiteFacilityGenerator中。vb:System.Windows.Forms.Control中的第231行
。单击System.Windows.Forms.Button上的(EventArgs e)
。单击System.Windows.Forms.Button上的(EventArgs e)
。OnMouseUp(MouseEventArgs-mevent)
位于System.Windows.Forms.Control。WmMouseUp(消息&m,鼠标按钮,Int32点击)
位于System.Windows.Forms.Control。在System.Windows.Forms.ButtonBase上的WndProc(消息和消息)
。在System.Windows.Forms.Button上显示WndProc(消息和消息)
。在System.Windows.Forms.NativeWindow上显示WndProc(消息和消息)
。回调(IntPtr hWnd、Int32 msg、IntPtr wparam、intptrLPRAM)
**** Hidden Message ***** MGDDBG是你的朋友,会让你看这些有问题的实体。
我很好奇你为什么要测试rxclass isderivedfrom,你希望在这里得到什么?
我想您的意思是从objectid中获取rxclass并测试它是否等于blockreference的值
页:
[1]