UIDoc.Selection as a ViewSheet is empty

UIDoc.Selection as a ViewSheet is empty

pgibsonHVST5
Contributor Contributor
1,946 Views
10 Replies
Message 1 of 11

UIDoc.Selection as a ViewSheet is empty

pgibsonHVST5
Contributor
Contributor

I have a few little sheet maintenance and setup tools in an add in, and I'm trying to streamline them a bit by letting the user select a sheet and then run the addin so that the selected sheet becomes the default sheet for the add in logic.  But the UI seems to not want to let me do this.  I select a sheet in the Project Browser, and then go to the ribbon which will not respond (this is a general problem, not specific to the addin).  So instead I open the sheet, and verify that the properties window shows the sheet (I believe this means that the sheet is selected, but perhaps this is my error?).  I then run the addin, which has in the IExternalCommand Execute function:

 

            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            Selection selection = uidoc.Selection;
            ICollection<ElementId> sIds = selection.GetElementIds();

But sIds is empty.  I'm not sure exactly what the problem is but could it be related to the fact that I can't run the addin directly after selecting a sheet in the ProjectBrowser (and seeing it highlighted) due the unresponsive ribbon.  Or is it that a ViewSheet cannot be part of the selection set accessed by the API?

 

Even more ideally from a work flow standpoint would be the ability to right-click a sheet in the project browser and have a hook to the addin Execute Method in the context menu, but I have not seen (or if I have understood) how that might be accomplished.

Accepted solutions (1)
1,947 Views
10 Replies
Replies (10)
Message 2 of 11

matthew_taylor
Advisor
Advisor

Hi,

Which version of Revit are you having issues with?

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 11

pgibsonHVST5
Contributor
Contributor

I am using Revit 2016 on Windows 10.  I don't remember it happening when I was using Windows 7 . . . but I cannot be sure about that.

0 Likes
Message 4 of 11

matthew_taylor
Advisor
Advisor

Hi,

Your code is fine. You should be able to do what you're trying to do.

 

The execution and change of focus is where this sort of thing causes an issue.

Debugging using the add-in manager (AIM) or something like that won't allow selection of this type. (The focus is taken away from the project browser.)

Hook it up to an actual ribbon button and you should be okay. It's a hell of a way to debug, but it's the only thing I've found that works consistently. You need to take care of where the 'focus' is.

 

If you check the selection and either there is nothing selected or the elements aren't viewsheets, then pop up a dialog to allow the user to select them. This is a workflow that the user would relate to, and also help you debug in a non-ribbon button context.

 

Let me know how you get on.

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 5 of 11

pgibsonHVST5
Contributor
Contributor

Hi Matt,

 

Thanks for your attention and time.

 

This addin is properly registered and hooked up to the ribbon panel (it appears under the add-ins tab, as I'm showing here):MOAToolsOnRibbon.PNG

I have verified that the behavior is the same with a release version on a non development machine.  Selecting a sheet in the project bowser, and then going to the ribbon panel does not work.  In fact, if I select on anything in either the properties panel, or in the project browser the ribbon panel is unresponsive until I select something in the main revit window first.  I think this must be a bug in my revit install, or in revit under windows 10 . . . the project browser window blinks when it has focus and I click on anything in the ribbon area.  I don't remember this behavior in Windows 7.  

 

0 Likes
Message 6 of 11

matthew_taylor
Advisor
Advisor

Hi @pgibsonHVST5,

No problem. Sorry you're not finding a way through so far!

 

Some other things to check out:

  • Try another version of Revit.
  • Use a stripped down 'built from scratch' version to see if something else in your code is interfering.
  • Consider adding a (test) button that is just a just a basic button not a splitbutton.

If the above don't help, consider stripping down your code to the button and the selection code and either posting that or private messaging a link to it. I'd be happy to test it on my Windows 7 machine.

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 7 of 11

pgibsonHVST5
Contributor
Contributor

Hi Matt,

 

Thanks again for your assistance.  I am thinking you misunderstand . . . the behavior is not revit with my addin, the behavior is revit, and it affects my addin: when I select something in the project browser, the revit ribbon is then unresponsive . . . all of the revit ribbon, not just the addins panel, but the architecture, modify, annotate, manage, etc, the entire revit ribbon.  I don't remember this being the case in Windows 7, but I cannot verify.

0 Likes
Message 8 of 11

pgibsonHVST5
Contributor
Contributor
Accepted solution

I have solved this by using the active view . . . if it is a viewsheet then I use it.  If not then I ignore and let the user select a viewsheet from a dropdown which has been the way it works.  A reasonable compromise that just means we have to open the sheet we want to use in the addin before running the command.

 

UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
ViewSheet vs = null;

if (uidoc.ActiveView.ViewType == ViewType.DrawingSheet)
{
      vs = uidoc.ActiveView as ViewSheet;
}
0 Likes
Message 9 of 11

matthew_taylor
Advisor
Advisor

Hi,

I was trying to see if there was something else causing your issue other than Win10.

I can attest that the method you wanted to use works fine on my Win7 installation.

You may want to check out this article: https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Window...

 

I'm glad you found a workflow (similar to the one I suggested) that is a suitable compromise.

 

If you have to support Win7 and Win10, a check of the operating system could allow you to add full functionality to Windows 7.

Environment.OSVersion.Version

-Matt

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 10 of 11

pgibsonHVST5
Contributor
Contributor

After using my plugin for a while I have noticed something interesting: If the project browser window is docked inside the revit main window then the problem I noted (ribbon wont respond) does not occur.  This problem only occurs if the project browser panel is floating free (combined with properties palette or not makes no difference).  Perhaps this is something that Revit can fix down the road . . . 

0 Likes
Message 11 of 11

joshua.lumley
Advocate
Advocate

Thank you this is a good solution

0 Likes