- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
in my ACAD Plugin I want to be able to drag some selected Objects from the Editor into my WPF TreeView which is located in a PaletteSet. In the drop handler i need an array filled with the ObjectId's. I've googled for ages but I've only found snippets to do the opposite.
I'm using this great DnD Framework. My first attempt was to just look whats in the data object of the drop handler. It wasn't null - thats great. It was a System.Windows.DataObject and its GetFormats() method returned this list:
data.GetFormats()
{string[9]}
[0]: "Embed Source"
[1]: "Object Descriptor"
[2]: "MetaFilePict"
[3]: "Link Source"
[4]: "Link Source Descriptor"
[5]: "Bitmap"
[6]: "System.Drawing.Bitmap"
[7]: "System.Windows.Media.Imaging.BitmapSource"
[8]: "AutoCAD.r22"
So I saw the "AutoCAD.r22" format and thought "that must be it!" and called the GetData(string format, bool autoConvert) method of the DataObject: GetData("AutoCAD.r22", true)
and received a MemoryStream. I've created a Byte[] from that and saved it to a file. Then i've looked into the file with a Hex Editor to search for the ObjectId of the Object I've dropped... but no success. In my desperation I've done the same with the other formats - but no luck. At least i can now use the DataObject to determine if the Drop came from the ACAD Editor by checking for the "AutoCAD.r22" format string.
Then I saw the Editor.Dragging and Editor.DragEnded events and thought "ugh, I'm so dumb". The documentation says "Occurs when a dragging operation is performed in a drawing". That must be it!
But it seemed to never fire! My blood pressure starts to grow while I realized that I'm already hours into this "simple task". I've forgot my breakpoint inside the Editor.Dragging event and found out by accident that this event should be called Editor.Jigging because it's raised when a Jig is rendering while you move your Mouse.
My third attempt was to assume that, if the drop handler receives a ACAD drop, the dropped objects must be those who are currently selected, right? So... just query the Editor whats selected, right? Easy! ... No its not...
So after asking some kind people here in this Forum, I've learned that i can query the selected Objects by calling Editor.SelectImplied() but this must be inside a Command Method that has the CommandFlags.UsePickSet in its CommandMethod Attribute. So I've created a static method in my UserControl that can be called from this Command to do the ACAD Drop and pass the ObjectID's. In my drop handler i check if the drop came from acad, call the command by Document.SendStringToExecute() and return from my drop handler. But every time my Command was executed, there was nothing selected! And do you want to know why? Because ACAD is deselecting everything in the moment you start the dragging!! At this moment my veins where clearly visible...
So this also wasn't possible.
My last and currently woking attempt is to monitor the selected Objects with the Editor.SelectionAdded event and maintain a static List<ObjectId>. This approach doesn't make me happy because thats really dirty and can cause a lot of issues. Is there really no way to do this clean?
Solved! Go to Solution.