How to: Find a point on the surface of a model given a known window point

As part of the SelectionItem class in HPS, there is the function ShowSelectionPosition():
Depending on the variant of the function, it will return a WindowPoint or WorldPoint.

To demonstrate getting a WorldPoint, below is a code snippet that can be executed in the hps_mfc_sandbox Visual Studio project found in the directory:

void CHPSView::OnUserCode3()
	//First load model then run user code
	SegmentKey modelKey = _canvas.GetAttachedLayout().GetAttachedView().GetAttachedModel().GetSegmentKey();
	SegmentKey subsegmentKey = modelKey.Subsegment("sub");
	View view = _canvas.GetAttachedLayout().GetAttachedView();

	//Set a point in window space, for example, right in the center
	WindowPoint wp0(0, 0);

	SelectionOptionsKit selectionOptions;
	SelectionResults selectionResults;
	size_t numberOfSelectedItems;
	numberOfSelectedItems = _canvas.GetWindowKey().GetSelectionControl().SelectByPoint(wp0, selectionOptions, selectionResults);

	SelectionResultsIterator it = selectionResults.GetIterator();
	WorldPoint selectionPosition;

	while (it.IsValid())
		KeyPath selectionPath;
		SelectionItem selection = it.GetItem();

		//Get the position of the selection


	//Insert marker in World space


A short video (with audio narration) demonstrating the code is also available: