Message 1 of 7
Launch AutoCAD and Create a Search File Path
Not applicable
03-06-2003
02:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
' Hi,
' I did the below bit and pieces code to launch AutoCAD from my exe and also
' to create a new Search File Path from where I launched folder, but only
works if I have AutoCAD already opened
' not from scratch (from the exe) it always create the path from:
\windows\system32
' can someone test this is for Visual Basic, thanks Luis E.
Option Explicit
Public objAcad As AcadApplication
Public ThisDrawing As AcadDocument
Sub main()
Dim AcadRunning As Boolean
On Error GoTo Err_Control
AcadRunning = IsAutoCADOpen()
If AcadRunning Then
Set objAcad = GetObject(, "AutoCAD.Application")
Else
Set objAcad = CreateObject("AutoCAD.Application")
End If
' starting code to create the Search File Path
Dim preferences As Object
Set preferences = objAcad.preferences
Dim SPath As String
SPath = preferences.Files.SupportPath
Dim addPath As String
addPath = objAcad.ActiveDocument.GetVariable("DWGPREFIX")
' just testing to show what path is added
MsgBox ("New path: " & addPath)
Dim lengthPath As Integer
lengthPath = Len(addPath)
If Right(addPath, 1) = "\" Then
addPath = Left(addPath, lengthPath - 1)
End If
' add our folder where we have installed our application
' or from where AutoCAD is opened
If StrConv(SPath, 1) Like "*" & addPath & "*" <> True Then
preferences.Files.SupportPath = SPath & ";" & addPath
End If
objAcad.Visible = True
Set ThisDrawing = objAcad.ActiveDocument
Exit_Here:
Exit Sub
Err_Control:
MsgBox Err.Description
Resume Exit_Here
End Sub
Function IsAutoCADOpen() As Boolean
On Error Resume Next
Set objAcad = GetObject(, "AutoCAD.Application")
IsAutoCADOpen = (Err.Number = 0)
Set objAcad = Nothing
Err.Clear
End Function
' I did the below bit and pieces code to launch AutoCAD from my exe and also
' to create a new Search File Path from where I launched folder, but only
works if I have AutoCAD already opened
' not from scratch (from the exe) it always create the path from:
\windows\system32
' can someone test this is for Visual Basic, thanks Luis E.
Option Explicit
Public objAcad As AcadApplication
Public ThisDrawing As AcadDocument
Sub main()
Dim AcadRunning As Boolean
On Error GoTo Err_Control
AcadRunning = IsAutoCADOpen()
If AcadRunning Then
Set objAcad = GetObject(, "AutoCAD.Application")
Else
Set objAcad = CreateObject("AutoCAD.Application")
End If
' starting code to create the Search File Path
Dim preferences As Object
Set preferences = objAcad.preferences
Dim SPath As String
SPath = preferences.Files.SupportPath
Dim addPath As String
addPath = objAcad.ActiveDocument.GetVariable("DWGPREFIX")
' just testing to show what path is added
MsgBox ("New path: " & addPath)
Dim lengthPath As Integer
lengthPath = Len(addPath)
If Right(addPath, 1) = "\" Then
addPath = Left(addPath, lengthPath - 1)
End If
' add our folder where we have installed our application
' or from where AutoCAD is opened
If StrConv(SPath, 1) Like "*" & addPath & "*" <> True Then
preferences.Files.SupportPath = SPath & ";" & addPath
End If
objAcad.Visible = True
Set ThisDrawing = objAcad.ActiveDocument
Exit_Here:
Exit Sub
Err_Control:
MsgBox Err.Description
Resume Exit_Here
End Sub
Function IsAutoCADOpen() As Boolean
On Error Resume Next
Set objAcad = GetObject(, "AutoCAD.Application")
IsAutoCADOpen = (Err.Number = 0)
Set objAcad = Nothing
Err.Clear
End Function