Get and Set Search Folders Example (C#)
This example shows how to get and set the file locations in which SOLIDWORKS
searches for reference documents.
//----------------------------------------------------------------------------
// Preconditions: Open SOLIDWORKS.
//
// Postconditions:
// 1. Inspect the Immediate window.
// 2. c:\ is added to the beginning of the search folder path for reference
// documents.
//
---------------------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System.Runtime.InteropServices;
using
System;
using
System.Diagnostics;
namespace
GetandSetSearchFolders_CSharp.csproj
{
partial
class
SolidWorksMacro
{
ModelDoc2
Part;
string
searchFolders;
bool
boolstatus;
public
void Main()
{
Part = (ModelDoc2)swApp.ActiveDoc;
swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUseFolderSearchRules,
false);
searchFolders = "c:\\;"
+ searchFolders;
boolstatus = swApp.SetSearchFolders(0, searchFolders);
searchFolders = swApp.GetSearchFolders(0);
Debug.Print("New
search path: " + searchFolders);
}
public
SldWorks
swApp;
}
}