Manage XRef Draworder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The Task
I've been tasked with replicating an old VBA tool in C# .NET.
Unfortunately all I've got is a screen capture of the form and a description of the purpose, so I don't even have the old VBA as a reference.
The VBA tool was used to manage the draw order of XRefs in a drawing.
It presented a list of the XRefs with buttons for 'Move To Top', 'Move Up', 'Move Down', 'Move To Bottom'.
The XReferences palette doesn't let you do this. Otherwise you're left with using the DRAWORDER command.
If someone's already done this, fine. I'd still like to understand what's required to code it.
So Far
I can fairly easily get and present a list of the xrefs in a drawing.
I worked out that a TreeView worked well, as it easily allowed drag-n-drop reordering of the files in the list, eliminating the 'Move...' buttons.
Each node can also carry the XrefGraphNode object as its Tag, making it possible to get at the objects again.
Then all I've done is add 'Update' and 'Close' buttons.
I've got the xrefs in the tree, and I'm throwing the XrefGraphNode's 'Database' property at a PropertyGrid I'm using for diagnostics at the moment:
So I'm at the point where I'm trying to change the draw order of the Xrefs. This is where it's 'going to pot'.
The Problem(s)
I've had a look at a couple of articles:
- http://through-the-interface.typepad.com/through_the_interface/2013/05/fixing-autocad-drawings-expor...
- http://adndevblog.typepad.com/autocad/2012/06/setting-relative-draw-order-of-entities-using-net.html
They have given me the general idea, without helping with the specifics.
I've got two questions:
- How can I get the existing draworder of the xrefs so that I can display them in the correct order in the TreeView?
- I suspect that the order they're retrieved has more to do with the order they were attached, than their existing draworder. I'm having trouble proving otherwise.
- How do I actually update the draworder for the xrefs?
- Here's the code for the 'Update' button cribbed and adapted from the articles above:
private void buttonUpdate_Click(object sender, EventArgs e) { using (Transaction t = db.TransactionManager.StartTransaction()) { var objectIDs = new ObjectIdCollection(); foreach (TreeNode node in treeViewXRefs.Nodes) { objectIDs.Add(((XrefGraphNode)node.Tag).BlockTableRecordId); } for (int oi = 0; oi < objectIDs.Count; oi++) { ObjectId objectID = objectIDs[oi]; var btr = (BlockTableRecord)t.GetObject(objectID, OpenMode.ForRead); var xrColl = new ObjectIdCollection(); xrColl.Add(objectID); var dot = (DrawOrderTable)t.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite); if (oi == 0) dot.MoveToTop(xrColl); else dot.MoveBelow(xrColl, objectIDs[oi - 1]); } } }
When this runs, I get all the way to 'dot.MovetoTop...' and get an 'eInvalidInput' error.
All I need is the nudge, or clue that gets me past my blockages, and I think I'm done. Famous last words!!