How to open AutoCAD drawing in AutoCAD 2002 using VB?

How to open AutoCAD drawing in AutoCAD 2002 using VB?

Anonymous
Not applicable
541 Views
8 Replies
Message 1 of 9

How to open AutoCAD drawing in AutoCAD 2002 using VB?

Anonymous
Not applicable
I'm a beginner and I manage to open AutoCAD 2002 program but was unable to open the specific drawing. Why is that so? Please advise....

Thank you.
0 Likes
542 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
if you are working in mdi-mode, you have to use the open-method from
"Documents"-collection

myApp.Documents.Open .....

- alfred -

On Sun, 17 Nov 2002 07:57:19 -0800, lyz77 wrote:

>I'm a beginner and I manage to open AutoCAD 2002 program but was unable to open the specific drawing. Why is that so? Please advise....

Thank you.


- alfred -

0 Likes
Message 3 of 9

Anonymous
Not applicable
I'm not real familiar with using VB
to automate AutoCAD but the "Open Method" topic in the VBA Reference
states:

 

"When working in MDI mode you should always use the Open method from the
Documents collection. When working in SDI mode, use the Open method from the
Document object."

 

Therefore, you may need to
use:

   

    If Err Then

        '...

    End If

 

    If myDoc.Name <> "Borelog1_20.dwg" Then

        Set myDoc = myApp.Documents.Open
("E:\ADCS\CS220\Coding\Project\Econ\Borelog1_20.dwg")

    Else

   
face="Times New Roman">     Set
myDoc = myApp.ActiveDocument

    End If

 

    point1(0) = 1600: point1(1) = -4000: point1(2) =
0
    point2(0) = 17000: point2(1) = 4000: point2(2) =
0
    ' Zoom out to encapsulate view of map in VB
form.
    myDoc.ActiveViewport.ZoomWindow point1,
point2
    myApp.Visible = True

Steve Howatt

CAD Manager

Perkins & Will

Minneapolis


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I'm
a beginner and I manage to open AutoCAD 2002 program but was unable to open
the specific drawing. Why is that so? Please advise....

Thank you.





Sub LoadDwg()
On Error Resume Next
' Get the AutoCAD Application
object if AutoCAD is running.
Set myApp = GetObject(,
"AutoCAD.Application")
    If Err
Then
       
Err.Clear
        ' Start AutoCAD if it
is not running.
        Set myApp =
CreateObject("AutoCAD.Application")
       
If Err
Then
           
MsgBox
Err.Description
           
Exit Sub
        End
If
    End If
    Set myDoc =
myApp.ActiveDocument
    ' Open the drawing if it is not
already open.
    If myDoc.Name <> "Borelog1_20.dwg"
Then myDoc.Open
("E:\ADCS\CS220\Coding\Project\Econ\Borelog1_20.dwg")
   
point1(0) = 1600: point1(1) = -4000: point1(2) = 0
   
point2(0) = 17000: point2(1) = 4000: point2(2) = 0
    '
Zoom out to encapsulate view of map in VB form.
   
myDoc.ActiveViewport.ZoomWindow point1, point2
   
myApp.Visible = True
End Sub
0 Likes
Message 4 of 9

Anonymous
Not applicable
Alfred

'Are you running 2000 or 2002?

'Create a form and commandbutton

'Change the path hereunder to your AutoCAD path, and use the
shell.

'you have to use the vb-Max-focus so AutoCAD will not be
docking in the background.

 

Private Sub Command1_Click()
Shell "C:\r02\acad.exe ",
vbMaximizedFocus
End Sub

Hope it help

MAK


________________________________
I will not accept
Email or attachment
I will not take the risk of
viruses.
_______________________________
`·.¸.-*`"0MAK0"`*-.¸.·´
``o000o.^\/^.o000o``
_
VB6- CAD2002 _________________


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

I'm not real familiar with using VB
to automate AutoCAD but the "Open Method" topic in the VBA Reference
states:

 

"When working in MDI mode you should always use the Open method from the
Documents collection. When working in SDI mode, use the Open method from the
Document object."

 

Therefore, you may need to
use:

   

    If Err Then

        '...

    End If

 

    If myDoc.Name <> "Borelog1_20.dwg" Then

        Set myDoc =
myApp.Documents.Open
("E:\ADCS\CS220\Coding\Project\Econ\Borelog1_20.dwg")

    Else

   
face="Times New Roman">     Set
myDoc = myApp.ActiveDocument

    End If

 

    point1(0) = 1600: point1(1) = -4000: point1(2) =
0
    point2(0) = 17000: point2(1) = 4000: point2(2) =
0
    ' Zoom out to encapsulate view of map in VB
form.
    myDoc.ActiveViewport.ZoomWindow point1,
point2
    myApp.Visible = True

Steve Howatt

CAD Manager

Perkins & Will

Minneapolis


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I'm
a beginner and I manage to open AutoCAD 2002 program but was unable to open
the specific drawing. Why is that so? Please advise....

Thank you.





Sub LoadDwg()
On Error Resume Next
' Get the AutoCAD
Application object if AutoCAD is running.
Set myApp = GetObject(,
"AutoCAD.Application")
    If Err
Then
       
Err.Clear
        ' Start AutoCAD if
it is not running.
        Set myApp =
CreateObject("AutoCAD.Application")
       
If Err
Then
           
MsgBox
Err.Description
           
Exit Sub
        End
If
    End If
    Set myDoc =
myApp.ActiveDocument
    ' Open the drawing if it is not
already open.
    If myDoc.Name <> "Borelog1_20.dwg"
Then myDoc.Open
("E:\ADCS\CS220\Coding\Project\Econ\Borelog1_20.dwg")
   
point1(0) = 1600: point1(1) = -4000: point1(2) = 0
   
point2(0) = 17000: point2(1) = 4000: point2(2) = 0
    '
Zoom out to encapsulate view of map in VB form.
   
myDoc.ActiveViewport.ZoomWindow point1, point2
   
myApp.Visible = True
End Sub
0 Likes
Message 5 of 9

Anonymous
Not applicable
Oops

I did not test it in a MDI mode, but it should works in
pull-down menu with the same shell command.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Alfred

'Are you running 2000 or 2002?

'Create a form and commandbutton

'Change the path hereunder to your AutoCAD path, and use the
shell.

'you have to use the vb-Max-focus so AutoCAD will not be
docking in the background.

 

Private Sub Command1_Click()
Shell "C:\r02\acad.exe ",
vbMaximizedFocus
End Sub

Hope it help

MAK


________________________________
I will not accept
Email or attachment
I will not take the risk of
viruses.
_______________________________
`·.¸.-*`"0MAK0"`*-.¸.·´
``o000o.^\/^.o000o``
_
VB6- CAD2002 _________________


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

I'm not real familiar with using
VB to automate AutoCAD but the "Open Method" topic in the VBA Reference
states:

 

"When working in MDI mode you should always use the Open method from
the Documents collection. When working in SDI mode, use the Open method from
the Document object."

 

Therefore, you may need to
use:

   

    If Err Then

        '...

    End If

 

    If myDoc.Name <> "Borelog1_20.dwg" Then

        Set myDoc =
myApp.Documents.Open
("E:\ADCS\CS220\Coding\Project\Econ\Borelog1_20.dwg")

    Else

   
face="Times New Roman">    
Set myDoc = myApp.ActiveDocument

    End If

 

    point1(0) = 1600: point1(1) = -4000: point1(2) =
0
    point2(0) = 17000: point2(1) = 4000: point2(2) =
0
    ' Zoom out to encapsulate view of map in VB
form.
    myDoc.ActiveViewport.ZoomWindow point1,
point2
    myApp.Visible = True

Steve Howatt

CAD Manager

Perkins & Will

Minneapolis


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I'm
a beginner and I manage to open AutoCAD 2002 program but was unable to
open the specific drawing. Why is that so? Please advise....

Thank you.





Sub LoadDwg()
On Error Resume Next
' Get the AutoCAD
Application object if AutoCAD is running.
Set myApp = GetObject(,
"AutoCAD.Application")
    If Err
Then
       
Err.Clear
        ' Start AutoCAD if
it is not running.
        Set myApp
=
CreateObject("AutoCAD.Application")
       
If Err
Then
           
MsgBox
Err.Description
           
Exit Sub
        End
If
    End If
    Set myDoc =
myApp.ActiveDocument
    ' Open the drawing if it is not
already open.
    If myDoc.Name <>
"Borelog1_20.dwg" Then myDoc.Open
("E:\ADCS\CS220\Coding\Project\Econ\Borelog1_20.dwg")
   
point1(0) = 1600: point1(1) = -4000: point1(2) = 0
   
point2(0) = 17000: point2(1) = 4000: point2(2) = 0
    '
Zoom out to encapsulate view of map in VB form.
   
myDoc.ActiveViewport.ZoomWindow point1, point2
   
myApp.Visible = True
End
Sub
0 Likes
Message 6 of 9

Anonymous
Not applicable
> Shell "C:\r02\acad.exe ", vbMaximizedFocus

If the goal is to automate AutoCAD, this is not a suitable approach as
it will not return a reference to the AutoCAD application object.
Instead, you should use GetObejct and/or CreateObject.

--
There are 10 kinds of people:
Those who understand binary and those who don't
http://www.acadx.com
0 Likes
Message 7 of 9

Anonymous
Not applicable
Hello Frank,

You are absolutely correct, I did not know his approach, I
just posted a quickie for his problem.

but if he is using VB5, or VB6 and call
the shell32 in his declaration as follow:

 

Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile
As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As
Long
'-----------------------------------------------------------------------------------------------

'change the path to your path
Private Sub
Command1_Click()
ShellExecute hwnd, "open", "c:\r02\support\overhead.dwg",
"", "", vbNormalFocus
End Sub

 

Then he will  open any file , you can test
it.

I just started in VBA and have my difficulty in VBA code, so
you are the man. You have a great site, I down loaded some nice stuff
today. Can you help me in my post "VBA selection
set "
in this NG, I will be appreciated.

 

So long.

MAK

 

"Frank Oquendo" <frankoatacadxdotcom> wrote in message

size=2>news:7AEDD7A8C2BA964E0BB3452D4F1DA8D2@in.WebX.maYIadrTaRb

size=2>...
> > Shell "C:\r02\acad.exe ",
vbMaximizedFocus
>
> If the goal is to automate AutoCAD, this is
not a suitable approach as
> it will not return a reference to the AutoCAD
application object.
> Instead, you should use GetObejct and/or
CreateObject.
>
> --
> There are 10 kinds of people:
>
Those who understand binary and those who don't
>

href="http://www.acadx.com">
size=2>http://www.acadx.com

>
>
0 Likes
Message 8 of 9

Anonymous
Not applicable
Thanks a lot everbody, I manage to get it open in AutoCAD 2002.

If I need to draw a line or insert text into my drawing, will I be reference to mydoc.modelspace.addLine() or myApp.modelspace.addline()?
0 Likes
Message 9 of 9

Anonymous
Not applicable
a help for such problems would be if you look into the help-file
(acadauto.chm ==> activex and vba reference), the objectmodel shows
dependence between the different types of objects and then you click
onto the object for it's methods, properties and events.

for this question think of: does the application have a modelspace?
no, because if you want to add a line to the modelspace the
application has to know into which file the line should be generated

the object-model is always my way to learn the customization of an
application. hope this is a help
- alfred -

On Sun, 17 Nov 2002 22:48:17 -0800, lyz77 wrote:

>Thanks a lot everbody, I manage to get it open in AutoCAD 2002.

If I need to draw a line or insert text into my drawing, will I be reference to mydoc.modelspace.addLine() or myApp.modelspace.addline()?

0 Likes