.NET

Reply
Valued Contributor
wbdehaan
Posts: 64
Registered: ‎11-01-2001
Message 1 of 6 (402 Views)

Drag drop item at specific point in AutoCad

402 Views, 5 Replies
06-17-2013 01:14 AM

Hi,

 

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.DocumentManager.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? 

 

kind regards,

 

Wouter de Haan

 

 

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 6 (349 Views)

Re: Drag drop item at specific point in AutoCad

06-19-2013 08:46 AM in reply to: wbdehaan

Can you give us a sample project to test with please?





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
wbdehaan
Posts: 64
Registered: ‎11-01-2001
Message 3 of 6 (331 Views)

Re: Drag drop item at specific point in AutoCad

06-20-2013 07:07 AM in reply to: fenton.webb

Hi,

 

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.

 

why:

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.

Valued Contributor
wbdehaan
Posts: 64
Registered: ‎11-01-2001
Message 4 of 6 (329 Views)

Re: Drag drop item at specific point in AutoCad

06-20-2013 07:08 AM in reply to: wbdehaan

 

additional: the Mtext in de upperleft corner, the crosshair where i dropped my item, and the circle drawn at the bottom

 

 

Naamloos.png

*Expert Elite*
norman.yuan
Posts: 993
Registered: ‎04-27-2009
Message 5 of 6 (319 Views)

Re: Drag drop item at specific point in AutoCad

06-20-2013 12:19 PM in reply to: wbdehaan

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.DoDragDrop(), which has different arguments from Windows.Forms.Control.DoDragDrop. You need to derive a class from Autodesk.AutoCAD.Windows.DropTarget as one of the argument for Application.DoDragDrop.

 

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:

 

http://drive-cad-with-code.blogspot.ca/2013/06/drag-something-and-drop-into-autocad.html

 

It may be helpful for what you are doing.

Valued Contributor
wbdehaan
Posts: 64
Registered: ‎11-01-2001
Message 6 of 6 (305 Views)

Re: Drag drop item at specific point in AutoCad

06-21-2013 07:18 AM in reply to: wbdehaan

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

 

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.