locked
Preview an AutoCAD drawing?

    Question

  • Hey guys, i've only recently started using C# and like it a lot so far. However, i'm having a couple of troubles with my program...

     

    I wish to have a listbox, which reads files in a specified folder with the .dwg (CAD drawing) extension. Also when i click on a file in this listbox, i'd like (if possible) to load a preview of the CAD drawing in a picturebox or something similar next to the listbox.

     

    Any feedback or help on what code to add would be great. Please tell me if i have been too vague.

     

    Thanks in advance,

    lukz33mts

    Saturday, July 21, 2007 10:40 PM

Answers

  • Hi,

     

    1   You need to populate your listbox control by using DirectoryInfo and FileInfo class. Here is simple code to populate listbox control with text file.

    2   You need to use AutoCAD software to preview .dwg file. In example I use notepad.exe to open text file. Put your AutoCAD preview exe file and dwg file into Process.Start() method.

    Code Snippet

    private void Button1_Click(object sender, System.EventArgs e)

    {

                 DirectoryInfo di = new DirectoryInfo("c:\\temp\\");

                 foreach (DirectoryInfo fdi in di.GetDirectories()) {

                                 foreach (FileInfo fs in fdi.GetFiles()) {

                                                 string[] str = fs.Name.Split(".");

                                                 string ext = Conversion.str(1).Trim;

                                                 string ext1 = ext.ToLower;

                                                 if ((ext1 == "txt"))

                                                 {

                                                                 ListBox1.Items.Add((object)fs.FullName);

                                                 }

                                 }

                 }

    }

    private void ListBox1_DoubleClick(object sender, System.EventArgs e)

    {

                 Process.Start("notepad.exe", ListBox1.SelectedItem.ToString());

    }

     

    Good luck

    Monday, July 23, 2007 6:17 AM

All replies

  • Hi,

     

    1   You need to populate your listbox control by using DirectoryInfo and FileInfo class. Here is simple code to populate listbox control with text file.

    2   You need to use AutoCAD software to preview .dwg file. In example I use notepad.exe to open text file. Put your AutoCAD preview exe file and dwg file into Process.Start() method.

    Code Snippet

    private void Button1_Click(object sender, System.EventArgs e)

    {

                 DirectoryInfo di = new DirectoryInfo("c:\\temp\\");

                 foreach (DirectoryInfo fdi in di.GetDirectories()) {

                                 foreach (FileInfo fs in fdi.GetFiles()) {

                                                 string[] str = fs.Name.Split(".");

                                                 string ext = Conversion.str(1).Trim;

                                                 string ext1 = ext.ToLower;

                                                 if ((ext1 == "txt"))

                                                 {

                                                                 ListBox1.Items.Add((object)fs.FullName);

                                                 }

                                 }

                 }

    }

    private void ListBox1_DoubleClick(object sender, System.EventArgs e)

    {

                 Process.Start("notepad.exe", ListBox1.SelectedItem.ToString());

    }

     

    Good luck

    Monday, July 23, 2007 6:17 AM
  • Thanks a lot, i'll give this a go tonight. Seems like it should do the trick.



    Hehe, im glad i asked i would have spent ages googling for this Wink



    greets, lukz33mts

    Tuesday, July 24, 2007 6:01 PM