Revit API C# - ShowElements of ViewSheet, Select ViewPort, Activate Viewport works during Debug Step through but not live - revit-api

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");

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.

Related

JavaFX request layout does nothing

I'm absolutely confused.
Studying JavaFX for several months.
In my application I have a custom scrollpane, where I recount scrollbar values manually. Everything is OK there. And when I resize the window it also works fine.
The problem appears when I launch application the first time. I see that my scrollbar value is incorrect, and it become correct when I resize window or move the pane placed inside scrollpane.
So theoretically all i need is just update my scrollpane on window start, or after window start. And... I've spent more than week trying to find out how. And the only way I've managed to do this is to call layoutChildren recursively. This is awful of course.
layout() - doesn't have any effect. I tried it with runLater() and placed it inside timer call. No way!
requestLayout() - also makes no sense.
Is it possible just UPDATE or REDRAW or MARK CONTROL TREE AS DIRTY in JAVAFX ???
Ok well, try this way
first gaining the focus, then try relayout options..
blah.requestFocus();
blah.layout();
Well. layout() works. But it shouldn't be placed inside Platform.runLater().
In simple example everything is fine. Then I suggest I have something wrong with my controls.
Thanks.

MergDataGridScroller: How to save + restore position?

Is there an easy way to save the vertical/horizontal scroll position of the datagrid scroller used inside the MergDataGridScroller? Want to be able to go back to the same card and have the datagrid open at the same location as it previously was.
It seems that the datagrid scroller is created/destroyed on the open/close-Card cycle, otherwise I could just hide it.
Perhaps this is one of those situations where it's easier to "roll my own"?
Any help appreciated - thanks!
Yes the scroller is created and destroyed as you open and close cards. I think this is something that should be supported but isn't currently. Basically it's just a matter of not resetting the scroll of the group and then setting the native scroller to the scroll of the group when it's created. Should just be a couple of tweaks to the handleLayout command in the behaviour. I'm not sure about maintaining scroll when the content rect changes. I can look at that too.
So in answer to you question rather than roll your own you have a couple of choices:
Wait for me to do it and release a new version
Edit the behaivior script with whatever changes you like
EDIT
I've done this now ;-)

Howto prevent a CFrameWnd from being mouse moved

I have an application that displays a CFrameWnd that is displayed on top of the main window. I need the window to be non-movable and non-resizable when the user selects a certain mode for the window.
My CFrameWnd is created with the styles WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_POPUP
I have come across a solution using an overload of CWndOnNcHitTest to rewrite
HTLEFT,HTRIGHT,HTTOP,HTTOPLEFT,HTTOPRIGHT,HTBOTTOM,HTBOTTOMLEFT,HTBOTTOMRIGHT,HTSIZE,HTCAPTIONto HTBORDERto prevent the framework to recognize the areas responsible for sizing / moving.
This method works well for resizing in my case, but moving the window is still possible, although the hittest override works correctly (verified with traces).
Is there anything wrong in my approach, or could there be something interfering with this solution and if so, do you have any tips on where to look?
You should be able to make OnNcHitTest() work, don't return HTCAPTION.
Still, there's more than one way to move/size a window, you also have to worry about the system menu (type Alt+Space). Write a message handler for WM_MOVING and WM_SIZING and override the RECT so the window stays put.

Problems with refreshing a draggable MFC window

Greetings.
I have to make a draggable MFC dialog window, which has a background - used that: http://www.codeproject.com/KB/graphics/picturewindow.aspx - and has several picturebox controls. I have tried two approaches, and while they do work, they have some problems.
First approach is "Manual" - on the LBUTTONDOWN message I check if it;s on a clean area of my window, and set a flag variable. On MOUSEMOVE, the flag is checked and if it's set, a MoveWindow function is called, and then, Invalidate(1). On LBUTTONUP, flag is unset.
This approach works correctly and redraws as needed, but is somehow very slow - if I'm moving the cursor too fast, the window falls behing and isn't dragged, as cursor's not over the window anymore.
The second approach is "Automatic" - I just call
DefWindowProc(WM_SYSCOMMAND, SC_MOVE+2,MAKELPARAM(point.x,point.y));
on LBUTTONDOWN, and it handles the rest, it's quick and never fall behind, but when I drag it over screen's edge ( so that some part of the window gets invisible), when I drag it back, all the controls get invisible and are not refreshed, background is okay. I suppose that's because Invalidate() isn't called during movement that way, as I actually call it after calling DefWindowProc() and so, everything is refreshed properly when I depress the button.
What should I do to improve either of those solutions? I need it both fast and correct. I may have not provided some required information, I'll add it is need arise.
Thanks in advance.
Solved the problem, by modifying the second way. I added a total redraw to the OnPaint(), and to get rid of flicker, I only redraw durng dragging, by using a flag variable.

Components in module disappear when browser is resized (Flex 3)

We have this Flex app built on Builder 3 and we're using SuperTabNavigator from FlexLib to have some modules displayed. The thing is, whenever the user resizes the browser window all the contents on any tabs open simply disappear and there's no way to get them back. This only happens the first time, so if you close these 'broken' tabs and reopen them, you can resize all you want, but you still lost all you were doing in them and this is unacceptable. I've done some testing and found the module in that tab doesn't dispatch the resize events when this happens. It's dispatched when it opens (everything is set to 100% to fit the browser window, so it resizes on startup) and every other time you resize it without 'breaking' it. It gets weirder. I've also found that resizing works perfectly as long as you resize it to a size larger than the original (i.e. you open it in a browser window that is restored and then maximized), but even after doing that, if you change its size back to something even a pixel smaller than the original, the module just disappears. Everything else remains in perfect working conditions: any components outside tabs and the tabs itself work, but (summing up) anything within any tab open at the moment you first resize the browser window to a size smaller than the original just disappears.
I understand that this is a weird problem and hope some of you might be able to help me. Feel free to ask any questions if anything wasn't clear.
Thanks in advance.
I had this exact same problem with my application. The issue stemmed from the fact that the RemovedFromStage event was being fired when the window was sized smaller than its original size. I was catching the RemovedFromStage event and hiding my component, which resulted in this behavior. A more detailed explanation can be found here.

Resources