25 | 03 | 2017

Add / Change Support Path

It is possible to change the or add a support path using VBA. To do so we have two functions AddSupportPath() and ChangeSupportPath().  Use whichever suits you best.

 

Private Function AddSupportPath(ByVal path As String)

'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
Dim acadPref As AcadPreferencesFiles
Dim OLDpaths As String
Dim NEWpath As String

NEWpath = path

'First we get all existing support paths
'Paths come as one string divided by ;
Set acadPref = AcadApplication.Preferences.Files

OLDpaths = acadPref.SupportPath

Debug.Print OLDpaths

'Add the new path by adding a ; and the path
NEWpath = OLDpaths & ";" & NEWpath

acadPref.SupportPath = NEWpath

Debug.Print acadPref.SupportPath

End Function

 

To change a support path use the following Function

 

Private Function ChangeSupportPath(OldPathName As String, NewPathName As String)

Dim acadPref As AcadPreferencesFiles

Dim pathArray() As String

Dim oldStr As String, newStr As String

Dim i As Integer

'First we get all existing support paths
'Paths come as one string divided by ;
Set acadPref = AcadApplication.Preferences.Files

oldStr = acadPref.SupportPath

'We split the string so we have a array of paths
pathArray = Split(OLDpath, ";")

'Search for the same path name
For i = LBound(pathArray) To UBound(pathArray)
If pathArray(i) = OLDpath Then pathAry(i) = Trim(NEWpath)
Next i

For i = LBound(pathArray) To UBound(pathArray)
newStr = Trim(newStr) & Trim(pathAry(i)) & ";"
Next i

'If found then the path is replaced
newStr = Trim(Replace(Left(newStr, Len(newStr) - 1), ";;", ";"))

acadPref.SupportPath = newStr

Erase pathArray

Set acadPref = Nothing

End Function 

Download AutoCad sample Here

Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2208316
Latest Articles