Skip to content

Instantly share code, notes, and snippets.

@johnmorse
Created June 25, 2013 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmorse/5861350 to your computer and use it in GitHub Desktop.
Save johnmorse/5861350 to your computer and use it in GitHub Desktop.
Demonstrates how to open a RUI file and display a specific tool bar group.
static bool ShowGroupFromRuiFile(const wchar_t* fullPathToRuiFile, const wchar_t* groupName, bool showFirstFroupIfNotFound)
{
ON_wString ruiFileName(fullPathToRuiFile);
if (ruiFileName.IsEmpty())
return false; // No RUI file name specified
// This flag should always be false since we are dealing with full path names
// and not RUI file aliases
bool nameIsAlias = false;
// Check to see if the file is open, there is nothing wrong with just calling
// FileOpen since it simply returns the currently open file UUID if the file
// was already opened or opens the file and then returns the file UUID.
bool isOpen = CRhinoUiFile::FileIsOpen(ruiFileName, nameIsAlias);
ON_UUID ruiFileId = ON_nil_uuid;
if (isOpen) // If the file is currently open then get the file ID
ruiFileId = CRhinoUiFile::FileID(ruiFileName, nameIsAlias);
else // Open the file
ruiFileId = CRhinoUiFile::FileOpen(ruiFileName);
// If the file did not open because it was not found or there was an error
// parsing the file.
if (ON_nil_uuid == ruiFileId)
{
RhinoApp().Print(L"Unable to open \"%s\" file\n", ruiFileName);
return false;
}
// Look for the specified group and get its UUID
ON_UUID groupToShow = ON_nil_uuid;
const int groupCount = CRhinoUiFile::GroupCount(ruiFileId);
for (int i = 0; groupName && *groupName && groupToShow == ON_nil_uuid && i < groupCount; i++)
{
ON_UUID groupId = CRhinoUiFile::GroupID(ruiFileId, i);
ON_wString groupName = CRhinoUiFile::GroupName(ruiFileId, groupId);
if (groupName.CompareNoCase(groupName) == 0)
groupToShow = groupId;
}
// If the group was not found or no group was specified and there are one or
// more groups in the file and "showFirstFroupIfNotFound" is true then get
// the UUID for the first group in the file
if (groupToShow == ON_nil_uuid && groupCount > 0 && showFirstFroupIfNotFound)
groupToShow = CRhinoUiFile::GroupID(ruiFileId, 0);
// If no group was found and showFirstFroupIfNotFound is set to false
if (groupToShow == ON_nil_uuid && !showFirstFroupIfNotFound)
{
RhinoApp().Print(L"No groups found in file \"%s\"\n", ruiFileName);
return false;
}
// If a group was found then show it, no need to check if it is currently
// visible before calling show.
if (groupToShow != ON_nil_uuid)
CRhinoUiFile::GroupShow(ruiFileId, groupToShow, true);
return true;
}
static void Test()
{
// Display the "Standard Toolbar Group" from the default rhino RUI file
ON_wString defaultrui;
CRhinoFileUtilities::GetDefaultRuiFilename(defaultrui);
bool success = ShowGroupFromRuiFile(defaultrui, L"Standard Toolbar Group", true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment