dynamic path for inserting blocks

dynamic path for inserting blocks

Anonymous
Not applicable
324 Views
3 Replies
Message 1 of 4

dynamic path for inserting blocks

Anonymous
Not applicable
I'm struggling width something I would presume to be fairly easy. All of our projects have their own folders. If I open a drawing an insert a block I want to be able to start the block search in the dir in wich the current drawing is located (if you click the browse button in the dialog box).
This means that for each drawing the path for inserting blocks is different.

Wit:h: sCurPath = ThisDrawing.Path & "\" I will get the path I want but I cant figure out how to set the new path. I want the dialog box to open up in this directory if you click the browse button.

Can anybody give a clue?

thanks in advance
0 Likes
325 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
What happens if you turn AutoCAD's RememberFolders off?

--
R. Robert Bell


wrote in message news:5427055@discussion.autodesk.com...
I'm struggling width something I would presume to be fairly easy. All of our
projects have their own folders. If I open a drawing an insert a block I
want to be able to start the block search in the dir in wich the current
drawing is located (if you click the browse button in the dialog box).
This means that for each drawing the path for inserting blocks is different.

Wit:h: sCurPath = ThisDrawing.Path & "\" I will get the path I want but I
cant figure out how to set the new path. I want the dialog box to open up in
this directory if you click the browse button.

Can anybody give a clue?

thanks in advance
0 Likes
Message 3 of 4

Anonymous
Not applicable
In your case you just need to get the full path of your drawing and set the current windows dir to that path, then run your insert command/routine.

chdir ThisDrawing.GetVariable("DWGPREFIX")
0 Likes
Message 4 of 4

Anonymous
Not applicable
Some extra info:
There are cases where ACAD prefers to manage the initial directory of some commands by using the registry, in which case you actually have to change the registry key. This takes a little more work, here is an example (note the key constants in this example pertain to Mechanical Desktop):

Look out for word wrap!......

Option Explicit
'Registry functions
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.

'Reg data types
Public Const REG_EXPAND_SZ = 2
Public Const REG_SZ = 1

'Reg primary keys
Public Const HKEY_CURRENT_USER = &H80000001

'Reg access settigns
Public Const KEY_SET_VALUE = &H2

Private Const PROFILE_KEY As String = "Software\Autodesk\AutoCAD\r15.0\Acad-103:409\Profiles\"
Private Const EXTERNAL_DIR As String = "\Dialogs\External file to attach"
Private Const OPEN_DIR As String = "\Dialogs\OpenSaveAnavDialogs"
Private Const EXTERNAL_DIR_VALUE As String = "InitialDirectory"
Private Const OPEN_DIR_VALUE As String = "InitialDirectory"
Private Const STOCK_PARTS_DATA As String = "R:\Parts\"
Private Const DRAWINGS_DATA As String = "D:\drawings\"

Dim lKey As Long
Dim sCurrent As String, sProfile As String



Public Sub Run_BrowseAttachCurrent()
' Browse and attach from the directory of the current drawing

' Get the current user profile first
sProfile = ThisDrawing.GetVariable("CPROFILE")

'Get the current drawing's directory
sCurrent = ThisDrawing.GetVariable("DWGPREFIX")

' Overwrite the existing reg. value to point to the stock parts dir
' First open the key
Call RegOpenKeyEx(HKEY_CURRENT_USER, PROFILE_KEY & sProfile & EXTERNAL_DIR, 0, KEY_SET_VALUE, lKey)
' Over write the value
Call RegSetValueEx(lKey, EXTERNAL_DIR_VALUE, 0, REG_SZ, ByVal sCurrent, Len(sCurrent) + 1)
' Close the key
Call RegCloseKey(lKey)

End Sub

Regards,
Jacob Dinardi
www.DinardiEngineering.com
0 Likes