Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:addsearchpath [2015/09/14] (current)
Line 1: Line 1:
 +====== Add to Rhino'​s File Search Path ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to add a file path to Rhino'​s file search path.//
 +
 +===== Question =====
 +Is there a way to add a file path to Rhino'​s file search path without having to script the Options command?
 +
 +===== Answer =====
 +Rhino'​s file search path is held by Rhino'​s **CRhinoDirectoryManager** object. You can get the one and only **CRhinoDirectoryManager** object as follows:
 +
 +==== C++ ====
 +<code c++>
 +CRhinoDirectoryManager&​ dm = RhinoApp().RhinoDirectoryManager();​
 +</​code>​
 +
 +===== Example =====
 +The following utility function demonstrates how to add (insert append or insert) to Rhino'​s file search path.
 +
 +==== C++ ====
 +<code c++>
 +int RhAddSearchPath( const wchar_t* pszFolder, int index = -1 )
 +{
 +  int rc = -1;
 +  if( 0 == pszFolder || 0 == pszFolder[0] )
 +    return -1;
 +
 +  int rc = -1;
 +  if( CRhinoFileUtilities::​DirExists(pszFolder) )
 +  {
 +    CRhinoDirectoryManager&​ dm = RhinoApp().RhinoDirectoryManager();​
 +    const int path_count = dm.SearchPathCount();​
 +    for( int i = 0; i < path_count; i++ )
 +    {
 +      if( 0 == on_wcsicmp(pszFolder,​ dm.SearchPath(i)) )
 +      {
 +        rc = i;
 +        break;
 +      }
 +    }
 +
 +    if( rc == -1 )
 +    {
 +      index = RHINO_CLAMP( index, -1, path_count );
 +      if( index == -1 )
 +        rc = dm.AppendSearchPath( pszFolder );
 +      else if( dm.InsertSearchPath(index,​ pszFolder) )
 +        rc = index;
 +    }
 +  }
 +  return rc;
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/addsearchpath.txt ยท Last modified: 2015/09/14 (external edit)