The visibility for the Component is done by highlighting. When you include a model or view segment key to the off-screen window, the visibility that you changed for the components is not applied because the keypath for the highlight doesn’t work for the off-screen window.
If you want to apply the visibility that you set to the off-screen window, you can use WindowKey::FindHighlights() to find all the active Highlights. Then, you can set the highlight to the off-screen window for each of them that is a Hide or Show style with the correct keypath of the component.
Highlighting — HOOPS Visualize Desktop Documentation
You can get the style and keypath using HighlightSearchResultsIterator. The keypath for the style has the main view as part of the path. You can replace the main view in the path with the offscreen view, and add the results as new highlights in the offscreen window. The name of the style for hide is like “sprk_view_hide”,
The following code can be used in the MFC Sandbox;
void CHPSView::OnUserCode()
{
View view = GetCanvas().GetFrontView();
WindowKey winkey = GetCanvas().GetWindowKey();
HighlightSearchOptionsKit options;
HighlightSearchResults result;
// Get Highlights
size_t numHighlights = winkey.FindHighlights(options, result);
HighlightSearchResultsIterator it = result.GetIterator();
KeyPathArray apath;
UTF8Array stylenames;
while (it.IsValid()) {
UTF8 style_name = it.GetStyleName();
stylenames.push_back(style_name);
KeyPath path = it.GetItem();
apath.push_back(path);
++it;
}
OffScreenWindowOptionsKit oswok;
oswok.SetDriver(Window::Driver::Default3D).SetAntiAliasCapable(true);
unsigned int width, height;
winkey.GetWindowInfoControl().ShowPhysicalPixels(width, height);
OffScreenWindowKey offscreenWindowKey = Database::CreateOffScreenWindow(width, height, oswok);
HPS::IncludeKey includekey = offscreenWindowKey.IncludeSegment(view.GetSegmentKey());// include view key
for (int i = 0; i < numHighlights; ++i)
{
KeyArray keys;
apath[i].ShowKeys(keys);
keys.pop_back(); // remove layout include key
keys.pop_back(); // remove view include key
keys.push_back(includekey); // add view include key which is inlucded to offscreenWindowKey
// Set highlight to offscreen Window
HPS::HighlightOptionsKit highlihtoption;
highlihtoption.SetStyleName(stylenames[i]);
offscreenWindowKey.GetHighlightControl().Highlight(keys, highlihtoption, false);
}
UpdateNotifier updateNotifier = offscreenWindowKey.UpdateWithNotifier();
updateNotifier.Wait();
HPS::Image::ExportOptionsKit kit;
kit.SetFormat(HPS::Image::Format::Jpeg);
HPS::Image::File::Export("image_export_offscreen.jpeg", offscreenWindowKey, kit);
}

