Tuesday, July 17, 2007

Launch AutoCAD 2004 from VB.NET

' Get the active session of AutoCAD 2004 using late binding AcadApp = GetObject(, "AutoCAD.Application.16") If Err.Number <> 0 Then Err.Clear() Shell("c:\Program Files\Common Files\Autodesk Shared\WSCommCntr1.exe", AppWinStyle.NormalFocus) ' Create a new session of AutoCAD 2004 using late binding AcadApp = CreateObject("AutoCAD.Application.16") If Err.Number <> 0 Then MsgBox("Error, could not create a new AutoCAD session") End End If End If AcadApp.Visible = True

The workaround seems to be to start WSCommCntr1.exe before running CreateObject.

This is probably true for AutoCAD 2005 as well as if done using VB6.

1 comment:

  1. Hi, I have a problem with the use of late binding when I try to use ActiveDimStyle and assign other object that was created using the method Add.

    the code is:

    Dim acApp as Object
    Dim acDoc as Object
    Dim newDimStyle as Object

    /***** Here the code mentioned in this post ******/

    AcDoc = AcApp.ActiveDocument
    newDimStyle = acDoc.DimStyles.Add("MyStyle")
    AcDoc.ActiveDimStyles = newDimStyle

    The problem is an exception of COM Objects.

    ReplyDelete