Can I find the index of the selected ViewItem?

Can I find the index of the selected ViewItem?

‘Index’ is a numeric variable used in the ViewAndLayoutItem class.

We are developing a milestone plugin.(Plugin Integration)

I checked with “SelectedCameraChangedIndication”, but the Index was not known.

I have one more question.

Can I select a ViewItem using Index?

Please help me. Thank You.

I have had this struggle myself. I hope you can use my code snippet.

..
EnvironmentManager.Instance.RegisterReceiver(SelectedCameraChangedHandler,
                new MessageIdFilter(MessageId.SmartClient.SelectedCameraChangedIndication));
..
 
private object SelectedCameraChangedHandler(VideoOS.Platform.Messaging.Message message, FQID dest, FQID source)
{
	// Source is the window (if null Main Window)
	Item window = null;
	window = getWindow(source);
	_window = window.FQID;
	
	if (message.RelatedFQID == null)
	{
		//no camera (cannot find index)
	}
	else
	{
		Item viewItemInstance = getCurrentViewItem(window, message.RelatedFQID.ObjectId);
		_index = getIndex(viewItemInstance);
	}
	return null;
}
 
private Item getWindow(FQID source)
{
	Item window = null;
	if (source != null)
	{
		window = Configuration.Instance.GetItem(source);
	}
	else
	{
		List<Item> windows = Configuration.Instance.GetItemsByKind(Kind.Window);
		foreach (Item wi in windows)
		{
			if (wi.Name == "Main Window")
			{
				window = wi;
			}
		}
	}
	return window;
}
 
private Item getCurrentViewItem(Item window, Guid search)
{
	List<Item> views = window.GetChildren();
	foreach (Item view in views)
	{
		List<Item> viewItemInstances = view.GetChildren();
		foreach (Item viewItemInstance in viewItemInstances)
		{
			string currentCamGuid;
			if (viewItemInstance.Properties.TryGetValue("CurrentCameraId", out currentCamGuid))
			{
				if (currentCamGuid.ToLower() == search.ToString().ToLower()) //this is our viewitem
				{
					return viewItemInstance;
				}
			}
		}
	}
	return null;
}

On the second question. I have taken the next code snippet from Smart Client View and Windows Tool plugin sample -

EnvironmentManager.Instance.SendMessage(
                new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.SetSelectedViewItemCommand,
                    new SetSelectedViewItemData() { MoveCommand = MoveCommand.MoveIndex, LayoutIndex=1 }));

I can not use it for a few reasons, but thank you.

- Empty ViewItem

- Multiple cameras with the same FQID

I hope you will get a message like “GetSelectedViewItemCommand” even later.

Have a nice day

Milestone Development will develop this. In MIP SDK 2018R1 used in Smart Client 2018R1 there will be a new message “MessageId.SmartClient.SelectedViewItemChangedIndication” that will include the ViewItemInstance.

Thank you very much :slight_smile: