I have an VB.Net app that finds records that are balnk in an Object Data table. I want to find the corresponding AutCAD drawing object that is missing the Object Data and highlight it with a color such as RED.
Any thoughts? Thanks.
Imports acadapps = Autodesk.AutoCAD.ApplicationServices
Imports acaddbs = Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.Gis.Map
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Colors
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Public Class FindBlankODRoads
<Autodesk.AutoCAD.Runtime.CommandMethod("FindBlankODRoads")>
Public Sub getodrecordcount()
'Dim TableList As ObjectData.Tables = Autodesk.Gis.Map.HostMapApplicationServices.Application.ActiveProject.ODTables
Dim findtable As String = "PortStanley_Roads"
Dim returnval As Integer = 0
Dim myReturnval As Integer = 0
Dim myRoadName As String = ""
'Dim theList As Object
Dim doc As acadapps.Document = acadapps.Application.DocumentManager.MdiActiveDocument
Dim db As acaddbs.Database = doc.Database
Dim tables As ObjectData.Tables = HostMapApplicationServices.Application.ActiveProject.ODTables
Dim odrec As ObjectData.Record
Dim theObjID As acaddbs.ObjectId
Dim ent As Object
'Dim ent As Line = New Line()
'Dim i As Integer
Using doclock As acadapps.DocumentLock = doc.LockDocument
Using mytx As acaddbs.Transaction = db.TransactionManager.StartTransaction
'theList = TableList.GetTableNames()
'For i = 0 To UBound(theList)
'MsgBox(theList(1))
'Next
'Open the Block table for read
Dim acBlkTbl As acaddbs.BlockTable = mytx.GetObject(db.BlockTableId, acaddbs.OpenMode.ForRead)
'Open the Block table record Modelspace for read
Dim acBlkTblRec As acaddbs.BlockTableRecord = mytx.GetObject(acBlkTbl(acaddbs.BlockTableRecord.ModelSpace), _
acaddbs.OpenMode.ForRead)
Dim odrecords As ObjectData.Records = tables.GetObjectRecords(0, acBlkTblRec.ObjectId, Constants.OpenMode.OpenForRead, False)
If odrecords.Count > 0 Then
For Each odrec In odrecords
If odrec.TableName.ToUpper = findtable.ToUpper Then
'returnval += 1
returnval = returnval + 1
End If
myReturnval = odrec.Count
myRoadName = odrec.Item(2).StrValue
If odrec.Item(2).StrValue = "" Then
MsgBox("The road examined is : " & myRoadName & " Road number: " & returnval)
theObjID = acBlkTblRec.ObjectId
MsgBox("The object ID is: " & theObjID.ToString)
ent = mytx.GetObject(theObjID, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, True)
MsgBox(ent.GetType().FullName.ToString)
End If
Next
End If
mytx.Abort()
End Using 'transaction
End Using 'document lock
MsgBox("The number of raods is : " & returnval)
MsgBox("The number of roadrecords is : " & myReturnval)
MsgBox("The last road examined is : " & myRoadName)
End Sub
End Class
To me, it is not so clear what exactly you need to find out:
Do you mean ALL entities in drawing (or ModelSpace) are supposed to be attached with ODRecord from ODTable "PortStanley_Roads"? In this case, you want to find any entity that does not have ORRecord from "PortStandley_Roads" attached (an entity may have no ODRecord attached at all, or may have more than one ODRecords attached from different ODTables).
Or, do you mean to find Entities with ODRecord from "PortStanley_Roads: attached, but the ODRecord's fields may be blank (or may not have expected values in the fields)? Iin this case, you are only interested in those entitiesd that has ODRecords from "PortStanley_Roads" table attached.
But either way, assume the entities are all in modelspace, you need to loop through all entities in the ModelSpace, not trying to find ODRecord on ModelSpace block itself as your code shows. That is, once you get ModelSpace BlockTableRecord (acBlkTblRec in your code), you need to:
For Each id As ObjectId in acBlkRec
''Get ODRecord against each entity represented by id
Next
Norman Yuan
Thank you for responding.
Yes, I would like to loop through all of the objects drawn in Modelspace and find those with no entry (NULL) in a field of an Object Data table.
What you describe in your second paragraph is correct:
"Or, do you mean to find Entities with ODRecord from "PortStanley_Roads: attached, but the ODRecord's fields may be blank (or may not have expected values in the fields)? Iin this case, you are only interested in those entitiesd that has ODRecords from "PortStanley_Roads" table attached."
When an OD field is found to have a record that is NULL (empty), I would like to identify the associated drawn object in Modelspace by having it change color toi RED or, perhaps, have it placed on a new layer called "NULL".