Consulting

Results 1 to 6 of 6

Thread: How to control AutoCad LT with Visual Basic 6

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    Wink How to control AutoCad LT with Visual Basic 6

    i have autocad2007 and autocad LT 2006 in my system i want to open dwg files in autccad Lt 2006 using vb.6 code.

    i want to modify the above code and open dwg drawings in Lt

    above code will open drawing in autocad2007


    Dim DwgName As String
            On Error Resume Next
            Set acadApp = GetObject(, "AutoCAD.Application")
    If Err Then
       Set acadApp = CreateObject("AutoCAD .Application")
       Err.Clear
            End If
    '        If Right(App.Path, 1) = "\" Then
       '            DwgName = "C:\13027167-GX2.dwg"
       '        Else
       '            DwgName = "C:\13027167-GX2.dwg"
    '        End If
            Set acadDoc = acadApp.ActiveDocument
            If acadDoc.FullName <> DwgName Then
       acadDoc.Open DwgName
            End If
            Dim str As String, str1 As String
            str1 = "_-insert" & vbLf & """" & "C:\14001120-AA8232-AC8232-AZ665.dwg" & """" & vbLf & "0,0,0" & vbLf & vbLf & vbLf & vbLf & "z" & vbLf & "a" & vbLf
            'str = "dwin" & vbLf
            acadDoc.SendCommand str1
           ' acadDoc.SendCommand str
    acadApp.Visible = True
    Last edited by Aussiebear; 04-11-2023 at 05:23 AM. Reason: Adjusted the code tags

  2. #2
    Afternoon Sam.

    If AutoCad is similar to Microsoft Office, the Class Type references only the most current version installed, which would be AutoCad 2007 in your case. Fortunately, the first Argument for GetObject is Path. If you execute GetObject("C:\ProgramFiles\AutoCad LT 2006\AutoCad.exe") or whatever the path is, it should only get the AutoCad LT 2006 version.

    Hope that helps you some.
    Scott
    You don't understand anything until you learn it more than one way. ~Marvin Minsky

    I never teach my pupils; I only attempt to provide the conditions in which they can learn. - Albert Einstein

  3. #3
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi scott

    nice to hear from u....

    autocad LT do not support vb in its present version..this is the response i got from the autodesk customer support...
    now i need to find different approach..

    have a good day scoot

  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi shamsam1,

    This is correct, you cannot control Autocad LT with the createobject/getobject methods. You can however write a script that will open Autocad LT and insert the drawing(s) that you want and close it.

  5. #5
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    i am using script file(.scr file) to pass value

    C:\Program Files\AutoCAD LT 2006\aclt C:\1.dwg /b c:\script.scr
    first time when i pass value value ,autocad lt will open and in that i am inserting some dwg file

    if i pass value for second time its opening new autocad lt window and it will inset the drawing

    i dont want to open new window if autocadlt is open already i want to insert dwg file in active winodw

  6. #6
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    This is because you are not closing the acad lt. In the script file (.scr) you will need to send all of the commands that are required for that drawing. Calling acad lt from the command line (which is the only way I know of to do this) means that it is all by itself and you have no control. So in the script file close acad after the commands are through. Then start another script. To repeat you cannot reuse an existing instance of acad lt via a script file or anything else other than human intervention.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •