Wednesday, 21 August 2013

How to open the existing AutoCAD drawing using VB.NET /C# windows forms Or VB.NET / C# - Open an Existing Dwg from Stand-Alone exe

                               Hi friends, in this article I will explain about how to open the existing AutoCAD drawing using VB.NET /C# windows forms or VB.NET / C# - Open an Existing Dwg from Stand-Alone exe
Lets I will explain about Open A Drawing in VB.NET /C# as shown below.
Take one new project (File—New—Project—give a name to form).A form will be made.
We have to add the below references to project. I explained in the previous article How to add references for AutoCAD ,How to call LispProgram from VB.NET ? || Calling AutoCAD commands from .NET.
1. AutoCAD 2007/2010 Type Library
2. AutoCAD/ObjectDBX Common 17.0/18.0 type Library from COM tab.
3. acdbmgd.dll
4. acmgd.dll
And double click on the form and right the following code.
In VB.NET:
Public Class Form1
    Public AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
    Public AcadDoc As Autodesk.AutoCAD.Interop.AcadDocuments
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As system.EventArgs)   Handles MyBase.Load
         Dim AcadApp, NewFile As Object
        On Error Resume Next
        AcadApp = GetObject(, "autocad.Application")
        If Err.Number <> 0 Then
            Err.Clear()
            AcadApp = CreateObject("autocad.Application")
        End If

        AcadApp.Visible = True
        Err.Clear()
        NewFile = AcadApp.Documents.Open("c:\test.dwg", False)
        Dim command As String = "(load ""D:/test.vlx"")"
        NewFile.SendCommand(command & "(C:test) ")
    End Sub
End Class

In C#:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
Public Class Form1
{
      public Autodesk.AutoCAD.Interop.AcadApplication AcadApp;
      public Autodesk.AutoCAD.Interop.AcadDocuments AcadDoc;
      private void Form1_Load(System.Object sender, System.EventArgs e)
      {
            object AcadApp = null;
            object NewFile = null;
             // ERROR: Not supported in C#: OnErrorStatement

            AcadApp = Interaction.GetObject(, "autocad.Application");
            if (Err().Number != 0) {
                  Err().Clear();
                  AcadApp = Interaction.CreateObject("autocad.Application");
            }

            AcadApp.Visible = true;
            Err().Clear();
            NewFile = AcadApp.Documents.Open("c:\\test.dwg", false);
            string command = "(load \"D:/test.vlx\")";
            NewFile.SendCommand(command + "(C:test) ");
      }
    Public Form1()
      {
            Load += Form1_Load;
      }
}


If you like my blog Aspdotnet-Roja then why are you waiting like my blog through facebook page Aspdotnet-Roja

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.