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

How to drag and drop block in Autocad by C#.

24 REPLIES 24
Reply
Message 1 of 25
yuh0317
2382 Views, 24 Replies

How to drag and drop block in Autocad by C#.

Hi All,

I want to drag and drop a block which get from dwg. But I don't know how to create drag and drop "DataObject", please see the following code.

new System.Windows.DataObject(DataFormats.FileDrop, new string[] { fullpath }); It is OK for drag and drop a dwg file, but it is not OK for drag and drop a block. Could you give me a sample about this.

Thanks,
Hongdan
24 REPLIES 24
Message 21 of 25
Anonymous
in reply to: yuh0317

{quote}

Attached is an example of the wpf drag-drop and how to pick it up and do a
block jig.

{quote}

Sorry, what you posted is not 'drag and drop' at all.

What you posted is an example of calling your own partially-implemented
version of the AutoCAD INSERT command, when the right mouse button is
released, after it was pressed while the cursor was over an item in a list.

That is not drag and drop.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6307673@discussion.autodesk.com...
Sorry for the delay - too many things going on getting ready for the
holidays. Attached is an example of the wpf drag-drop and how to pick it up
and do a block jig. In the code behind for the wpf control, there is a
constant value that points to a folder that contains drawings. You will need
to change the path to a folder that has drawings in it on your pc. Then
compile and run the app to test it and see how it works. The sample is done
in vb.net but there are plenty of converts available on the 'net.

Mike
Message 22 of 25
mike.tuersley
in reply to: yuh0317

That is the workaround supplied by the senior AutoCAD architect, Tony. If you can get drag-n-drop to work with 100% WPF, then by all means, lets see it.

As I stated, the problem is the drop mechanism in cad does not accept dataobjects which come from WPF and there is no way to convert a dataobject to an idataobject.
Message 23 of 25
Anonymous
in reply to: yuh0317

{quote}

That is the workaround supplied by the senior AutoCAD architect, Tony.

{quote}

Are you saying Albert wrote that?

If he didn't write it, then what exactly did he 'supply' ?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
Message 24 of 25
mike.tuersley
in reply to: yuh0317

Yes. Here is what I received - it differs from the posted example because my project drops a class object which contains metadata [site location to download the block, part data to write in as xrecord, etc.] I tweaked the example to use just the string but you can see I followed the same logic supplied here:

Quote:
When you addd the ListboxItem - be it a icon or text, at that point set the Tag = MyClass

MyClass
{
string URL;
string partNumber;
}

In your StartDrag e.SOurce = listboxitem that is dragged, retrieve Tag into MyClass

MyClass = e.Source.Tag

sendStringToExecute("mycommand www.ttt.co, partno");

MyCommand
Getstring(URL)
GetString(Partno);
StartJig

:End Quote

Obviously, I would prefer a true drag-n-drop solution but I did not have the time to pursue it further and, honestly, trying to supply a converter between the two types is beyond my comfort level. Albert liked this better than a couple other ideas I had because in my case, the user could hit enter to repeat the insert process "...just like a native command". The data-idata has been logged as a defect and will be corrected at some point.
Message 25 of 25
Anonymous
in reply to: yuh0317

Mike - Regardless of where it came from, what you describe and subsequently
posted code for is not drag and drop.

Your code just runs a watered-down version of the INSERT command when the
user clicks a list item. So in otherwords, what you charcterize as a
'workaround' [for broken WPF drag and drop], amounts to not supporting drag
and drop at all.

That's no workaround. The workaround is to use the WinForms version of the
DoDragDrop() method as I mentioned earlier. I'm not sure where you got the
idea that there's some cost to referencing System.Windows.Forms.dll, because
AutoCAD loads and uses it anyway, so it's free.

Of course, you're free to use whatever approach you wish, but the point to
my comment is that what you posted for the OP is not a workaround that
allows them to use drag and drop.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6308388@discussion.autodesk.com...
Yes. Here is what I received - it differs from the posted example because my
project drops a class object which contains metadata [site location to
download the block, part data to write in as xrecord, etc.] I tweaked the
example to use just the string but you can see I followed the same logic
supplied here:

Quote:
When you addd the ListboxItem - be it a icon or text, at that point set the
Tag = MyClass

MyClass
{
string URL;
string partNumber;
}

In your StartDrag e.SOurce = listboxitem that is dragged, retrieve Tag into
MyClass

MyClass = e.Source.Tag

sendStringToExecute("mycommand www.ttt.co, partno");

MyCommand
Getstring(URL)
GetString(Partno);
StartJig

:End Quote

Obviously, I would prefer a true drag-n-drop solution but I did not have the
time to pursue it further and, honestly, trying to supply a converter
between the two types is beyond my comfort level. Albert liked this better
than a couple other ideas I had because in my case, the user could hit enter
to repeat the insert process "...just like a native command". The data-idata
has been logged as a defect and will be corrected at some point.

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