<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Launch AutoCAD and Create a Search File Path in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303255#M65283</link>
    <description>' Hi,&lt;BR /&gt;
' I did the below bit and pieces code to launch AutoCAD from my exe and also&lt;BR /&gt;
' to create a new Search File Path from where I launched folder, but only&lt;BR /&gt;
works if I have AutoCAD already opened&lt;BR /&gt;
' not from scratch (from the exe) it always create the path from:&lt;BR /&gt;
\windows\system32&lt;BR /&gt;
' can someone test this is for Visual Basic, thanks Luis E.&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Public objAcad As AcadApplication&lt;BR /&gt;
Public ThisDrawing As AcadDocument&lt;BR /&gt;
Sub main()&lt;BR /&gt;
&lt;BR /&gt;
 Dim AcadRunning As Boolean&lt;BR /&gt;
&lt;BR /&gt;
 On Error GoTo Err_Control&lt;BR /&gt;
&lt;BR /&gt;
 AcadRunning = IsAutoCADOpen()&lt;BR /&gt;
&lt;BR /&gt;
 If AcadRunning Then&lt;BR /&gt;
   Set objAcad = GetObject(, "AutoCAD.Application")&lt;BR /&gt;
 Else&lt;BR /&gt;
   Set objAcad = CreateObject("AutoCAD.Application")&lt;BR /&gt;
 End If&lt;BR /&gt;
&lt;BR /&gt;
' starting code to create the Search File Path&lt;BR /&gt;
&lt;BR /&gt;
Dim preferences As Object&lt;BR /&gt;
&lt;BR /&gt;
Set preferences = objAcad.preferences&lt;BR /&gt;
&lt;BR /&gt;
Dim SPath As String&lt;BR /&gt;
&lt;BR /&gt;
SPath = preferences.Files.SupportPath&lt;BR /&gt;
&lt;BR /&gt;
Dim addPath As String&lt;BR /&gt;
&lt;BR /&gt;
addPath = objAcad.ActiveDocument.GetVariable("DWGPREFIX")&lt;BR /&gt;
&lt;BR /&gt;
' just testing to show what path is added&lt;BR /&gt;
MsgBox ("New path: " &amp;amp; addPath)&lt;BR /&gt;
&lt;BR /&gt;
Dim lengthPath As Integer&lt;BR /&gt;
&lt;BR /&gt;
lengthPath = Len(addPath)&lt;BR /&gt;
If Right(addPath, 1) = "\" Then&lt;BR /&gt;
addPath = Left(addPath, lengthPath - 1)&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
' add our folder where we have installed our application&lt;BR /&gt;
' or from where AutoCAD is opened&lt;BR /&gt;
If StrConv(SPath, 1) Like "*" &amp;amp; addPath &amp;amp; "*" &amp;lt;&amp;gt; True Then&lt;BR /&gt;
preferences.Files.SupportPath = SPath &amp;amp; ";" &amp;amp; addPath&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
 objAcad.Visible = True&lt;BR /&gt;
&lt;BR /&gt;
 Set ThisDrawing = objAcad.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
Exit_Here:&lt;BR /&gt;
 Exit Sub&lt;BR /&gt;
Err_Control:&lt;BR /&gt;
 MsgBox Err.Description&lt;BR /&gt;
 Resume Exit_Here&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Function IsAutoCADOpen() As Boolean&lt;BR /&gt;
 On Error Resume Next&lt;BR /&gt;
 Set objAcad = GetObject(, "AutoCAD.Application")&lt;BR /&gt;
 IsAutoCADOpen = (Err.Number = 0)&lt;BR /&gt;
 Set objAcad = Nothing&lt;BR /&gt;
 Err.Clear&lt;BR /&gt;
End Function</description>
    <pubDate>Thu, 06 Mar 2003 10:35:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2003-03-06T10:35:01Z</dc:date>
    <item>
      <title>Launch AutoCAD and Create a Search File Path</title>
      <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303255#M65283</link>
      <description>' Hi,&lt;BR /&gt;
' I did the below bit and pieces code to launch AutoCAD from my exe and also&lt;BR /&gt;
' to create a new Search File Path from where I launched folder, but only&lt;BR /&gt;
works if I have AutoCAD already opened&lt;BR /&gt;
' not from scratch (from the exe) it always create the path from:&lt;BR /&gt;
\windows\system32&lt;BR /&gt;
' can someone test this is for Visual Basic, thanks Luis E.&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Public objAcad As AcadApplication&lt;BR /&gt;
Public ThisDrawing As AcadDocument&lt;BR /&gt;
Sub main()&lt;BR /&gt;
&lt;BR /&gt;
 Dim AcadRunning As Boolean&lt;BR /&gt;
&lt;BR /&gt;
 On Error GoTo Err_Control&lt;BR /&gt;
&lt;BR /&gt;
 AcadRunning = IsAutoCADOpen()&lt;BR /&gt;
&lt;BR /&gt;
 If AcadRunning Then&lt;BR /&gt;
   Set objAcad = GetObject(, "AutoCAD.Application")&lt;BR /&gt;
 Else&lt;BR /&gt;
   Set objAcad = CreateObject("AutoCAD.Application")&lt;BR /&gt;
 End If&lt;BR /&gt;
&lt;BR /&gt;
' starting code to create the Search File Path&lt;BR /&gt;
&lt;BR /&gt;
Dim preferences As Object&lt;BR /&gt;
&lt;BR /&gt;
Set preferences = objAcad.preferences&lt;BR /&gt;
&lt;BR /&gt;
Dim SPath As String&lt;BR /&gt;
&lt;BR /&gt;
SPath = preferences.Files.SupportPath&lt;BR /&gt;
&lt;BR /&gt;
Dim addPath As String&lt;BR /&gt;
&lt;BR /&gt;
addPath = objAcad.ActiveDocument.GetVariable("DWGPREFIX")&lt;BR /&gt;
&lt;BR /&gt;
' just testing to show what path is added&lt;BR /&gt;
MsgBox ("New path: " &amp;amp; addPath)&lt;BR /&gt;
&lt;BR /&gt;
Dim lengthPath As Integer&lt;BR /&gt;
&lt;BR /&gt;
lengthPath = Len(addPath)&lt;BR /&gt;
If Right(addPath, 1) = "\" Then&lt;BR /&gt;
addPath = Left(addPath, lengthPath - 1)&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
' add our folder where we have installed our application&lt;BR /&gt;
' or from where AutoCAD is opened&lt;BR /&gt;
If StrConv(SPath, 1) Like "*" &amp;amp; addPath &amp;amp; "*" &amp;lt;&amp;gt; True Then&lt;BR /&gt;
preferences.Files.SupportPath = SPath &amp;amp; ";" &amp;amp; addPath&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
 objAcad.Visible = True&lt;BR /&gt;
&lt;BR /&gt;
 Set ThisDrawing = objAcad.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
Exit_Here:&lt;BR /&gt;
 Exit Sub&lt;BR /&gt;
Err_Control:&lt;BR /&gt;
 MsgBox Err.Description&lt;BR /&gt;
 Resume Exit_Here&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Function IsAutoCADOpen() As Boolean&lt;BR /&gt;
 On Error Resume Next&lt;BR /&gt;
 Set objAcad = GetObject(, "AutoCAD.Application")&lt;BR /&gt;
 IsAutoCADOpen = (Err.Number = 0)&lt;BR /&gt;
 Set objAcad = Nothing&lt;BR /&gt;
 Err.Clear&lt;BR /&gt;
End Function</description>
      <pubDate>Thu, 06 Mar 2003 10:35:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303255#M65283</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-03-06T10:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Launch AutoCAD and Create a Search File Path</title>
      <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303256#M65284</link>
      <description>Luis,&lt;BR /&gt;
&lt;BR /&gt;
Here's your answer.&lt;BR /&gt;
&lt;BR /&gt;
Joe&lt;BR /&gt;
--&lt;BR /&gt;
&lt;PRE&gt;&lt;BR /&gt;
  On Error Resume Next&lt;BR /&gt;
  'open AutoCAD&lt;BR /&gt;
  Set objAcad = GetObject(, "AutoCAD.Application")&lt;BR /&gt;
  &lt;BR /&gt;
  If Err Then&lt;BR /&gt;
    Err.Clear&lt;BR /&gt;
    Set objAcad = CreateObject("AutoCAD.Application")&lt;BR /&gt;
    If Err Then&lt;BR /&gt;
      MsgBox "Could not start AutoCAD!", vbCritical, "Error - AutoCAD not found"&lt;BR /&gt;
      'unload application form&lt;BR /&gt;
      Unload Me&lt;BR /&gt;
      'exit the application&lt;BR /&gt;
      Exit Sub&lt;BR /&gt;
    End If&lt;BR /&gt;
  End If&lt;BR /&gt;
  &lt;BR /&gt;
'starting code to create the Search File Path&lt;BR /&gt;
Dim oPreferences As AcadPreferences&lt;BR /&gt;
Dim SPath As String&lt;BR /&gt;
Dim addPath As String&lt;BR /&gt;
Dim lengthPath As Integer&lt;BR /&gt;
&lt;BR /&gt;
  Set oPreferences = objAcad.preferences&lt;BR /&gt;
  SPath = oPreferences.Files.SupportPath&lt;BR /&gt;
  addPath = objAcad.ActiveDocument.GetVariable("DWGPREFIX")&lt;BR /&gt;
&lt;BR /&gt;
  'just testing to show what path is added&lt;BR /&gt;
  MsgBox ("New path: " &amp;amp; addPath)&lt;BR /&gt;
&lt;BR /&gt;
  lengthPath = Len(addPath)&lt;BR /&gt;
&lt;BR /&gt;
  If Right(addPath, 1) = "\" Then&lt;BR /&gt;
    addPath = Left(addPath, lengthPath - 1)&lt;BR /&gt;
  End If&lt;BR /&gt;
&lt;BR /&gt;
  'add our folder where we have installed our application&lt;BR /&gt;
  'or from where AutoCAD is opened&lt;BR /&gt;
  If StrConv(SPath, 1) Like "*" &amp;amp; addPath &amp;amp; "*" &amp;lt;&amp;gt; True Then&lt;BR /&gt;
    preferences.Files.SupportPath = SPath &amp;amp; ";" &amp;amp; addPath&lt;BR /&gt;
  End If&lt;BR /&gt;
  &lt;BR /&gt;
  'make AutoCAD visible&lt;BR /&gt;
  objAcad.Visible = True&lt;BR /&gt;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Mar 2003 11:15:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303256#M65284</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-03-06T11:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Launch AutoCAD and Create a Search File Path</title>
      <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303257#M65285</link>
      <description>Scrap the IsAutoCADOpen() function.&lt;BR /&gt;
&lt;BR /&gt;
Joe&lt;BR /&gt;
--</description>
      <pubDate>Thu, 06 Mar 2003 11:16:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303257#M65285</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-03-06T11:16:13Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303258#M65286</link>
      <description>Thank Joe,&lt;BR /&gt;
&lt;BR /&gt;
But it does the same as my previous code, I will keep testing.&lt;BR /&gt;
&lt;BR /&gt;
---&lt;BR /&gt;
luis</description>
      <pubDate>Thu, 06 Mar 2003 11:27:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303258#M65286</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-03-06T11:27:22Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303259#M65287</link>
      <description>Luis,&lt;BR /&gt;
