Is there an event for when a viewpoint is selected?

Is there an event for when a viewpoint is selected?

mtrainottiGHXJH
Enthusiast Enthusiast
1,252 Views
11 Replies
Message 1 of 12

Is there an event for when a viewpoint is selected?

mtrainottiGHXJH
Enthusiast
Enthusiast

There is functionality to determine the currently selected viewpoint: 

 

SavedItem CurrentVp = Autodesk.Navisworks.Api.Application.ActiveDocument.SavedViewpoints.CurrentSavedViewpoint;

 

However, if the user clicks away that value becomes null.

Because of this, I would like to store the last selected viewpoint but I cannot find in the documentation if there is an event that fires when a viewpoint is selected.

Thank you. 

0 Likes
Accepted solutions (1)
1,253 Views
11 Replies
Replies (11)
Message 2 of 12

alexisDVJML
Collaborator
Collaborator

Same issue here.

Very frustrating/inconsistent to have

Autodesk.Navisworks.Api.Application.ActiveDocument.SavedViewpoints.CurrentSavedViewpoint

changed to NULL even when the user does not change the item selected in Saved Viewpoints pane!

 

Didn't find a publicly available solution.
I implemented a proof of concept HACK to track Saved Viewpoints selection via its docking pane.

Will try to make it clean/independent from other stuff and put it here.

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 3 of 12

mtrainottiGHXJH
Enthusiast
Enthusiast

I would be interested to see what you came up with, please share. Thanks 🙂

0 Likes
Message 4 of 12

alexisDVJML
Collaborator
Collaborator

@mtrainottiGHXJH, Quick update,

 

1/ re: proof of concept HACK to track Saved Viewpoints selection via its docking pane:

My wrong. The "Saved ViewPoints" pane is not even registered as a DockPanePlugin.

However this approach can be used for the "Sets" pane to get an ObservableCollection of selected Sets.

I will post an example separately if you are interested.

 

2/ Now back to the "Saved ViewPoints" issue:

and specifically, when a SavedViewPoint is still selected in "Saved ViewPoints" pane BUT CurrentSavedViewpointChanged event is triggered and d.SavedViewpoints.CurrentSavedViewpoint return null.

 

Short term, I implemented a "hack" to handle such case by keeping "current" selected Saved VIew Point, and on such event, checking for unchanged Sectioning. Long term, I would like to rewrite our own Saved ViewPoints pane to replace the native one, that I guess is still a MFC or so remnant of old Navisworks

 

Here is an extract of my class that track changes in Selection Sets and Saved View point, to get you started:

 

//CRITICAL, clear on d.SavedViewpoints.Reset etc. to avoid keeping an dangling object.
protected SavedViewpoint pSelectedSavedViewPoint;

static private bool IsStillSameViewPoint(Document d, SavedViewpoint previous)
{
	if (previous is null || previous.IsDisposed)
		return false;

	LcOaClipPlaneSet previous_cps = previous.Viewpoint.InternalClipPlanes;
	LcOaClipPlaneSet current_cps = d.CurrentViewpoint.Value.InternalClipPlanes;

	return current_cps.ValueEquals(previous_cps);
}

protected virtual void OnCurrentSavedViewpointChanged(object sender, EventArgs e)
{
	//// on click single item, called twice, null for deselect then null if folder, SavedViewpoint if an actual viewpoint for select
	//// on multiple items selected, seems just give the last one clicked not necessary the last one in the tree order?
	//// we can't predict if we will get called twice so no choice
	var d = sender as Document;

	//// if no items selected, si is null
	var si = d.SavedViewpoints.CurrentSavedViewpoint;

	var svp = si as SavedViewpoint;
	if (svp == pSelectedSavedViewPoint)
		return;

	if (si == null && pSelectedSavedViewPoint != null && IsStillSameViewPoint(d, pSelectedSavedViewPoint))
		return;

	var old = pSelectedSavedViewPoint;
	pSelectedSavedViewPoint = svp;
	OnSelectedSavedViewpointChanged(d, new SelecteSavedViewPointChangedEventArgs(old, svp));
}

protected virtual void OnSelectedSavedViewpointChanged(Document d, SelecteSavedViewPointChangedEventArgs e)
{ }

 

 

 

 

@Navisworks team, please consider reimplementing this "Saved ViewPoints" pane in C#, cleanly as a DockPanePlugin.

I'm so frustrated with the current pane unpredictable drag & drop that works like once at of 4 times I can't imagine how many screens and keyboard have been destroyed just because of this 🤣

So you will make not only developers happybut lots of users I guess.

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 5 of 12

mtrainottiGHXJH
Enthusiast
Enthusiast

I ended up doing essentially the same thing, for my use case however I didn't need to check if it was different saved viewpoint so I just stored it as SavedItem and check for null on use.

 

Message 6 of 12

mtrainottiGHXJH
Enthusiast
Enthusiast
Accepted solution

For future readers:

The event for a change in the selected saved viewpoint is:  Autodesk.Navisworks.Api.Application.ActiveDocument.SavedViewpoints.CurrentSavedViewpointChanged;

You can bind this event to a method with: Autodesk.Navisworks.Api.Application.ActiveDocument.SavedViewpoints.CurrentSavedViewpointChanged += <your_method_here>;

Message 7 of 12

alexisDVJML
Collaborator
Collaborator

@naveen.kumar.t Please please, plead for us with the Engineering team.

We could do so many things if we can access the list of selected items in Saved Viewpoints, cf picture below.
Things like merging, renaming, grouping etc, not to mention Plugin specific features.
This would also settle cleanly the issue described in this thread instead of having really ugly and unreliable hacks.

Even if not officially supported, at our own risk, or need to sign a NDA with our blood, I'm fine as long as we can do it 😉

alexisDVJML_0-1687460036759.png
Thanks in advance.

 

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 8 of 12

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @alexisDVJML ,

 

I submitted a ticket to the Navisworks engineering team

 

NW-59274 - Expose Viewpoint selected events in the .NET API


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 9 of 12

mtrainottiGHXJH
Enthusiast
Enthusiast

It is also possible to make your own WPF tree view and interact with the api, such that you can keep track of which items are selected yourself. I actually started a mockup design of one a while back. It is definitely a good bit of work, but it would allow you to have custom UI elements in the saved viewpoint panel as well. Not trying to discount the idea of Navis exposing the selected elements, as that is a far more convenient solution haha.

Message 10 of 12

alexisDVJML
Collaborator
Collaborator
Yupz, I also considered this out of frustration 😉
I however asked my plugin users and they said it would be even more confusing/frustrating if they forgot to use the correct pane etc...
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 11 of 12

alexisDVJML
Collaborator
Collaborator
Thanks a lot.
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 12 of 12

alexisDVJML
Collaborator
Collaborator
And yes this is some work, kind of duplicated with the existing one.
Will revisit this idea if really can't go around.
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes