Starting shell command with Visual Basic

Starting shell command with Visual Basic

Anonymous
Not applicable
516 Views
7 Replies
Message 1 of 8

Starting shell command with Visual Basic

Anonymous
Not applicable
I am trying to start AutoCAD 2000 with a Visual Basic program using the Shell Command.
On one computer this works fine, but the other computer it will not work at all.
I have narrowed it down to AutoCAD not wanting to start, I think, because I can start notepad just fine.
I am trying to start ACAD and then have it run a script file immediately.

Any help would be greatly appreciated.
0 Likes
517 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
You'd have better luck in the VBA group.

VISUAL BASIC CUSTOMIZATION
The Visual Basic Customization newsgroup can be accessed in
either of the following ways:
By NNTP newsgroup reader at
news://discussion.autodesk.com/autodesk.autocad.customization.vba
By HTTP (web-based) interface at
http://discussion.autodesk.com/WebX?14@@.ee77f0d

--

-Jason
Member of the Autodesk Discussion Forum Moderator Program


"mantin999" wrote in message
news:f14aa6b.-1@WebX.maYIadrTaRb...
> I am trying to start AutoCAD 2000 with a Visual Basic program
using the Shell Command.
> On one computer this works fine, but the other computer it will
not work at all.
> I have narrowed it down to AutoCAD not wanting to start, I
think, because I can start notepad just fine.
> I am trying to start ACAD and then have it run a script file
immediately.
> Any help would be greatly appreciated.
>
>
0 Likes
Message 3 of 8

Anonymous
Not applicable
Load the acad.tlb library so AutoCAD is exposed to Visual Basic

Dim acadOBJ as AutoCAD.Application

'Visual Basic 6.0
Set acadOBJ = createObject(, "AutoCAD.Application")

' Visual Basic.NET
acadOBJ = createObject(, AutoCAD.Application)

acadObj.Visible = true


Now AutoCAD is started and visible

"Jason Piercey" wrote in message
news:8959DD0C03F883C4A5FDF9E8A761D8AC@in.WebX.maYIadrTaRb...
> You'd have better luck in the VBA group.
>
> VISUAL BASIC CUSTOMIZATION
> The Visual Basic Customization newsgroup can be accessed in
> either of the following ways:
> By NNTP newsgroup reader at
> news://discussion.autodesk.com/autodesk.autocad.customization.vba
> By HTTP (web-based) interface at
> http://discussion.autodesk.com/WebX?14@@.ee77f0d
>
> --
>
> -Jason
> Member of the Autodesk Discussion Forum Moderator Program
>
>
> "mantin999" wrote in message
> news:f14aa6b.-1@WebX.maYIadrTaRb...
> > I am trying to start AutoCAD 2000 with a Visual Basic program
> using the Shell Command.
> > On one computer this works fine, but the other computer it will
> not work at all.
> > I have narrowed it down to AutoCAD not wanting to start, I
> think, because I can start notepad just fine.
> > I am trying to start ACAD and then have it run a script file
> immediately.
> > Any help would be greatly appreciated.
> >
> >
>
>
0 Likes
Message 4 of 8

Anonymous
Not applicable
I did the following and it worked on one computer, but another computer it didn't work.
It came back with:
Runtime error 429
Active X Component can't create object.

>Load the acad.tlb library so AutoCAD is exposed to Visual >Basic
>Dim acadOBJ as AutoCAD.Application
>'Visual Basic 6.0
>Set acadOBJ = createObject(, "AutoCAD.Application")
>' Visual Basic.NET
>acadOBJ = createObject(, AutoCAD.Application)
>acadObj.Visible = true
>Now AutoCAD is started and visible
0 Likes
Message 5 of 8

Anonymous
Not applicable
Do you have the same versions of AutoCAD loaded [or AC loaded at all the second machine]? What about their installation location? Are they the same? Are you using a hardcoded path in your application? More complete code example might help determine the challenge.

Joe
--
0 Likes
Message 6 of 8

Anonymous
Not applicable
Below is the actual code used.

Dim iRetVal As Long
Dim sFileExists As String
.
.
.
.

sFileExists = Dir("c:\acad2000\acad.exe")
If sFileExists <> "" Then
iRetVal = Shell("c:\acad2000\acad.exe" & " /b " & _
"c:\work\scriptwriter.scr", vbMaximizedFocus)
End If

If I make a shortcut to ACAD with the following target:
C:\ACAD2000\acad.exe /b c:\work\SCRIPTWRITER.scr
it executes correctly.
0 Likes
Message 7 of 8

Anonymous
Not applicable
Try this ...
'***************************
Function LaunchScriptFile(sScriptName as String, WindowStyle as vbwindowstyle
) as boolean

on error goto LaunchScriptFileEH

Dim Dim cmd as string
Dim fso As New scripting.FileSystemObject

If fso.FileExists("C:\Program Files\AutoCAD 2002\ACAD.EXE") = True then
cmd = """C:\Program Files\AutoCAD 2002\ACAD.EXE"" /nologo /b """ & sScriptName & """"
Shell cmd, WindowStyle
LaunchScriptFile = True
else
LaunchScriptFile = False
endif

set fso = nothing

exit function

LaunchScriptFileEH:
LaunchScriptFile = False

exit function
'***************************
0 Likes
Message 8 of 8

Anonymous
Not applicable
OK, read the attached .txt since the formatting got smashed.
0 Likes