&lt;BR /&gt;
It worked prefectly for him so maybe I'm missing something. Perhaps more explanation would help.&lt;BR /&gt;
&lt;BR /&gt;
Joe&lt;BR /&gt;
--</description>
      <pubDate>Thu, 06 Mar 2003 12:05:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303259#M65287</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-03-06T12:05:42Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303260#M65288</link>
      <description>"joesu" &lt;JOESU&gt; wrote in message&lt;BR /&gt;
news:f14b867.1@WebX.maYIadrTaRb...&lt;BR /&gt;
Scrap the IsAutoCADOpen() function.&lt;BR /&gt;
Joe&lt;BR /&gt;
--&lt;BR /&gt;
&lt;BR /&gt;
Here is my previous code that I want it to update for AutoCAD 15, can you&lt;BR /&gt;
tested please (is not working...):&lt;BR /&gt;
&lt;BR /&gt;
What I want to do is to launch autocad from my exe and create a support path&lt;BR /&gt;
from where I have my exe.&lt;BR /&gt;
&lt;BR /&gt;
thank you,&lt;BR /&gt;
----&lt;BR /&gt;
luis&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Option Compare Text&lt;BR /&gt;
Declare Function RegQueryValueEx&amp;amp; Lib "advapi32.dll" Alias&lt;BR /&gt;
"RegQueryValueExA" (ByVal hKey&amp;amp;, ByVal lpszValueName$, ByVal lpdwRes&amp;amp;,&lt;BR /&gt;
lpdwType&amp;amp;, ByVal lpDataBuff$, nSize&amp;amp;)&lt;BR /&gt;
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA"&lt;BR /&gt;
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long,&lt;BR /&gt;
ByVal samDesired As Long, phkResult As Long) As Long&lt;BR /&gt;
&lt;BR /&gt;
Private Function GetAppPath(subkey As String, sAppEntry As String) As String&lt;BR /&gt;
Dim s As String * 255, sAppPath As String&lt;BR /&gt;
Dim lAppKey As Long, lType As Long, lLen As Long, lRC As Long&lt;BR /&gt;
&lt;BR /&gt;
Const HKEY_LOCAL_MACHINE = &amp;amp;H80000002&lt;BR /&gt;
Const HKEY_CLASSES_ROOT = &amp;amp;H80000001&lt;BR /&gt;
Const KEY_QUERY_VALUE = &amp;amp;H1&amp;amp;&lt;BR /&gt;
Const KEY_ENUMERATE_SUB_KEYS = &amp;amp;H8&amp;amp;&lt;BR /&gt;
Const KEY_NOTIFY = &amp;amp;H10&amp;amp;&lt;BR /&gt;
Const READ_CONTROL = &amp;amp;H20000&lt;BR /&gt;
Const STANDARD_RIGHTS_READ = READ_CONTROL&lt;BR /&gt;
Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or&lt;BR /&gt;
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY&lt;BR /&gt;
    lLen = Len(s)&lt;BR /&gt;
    lRC = RegOpenKeyEx(HKEY_CLASSES_ROOT, sAppEntry, 0, KEY_READ, lAppKey)&lt;BR /&gt;
    If lRC &amp;lt;&amp;gt; 0 Then Exit Function&lt;BR /&gt;
    lRC = RegQueryValueEx(lAppKey, subkey, 0, lType, s, lLen)&lt;BR /&gt;
    GetAppPath = Left$(s, lLen - 1)&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Sub Main()&lt;BR /&gt;
   Dim Acaddir As String&lt;BR /&gt;
   Dim version As String&lt;BR /&gt;
   Dim result As Boolean&lt;BR /&gt;
   Dim sAcadEntry As String&lt;BR /&gt;
&lt;BR /&gt;
   On Error Resume Next&lt;BR /&gt;
&lt;BR /&gt;
   sAcadEntry = "AutoCAD.Drawing.15\shell\open\command"&lt;BR /&gt;
   version = GetAppPath("command", sAcadEntry)&lt;BR /&gt;
   Acaddir = GetAppPath("AcadLocation", sAcadEntry &amp;amp; "\" &amp;amp; version)&lt;BR /&gt;
   If StrConv(Dir(Acaddir &amp;amp; "\ACAD.EXE"), 1) Like "ACAD.EXE" &amp;lt;&amp;gt; True Then&lt;BR /&gt;
    MsgBox ("AutoCAD Ver. 15 not installed. Please refer to User Manual.")&lt;BR /&gt;
    End&lt;BR /&gt;
   End If&lt;BR /&gt;
   result = Shell(Acaddir &amp;amp; "\acad.exe /b myapp.scr", 1)&lt;BR /&gt;
&lt;BR /&gt;
   'Wait 20 second to let AutoCAD open&lt;BR /&gt;
   Dim TimeNow As Double&lt;BR /&gt;
   Dim TimeEnd As Double&lt;BR /&gt;
   TimeNow = Hour(Now()) + (Minute(Now()) / 60#) + (Second(Now()) / 3600#)&lt;BR /&gt;
   TimeEnd = TimeNow + (180# / 3600#)&lt;BR /&gt;
   While TimeNow &amp;lt; TimeEnd And result &amp;lt;&amp;gt; True&lt;BR /&gt;
      TimeNow = Hour(Now()) + (Minute(Now()) / 60#) + (Second(Now()) /&lt;BR /&gt;
3600#)&lt;BR /&gt;
   Wend&lt;BR /&gt;
&lt;BR /&gt;
   If result &amp;lt;&amp;gt; True Then&lt;BR /&gt;
    MsgBox ("Cannot open AutoCAD 15.0")&lt;BR /&gt;
    End&lt;BR /&gt;
   End If&lt;BR /&gt;
   Dim acadApp As Object&lt;BR /&gt;
   Set acadApp = GetObject(, "AutoCAD.Application")&lt;BR /&gt;
   Dim preferences As Object&lt;BR /&gt;
   Set preferences = acadApp.preferences.Files&lt;BR /&gt;
   Dim SPath As String&lt;BR /&gt;
   SPath = preferences.Files.SupportPath&lt;BR /&gt;
   Dim newPath As String&lt;BR /&gt;
   newPath = acadApp.ActiveDocument.GetVariable("DWGPREFIX")&lt;BR /&gt;
   Dim LnewPath As Integer&lt;BR /&gt;
   LnewPath = Len(newPath)&lt;BR /&gt;
   If Right(newPath, 1) = "\" Then&lt;BR /&gt;
        newPath = Left(newPath, LnewPath - 1)&lt;BR /&gt;
   End If&lt;BR /&gt;
   'Add our folder where we are installed our application&lt;BR /&gt;
   If StrConv(SPath, 1) Like "*" &amp;amp; newPath &amp;amp; "*" &amp;lt;&amp;gt; True Then&lt;BR /&gt;
        preferences.Files.SupportPath = SPath &amp;amp; ";" &amp;amp; newPath&lt;BR /&gt;
   End If&lt;BR /&gt;
   Set acadApp = Nothing&lt;BR /&gt;
   Set preferences = Nothing&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;/JOESU&gt;</description>
      <pubDate>Thu, 06 Mar 2003 13:37:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303260#M65288</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-03-06T13:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Launch AutoCAD and Create a Search File Path</title>
      <link>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303261#M65289</link>
      <description>using Luis's first code I am getting an error, that described as "Call was&lt;BR /&gt;
rejected by callee."&lt;BR /&gt;
I am working with Acad2002 and VB.NET&lt;BR /&gt;
Do you have some suggestions?</description>
      <pubDate>Fri, 07 Mar 2003 06:44:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/launch-autocad-and-create-a-search-file-path/m-p/303261#M65289</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-03-07T06:44:04Z</dc:date>
    </item>
  </channel>
</rss>

