.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drag drop item at specific point in AutoCad

5 REPLIES 5
Reply
Message 1 of 6
wbdehaan
992 Views, 5 Replies

Drag drop item at specific point in AutoCad

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

 

 

 

5 REPLIES 5
Message 2 of 6
fenton.webb
in reply to: wbdehaan

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




Fenton Webb
AutoCAD Engineering
Autodesk

Message 3 of 6
wbdehaan
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.

Message 4 of 6
wbdehaan
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

Message 5 of 6
norman.yuan
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.

Message 6 of 6
wbdehaan
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

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost