| Author |
Message |
john m
Guest
|
Posted:
Thu Jan 13, 2005 6:55 pm Post subject:
vb6 |
|
|
Hello,
Can someone direct me to an example of the proper way to access autocad
from vb6?
i just want to see if there is an open session of acad and then if there is
use it and if not then start autocad.
some of my programs have lately started acting whacky by saying that no
autocad session was found when there is one open.
do i need to set a reference to something? scripting runtime?
thanks in advance for any reply
jm
|
|
| Back to top |
|
 |
Jackrabbit
Guest
|
Posted:
Thu Jan 13, 2005 8:23 pm Post subject:
Re: vb6 |
|
|
Here's what I use to connect to Excel from VBA. You should be able to connect to AutoCAD the same way.
[pre]
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If objExcel Is Nothing Then
Err.Clear
blnExcelWasRunning = False
Set objExcel = GetObject("", "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
MsgBox "Error: You must have Excel installed on your" & vbCrLf & _
"computer to use the Import BDIF function."
ImportDieData_BDIF = 1
Set objExcel = Nothing
Exit Function
End If
Else
blnExcelWasRunning = True
End If
[/pre] |
|
| Back to top |
|
 |
john m
Guest
|
Posted:
Fri Jan 14, 2005 2:56 am Post subject:
Re: vb6 |
|
|
thanks JR
does anyone know why this code throws an error in VB6?
this is the same way i was doing it before..
what i get when i run this code or my own is "Compiler Error: Invalid
Outside Procedure"
thanks
jm
"Jackrabbit" <nospam@address.withheld> wrote in message
news:755780.1105629850844.JavaMail.jive@jiveforum1.autodesk.com...
| Quote: | Here's what I use to connect to Excel from VBA. You should be able to
connect to AutoCAD the same way.
[pre]
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If objExcel Is Nothing Then
Err.Clear
blnExcelWasRunning = False
Set objExcel = GetObject("", "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
MsgBox "Error: You must have Excel installed on your" & vbCrLf &
_
"computer to use the Import BDIF function."
ImportDieData_BDIF = 1
Set objExcel = Nothing
Exit Function
End If
Else
blnExcelWasRunning = True
End If
[/pre] |
|
|
| Back to top |
|
 |
hwalker
Guest
|
Posted:
Fri Jan 14, 2005 10:03 am Post subject:
Re: vb6 |
|
|
It probably doesn't work because JR says his program runs in VBA and you say your programs run in VB6. They use slightly different command sets. try adapting the following which I used for a program I wrote in VB6 for Autocad LT. It uses DDE and you need to put a text box on a form and call it txtbID. Also be careful of the word wrapping on the stuff I've pasted below
txtbID.LinkMode = 0 '0 = reset
txtbID.LinkTopic = "AutoCAD LT.DDE|system" 'establish DDE link
txtbID.LinkMode = 2
txtbID.LinkTimeout = -1
If Dir("C:\plotlogfile\*.log") > "" Then
FileName$ = Dir("C:\plotlogfile\*.log")
Do Until FileName$ = ""
If UCase$(FileName$) <> "HARDCOPY.LOG" Then Kill "c:\plotlogfile\" + FileName$
FileName$ = Dir
Loop
End If
'Call Command1_Click
AppActivate "AutoCAD LT", True |
|
| Back to top |
|
 |
john m
Guest
|
Posted:
Fri Jan 14, 2005 9:52 pm Post subject:
Re: vb6 |
|
|
Thank You
I still get the same error regardless of which way i do it.
For some reason every time i try to use appactivate or shell or createobject
or get object its always the same
"Invalid Outside Procedure"
Programs which have worked before no longer work
"hwalker" <nospam@address.withheld> wrote in message
news:30993340.1105693334198.JavaMail.jive@jiveforum2.autodesk.com...
| Quote: | It probably doesn't work because JR says his program runs in VBA and you
say your programs run in VB6. They use slightly different command sets. try |
adapting the following which I used for a program I wrote in VB6 for Autocad
LT. It uses DDE and you need to put a text box on a form and call it txtbID.
Also be careful of the word wrapping on the stuff I've pasted below
| Quote: |
txtbID.LinkMode = 0 '0 = reset
txtbID.LinkTopic = "AutoCAD LT.DDE|system" 'establish DDE
link
txtbID.LinkMode = 2
txtbID.LinkTimeout = -1
If Dir("C:\plotlogfile\*.log") > "" Then
FileName$ = Dir("C:\plotlogfile\*.log")
Do Until FileName$ = ""
If UCase$(FileName$) <> "HARDCOPY.LOG" Then Kill "c:\plotlogfile\" +
FileName$
FileName$ = Dir
Loop
End If
'Call Command1_Click
AppActivate "AutoCAD LT", True |
|
|
| Back to top |
|
 |
Jackrabbit
Guest
|
Posted:
Fri Jan 14, 2005 10:02 pm Post subject:
Re: vb6 |
|
|
Is your code actually inside a procedure??
Public Sub()
Your code here?
End Sub |
|
| Back to top |
|
 |
john m
Guest
|
Posted:
Fri Jan 14, 2005 11:35 pm Post subject:
Re: vb6 |
|
|
thanks JR
i was trying it in the immediate window
finally got this to work
Private Sub Form_Load()
Dim oa As Object
On Error Resume Next
Set oa = GetObject(, "Autocad.application.16")
If Err <> 0 Then
Err.Clear
Set oa = CreateObject("Autocad.application.16")
End If
End Sub
apparently the ".16" is required for 2005
"Jackrabbit" <nospam@address.withheld> wrote in message
news:20406060.1105722171620.JavaMail.jive@jiveforum2.autodesk.com...
| Quote: | Is your code actually inside a procedure??
Public Sub()
Your code here?
End Sub |
|
|
| Back to top |
|
 |
Chris ( Val )
Guest
|
Posted:
Sun Jan 16, 2005 7:28 pm Post subject:
Re: vb6 |
|
|
"john m" <jmNOSPAM@haengineers.com> wrote in message news:41e67d59$1_1@newsprd01...
| Hello,
|
| Can someone direct me to an example of the proper way to access autocad
| from vb6?
|
| i just want to see if there is an open session of acad and then if there is
| use it and if not then start autocad.
|
| some of my programs have lately started acting whacky by saying that no
| autocad session was found when there is one open.
|
| do i need to set a reference to something? scripting runtime?
|
| thanks in advance for any reply
You just need to add a reference to the "AutoCAD 2005 Type Library"
for example (whatever your AutoCAD version is). Then you can just
do something like the following:
Private Sub Form_Load()
'
Dim AutoCAD As New AcadApplication
AutoCAD.Documents.Open "C:\MyDWG.dwg"
Dim Buffer As String
Dim Layer As Object
Dim ActiveDocument As AcadDocument
Set ActiveDocument = AutoCAD.ActiveDocument
Buffer = "This drawing contains the following layers: " & vbNewLine & vbNewLine
For Each Layer In ActiveDocument.Layers
If Layer.Name = "0" Then
Buffer = "Default Layer: " & Layer.Name & vbNewLine & vbNewLine
Else
Buffer = Buffer + Layer.Name & vbNewLine
End If
Next Layer
MsgBox Buffer, vbInformation, "LAYERS LIST INFORMATION"
AutoCAD.Documents.Close
AutoCAD.Quit
Set AutoCAD = Nothing
Unload Me
End
'
End Sub
Cheers.
Chris Val |
|
| Back to top |
|
 |
|
|
|
|