1

I'm trying to activate a viewport using Jeremy's Keys on a sheet and I am able to do it while doing Debug Step-Through but for some reason, it doesn't work when live.

I've tried the following:

1) using a while loop to wait for the active view to be the viewport's view but it doesn't seem to fire.

2) putting it in a separate transaction

3) tried using System.Threading.Thread.Sleep(2000);

4) started looking into Async, await however I'm not that skilled with it yet.

Has anyone else come across this issue and found a solution?

My current Sudo code is similar to the title of the question.

draw a temporary line across viewport

doc.showElements(temporaryline)

delete temporary line

Select viewport

Press.Keys("AV") (AV is my shortcut for activating a view when the viewport is selected)

I can upload actual code if needed

////////////////UPDATE///////////////// here is the culprit

//change views to sheet
uidoc.ShowElements(viewportElement); 


//select viewport
uidoc.Selection.SetElementIds(elementIdsViewPort);

//activate viewport
Press.Keys("AV");


Cflux
  • 1,423
  • 3
  • 19
  • 39
  • You should be able to do this - although you may need to use an External Event. If it written in Python, could you post your code? – Callum Jun 14 '20 at 21:20
  • @Callum, could you speak more on the external event or provide an example? My code is written in C#. – Cflux Jun 16 '20 at 16:00
  • @Callum, I've updated the question to show the code. feel free to try it on your end. I've found that If I comment out the `showElements` line and already have the sheet open, the viewport will activate. – Cflux Jun 16 '20 at 20:12
  • Nope Im stumped. In Python you can use `System.Windows.Forms` `SendKeys` to do all sorts of stuff like this, but it doesnt seem to trigger Revits hotkeys. You can set up a timer, then click on a Parameter input field or start a Text note and have a timer input 'AV' as if its a user pressing the keys ... but if you have a viewport selected, it doesnt register. Strange! – Callum Jun 17 '20 at 03:24
  • 1
    @Callum, very strange indeed. thanks for looking into it. I've made a bit of headway into it using Async / Await methods. I'm now able to change views and then zoom extents of view which is nice. Cheers to "building the car as you're driving it" – Cflux Jun 17 '20 at 17:12
  • 1
    Got it working with Async/await Tasks. ¯\_(ツ)_/¯ [this post helped](https://stackoverflow.com/questions/29089417/c-sharp-wait-until-condition-is-true) – Cflux Jun 17 '20 at 21:01

1 Answers1

0

I can imagine that possibly Revit will do nothing at all to activate the view as long as your add-in is active. You need to relinquish control back to Revit in able for it to be able to do anything at all. Revit is single-threaded, and the add-in hogs the single thread. I believe.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Interesting. After more testing, if it goes without stepping through, it seems to work maybe 2 out of 5 times the way I want it to. if I step through, it works every time. It seems like I need a way of slowing down the process but also needing it to not freeze. Something like a pause button. – Cflux Jun 14 '20 at 14:19