I would like to use the behaviour of "drag and drop" into AutoCad (from a listbox in a form) at a specific point, I do not need to drop anything into AutoCad, I just need the exact point of the mouseposition converted to WCS in autocad.
the below code works, but i do not get the correct point in AutoCad.
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.D
ocumentManager.MdiActiveDocument.Editor '---now i drop listbox-text in autocad, DoDragDrop(ListBox1.Text, DragDropEffects.Copy) Dim pt As Point3d = ed.PointToWorld(New Point(CInt(MousePosition.X), CInt(MousePosition.Y))) '---draw circle ModelspaceAdd(Teken.Cirkel(pt(0), pt(1), 100)) End Sub
(Maybe it is possible to just change the mouse-cursor, but it doesn't 'lock' the selected item in the listbox, as if it was dragged into the drawing.)
can somebody please help me?
Wouter de Haan
the attached project is a simplified version. It now is possible to drag text into the drawing, but the location of the drawn circle is incorrect (maybe because I'm working with two 23" displays), and the text of the listbox is also pasted as mtext in the drawing.
this is what I would like:
Only draw a circle at the exact given point, and no additional listbox text in the drawing.
I have written a macro, in which I can select different items from the listbox into the drawing, Autocad 'knows' at which point the user dropped the item, and i can draw parametric products at the given point, depending on the drawing already created.
The reason the circle is drawn far off where you drag and drop is that your code used wrong DODragDrop() method, and also might because you used wrong mouse cursor location.
In your ListBox1_MouseDown() event handler:
DoDragDrop() method is the member of System.Windows.Forms.Control. That is you call this method when you intend to drag somerhing and drop it onto a Windows.Form/Control.
While what you want is to drag and drop into AutoCAD. So, you need to call Autodesk.AutoCAD.ApplicationServices.Application.D
Since your code is for dropping the dragged data onto the form, not onto AutoCAD, thus the wrong location.
The other reason: you get the mouse cursor location from the form's MousePosition property, which is the cursor's relative position on the form, not the screen position. But this error is irrelavent, because of calling wrong DoDragDrop() method.
Seeing your question unanswered for 2 days, I wrote on this topic in my blog here:
It may be helpful for what you are doing.
Hi Norman Yuan,
thank you for your answer and complete solution. Unfortunately, since i'm rather new to vb.net (converting my macro's from VBA to .Net), when trying to convert your code from C to .net, I keep getting error's. next week I'm going to try again. I'll let you know..have a nice weekend,
kind regards, Wouter
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register