PDA

View Full Version : [SOLVED] How to control AutoCad LT with Visual Basic 6



shamsam1
12-16-2008, 04:17 AM
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 :beerchug:



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

Demosthine
12-17-2008, 04:21 PM
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

shamsam1
12-17-2008, 09:09 PM
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

Tommy
12-18-2008, 06:06 AM
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.

shamsam1
12-18-2008, 10:21 PM
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

Tommy
12-19-2008, 06:26 AM
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.