Hi Group, From VB6, I create an instance of AutoCAD with CreateObject. When I issue the insert command at the AutoCAD command prompt and browse, my starting location in the Select Drawing File dialog is set to C:\winnt\system32\. Why is this and how can I change this to begin looking in a folder of my choice? Regards, Ken Hutson San Antonio, Texas
Maybe I'm missing something with your post...why are you using the command prompt to insert something? If you started the session in code, use code to do the insert and you won't have a problem.
Besides looking for ways to supply the path without having to browse as Mike noted, this is a good question. Think back to dos days and how the dos prompt displayed the current path. In windows this is the working dir. You can use the CurDir function to return this path, which is set in the 'Start In' field of a shortcut. But since you didn't start acad from a shortcut, apparently windows is using the system dir. You can use the ChDrive and ChDir functions to change the working dir.
For Mike, I can try and clarify. Usually, we start AutoCAD through the shortcut where we can specify the "start in" location as Ed points out. For us, we tap a %username% enviroment variable. However, assume that user starts VB App. VB App can't detect a running instance of AutoCAD but it needs AutoCAD running so it can operate. VB App invokes CreateObject. AutoCAD starts and VB App does it's thing. Maybe it inserts a block or whatever. So the user finishes using VB App and continues the editing session in the drawing AutoCAD started when CreateObject started AutoCAD. User types "insert" at the command prompt and the file selection dialog appears. User finds an unfamiliar and sensitive area which they would normally have no business in anyway. "Save" command exibits the same behavior. My goal is to start them in the directory they are used to seeing. For Ed, That is the FileSystemObject. Correct? I'll give it a whirl. Also am investigating ShellExecute function call. Looks like it takes parameters. Cheers, Ken Hutson San Antonio, TX
Nope, plain old vb functions, as basic as their dos counterparts. Just set the working dir before you start acad. Also, you wouldn't have this problem if the REMEMBERFOLDERS sysvar was set to 1.
Ed, Sorry I didn't specify. We are STILL on R2000. REMEMBERFOLDERS must have been added later. Thanks for the assist, Ken Hutson San Antonio, TX
I'm not following the gist of this thread all that well, so forgive me if my comment is off-base. But it sounds like you don't like where the various VB apps are leaving your working directory after they do their stuff. I would think that the place to tackle this problem is in the VB apps themselves. Could you modify them to store the current working dir when they start running, and then restore it when they're done (either normal or error exits)? HTH, James
James, Let's say AutoCAD user starts VB app because he knows that there is some function in VB App which will expedite an AutoCAD task. User presses a button in VB App to execute the desired function. Function may need an instance of AutoCAD so it checks to see if AutoCAD is running. Suppose it sees AutoCAD is NOT running. Maybe user forgot to start AutoCAD. So VB App calls CreateObject(, "AutoCAD.Application"). AutoCAD starts and VB App function does whatever it was designed to do in AutoCAD. Further, let's say user continues to edit the default drawing that was created when CreateObject instantiated the AutoCAD process. For example, user types "Save", "Insert" or "XREF attach". File dialog box comes up. In this case, on my system, the default path in the file dialog box comes up C:\winnt\system32\. I don't want user in this particular folder. They have no business there. Plus more than likely, it's a long traverse to find the path that is of interest to them. VB App didn't change a path at all. Problem is that CreateObject provides no way to specify a start up folder for AutoCAD (like a shortcut can) and I don't see a property on the acaddocument or acadapplication to change it after AutoCAD starts. Now the acaddocument has a Path property, but it's read only. Am I missing something? Ed, By the way, I tried Chdir function both before and after CreateObject. No effect. An API call to ShellExecute works but it's asynchronous. Cheers, Ken Hutson San Antonio, TX
Here's an ugly kludge that at least leaves them in the Windows Temp directory, a little less dangerous place.... and actually the TempFile API will take any directory as an argument, so you could leave them anywhere you want -- but the Win Temp directory is pretty guaranteed to exist, be writeable, etc....least danger of runtime errors. Option Explicit ' courtesy Randy Birch @ http://vbnet.mvps.org/index.html?code/fileapi/gettempfilename.htm ' helpful comments removed, code adulterated for my purposes Private Declare Function GetTempPath _ Lib "kernel32" Alias "GetTempPathA" _ (ByVal nBufferLength As Long, _ ByVal lpBuffer As String) As Long Private Declare Function GetTempFileName _ Lib "kernel32" Alias "GetTempFileNameA" _ (ByVal lpszPath As String, _ ByVal lpPrefixString As String, _ ByVal wUnique As Long, _ ByVal lpTempFileName As String) As Long Private Const MAX_PATH As Long = 260 Public Sub CommandButton1_Click() Dim TempXLfilename As String Dim AcadApp As Object Set AcadApp = CreateObject("AutoCAD.Application") TempXLfilename = GetTempXLfilename AcadApp.activedocument.SaveAs TempXLfilename AcadApp.activedocument.Close False 'could leave file open if you want to 'Kill TempXLfilename 'trying to clean up temp file is causing error... dunno why... End Sub Private Function GetTempXLfilename() Dim tempfilename As String tempfilename = CreateTempFilename Name tempfilename As tempfilename & ".xls" tempfilename = tempfilename & ".xls" Kill tempfilename GetTempXLfilename = tempfilename End Function Private Function GetSystemTempPath() As String Dim result As Long Dim buff As String buff = Space$(MAX_PATH) result = GetTempPath(MAX_PATH, buff) GetSystemTempPath = Left$(buff, result) End Function Private Function CreateTempFilename() As String Dim result As Long Dim buff As String buff = Space$(MAX_PATH) result = GetTempFileName(GetSystemTempPath(), "vbn", 0, buff) If result <> 0 Then CreateTempFilename = Left$(buff, InStr(buff, Chr$(0)) - 1) End If End Function Good luck, James
Okay, I follow now. Have you tried opening AutoCAD and applying a profile? That might get your paths back....
Mike, Just tried that. No effect. Good try though. I have two profiles. Default and KJH (my initials). Funny thing is, my profile is already active after CreateObject call. Seems like I need to get access to AutoCAD File Selection object. I am thinking it may be using information from a Windows component. Thanks, Ken Hutson San Antonio, TX
Oops... hehe.. I must've been tired. The two instances of ".xls" in the code I wrote needs to be changed to ".dwg". Otherwise the file gets saved to a different name, *.xls.dwg James
I was able to duplicate your situation by setting REMEMBERFOLDERS to 0. Earlier when I suggested to set the working dir, I neglected to mention that each app has its own working dir. You need to set it from withing acad, not your vb app. I created a function that did this and called it from the vb app, still the file dialog opens in system32. You can try this from the acad command line: "vbastmt ChDir sompath" Then open the file dialog and it still opens in system32. I looked in the registry and didn't find any place that was storing this path.
My memory finally kicked in...I did some work a while ago on this. I was able to set the registy path for the Insert dialog (I have it in lisp so you can just add it to a button macro) so that you could route the folder to your block lib's main folder, but for some reason you can set the reg keys for the Open/Save dialog just fine, but the dialog doesn't recognize the change.
Thanks to all for your exploration, The Excel Application has a property called DefaultFilePath. It's read/write. I'm on AutoCAD 2000 and I don't see anything similar. Don't know about more recent AutoCAD releases but perhaps since AutoDesk is aligning itself with Microsoft, it wouldn't be a bad idea to add this property to the AutoCAD Application object. As it is, I have resigned myself to design my App so that it will advise the user to start AutoCAD if it does not detect a running instance of AutoCAD. Cheers, Ken Hutson San Attonio, TX
Have a look at some of the registry keys in this location HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.0\ACAD-202:409\Profiles\<<Unnamed Profile>>\Dialogs I think they will help but maybe not for the save dialog. Regards - Nathan