Code Red > .NET
Getting extremely "large" negative block referece handles
Nightcrawler:
When I get handles for block references they usually look something like 153919. But for certain files I get handles that look like -4066801656873546453!
And when I try to get the block reference by that handle it throws an "eUnknownHandle" and crashes my AutoCAD instance.
--- Code: ---long handle = -4066801656873546453;
Handle hn = new Handle(handle);
ObjectId blockId = sideDb.GetObjectId(false, hn, 0); // Crashes here!
--- End code ---
It seems like a fairly uncommon issue as I've processed thousands of files without any problems. And even files in the same project works.
Anybody knows why this occurs, and what can I do to get the block reference when this occurs?
dgorsman:
Where are these handles coming from - xdata? Xrecords?
Rough guess, if from those there was some bad code modifying the wrong variable resulting into an unusable number or causing a numeric overflow from data type restrictions. Either way there is no way of getting the actual handle value back.
huiz:
Maybe you can fix it with the Audit command.
The large number looks like the minimum value of a long. It is negative and thus not valid. It might get fixed.
Nightcrawler:
@dgorsman I'm not sure what they are called tbh. I'm fairly inexperienced with the Autocad API, but this is how I get them:
--- Code: ---using (var transaction = db.TransactionManager.StartTransaction())
{
var layoutEntries = transaction.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
foreach (DBDictionaryEntry layoutEntry in layoutEntries)
{
var layout = transaction.GetObject(layoutEntry.Value, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Layout;
var fileRecords = transaction.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId id in fileRecords)
{
var blockRef = transaction.GetObject(id, OpenMode.ForRead) as BlockReference;
var handle = blockRef.Handle.Value,
var name = blockRef.Name,
...
}
}
transaction.Abort();
}
--- End code ---
@huiz, that's not a bad guess, but when I look at a couple of other handles I see values like -4066801656856679638, -4066801656856679152, -646675092. So not all are the same.
Running AUDIT on the model, as well as RECOVERALL I get this output "objects auditedAcDbBlockTableRecord: "A$C431C598E", XData Handle Unknown, Null" and then Autocad just hangs...
gile:
Hi,
Try replacing:
--- Code - C#: ---var blockRef = transaction.GetObject(id, OpenMode.ForRead) as BlockReference;var handle = blockRef.Handle.Value,var name = blockRef.Name,with:
--- Code - C#: ---var blockRef = transaction.GetObject(id, OpenMode.ForRead) as BlockReference;if (blockRef != null){ var handle = blockRef.Handle.Value; var name = blockRef.Name; // ...}because layout's block table records contain entities which are not block references (at least one Viewport).
Navigation
[0] Message Index
[#] Next page
Go to full version