0

I'm hosting my .Net ListView control using PalettSet in AutoCAD 2012. The Tag property of ListView items holds the path to *.dwg files. I want to drag from ListView, while picking the dwg file using Item.Tag property and drop it on AutoCAD drawing area and I'm expecting the result would be the drawing would be inserted there just like we normally drag a *.dwg file and drop it on drawing area

I've read about Drag and Drop Blocks using Jig Class and I tried some sample code but using built-in Circle class.

Do I have to first read Blocks from dwg file and then attached to mouse and do the drag and drop operation?

I'm actually confused...

Can someone please guide me? Would really appreciate your replies...

Thanks a bunch....

Farrukh

Farrukh Waheed
  • 2,163
  • 2
  • 29
  • 59

1 Answers1

0

Finally I solved this, but after some long research and code testing. I wrote code (by reading multiple blogs) which would insert the Block from *.dwg file into current AutoCAD document, but then I realize that many Blocks contains Attributes and some might need to be handled while adding dwg.

So finally, I decided to call INSERT command of AutoCAD, instead writing my own code. Here is the code for other fellows.

Please note that here I'm making it an example while hard-coding dwg file name and path, while in my real application, DWG file path would be read from ListBox.Tag property.

[CommandMethod("InsertDWG")]
static public void SendCmd()
{
    string DWGFile = @"D:\sym\1047.DWG";
    string InsertCmd = @"_.-INSERT " + DWGFile + '\r' + '\n';
    Document doc = Application.DocumentManager.MdiActiveDocument;
    doc.SendStringToExecute(InsertCmd, true, false, false);
}

Note: You should keep '\r' + '\n' (Will act as Enter or Carriage Return) with SendStringToExecute() method, or AutoCAD would get the command string, but will wait for user input.

Hope this would be beneficial for someone.

Best regards Farrukh

Farrukh Waheed
  • 2,163
  • 2
  • 29
  • 59