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
In previous article I already explained about How to addreferences for AutoCAD, How to call Lisp Program from VB.NET ? || CallingAutoCAD commands from .NET, How to open new drawing using VB.NET or C#? Or How to Connect with AutoCAD and Open A Drawing in VB.NET /C# .
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