How to make a graphical view active ?

How to make a graphical view active ?

daniel
Enthusiast Enthusiast
1,998 Views
9 Replies
Message 1 of 10

How to make a graphical view active ?

daniel
Enthusiast
Enthusiast

HI , 

I have implementet a dockable panel, which i have put som click and drag functionality..

 

when dropping from this panel, I need the active graphichal window to be active hand have focus...

 

Is there av way of doing this? 

 

I do set the UIDocument.ActiveView to the last active graphical window, but it seems not to give the window foucs.

 

Do I need to go to Windows API like Revitilizer suggested in this post? 

 

http://forums.autodesk.com/t5/revit-api/dockable-dialog-and-promptforfamilyinstanceplacement/m-p/541...

 

Daniel

0 Likes
1,999 Views
9 Replies
Replies (9)
Message 2 of 10

jeremytammik
Autodesk
Autodesk

Dear Daniel,

 

Thank you for your query.

 

I would have thought that there should be some way of doing this using the Revit API, without having to resort to the Windows API.

 

Have you tried to use the UIApplication.OpenAndActivateDocument method?

 

That should definitely bring the document and a graphical view of it into focus.

 

I am not sure whether it will be the view that you need, nor whether it can be used if the document is already active.

 

Go ahean, give it a try, and please let us know how it goes.

 

Otherwise, I would go for Revitalizer's suggestion.

 

He knows his stuff.

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 10

arnostlobel
Alumni
Alumni

Generally UIDocument.ActiveView shoudl give the newly activated view focus, but it greatly depends on when the ActiveView property is invoked. For example, when it is invoked from an UI event (such as Idling, but also External Event which is triggered during Idling), Revit cannot process incoming windows messages (including focus setting) while still waiting for the execution of the UI events (e.g. Idling). I believe that it's why we generally do not recommend calling API which has UI implications from modeless dialogs.

Arnošt Löbel
0 Likes
Message 4 of 10

daniel
Enthusiast
Enthusiast

 

I'll have a go at it.. 

 

Info;

This is why my families don't show ut at the mouse befor after the first click in a window (ref: discussion at RTC , familybrowser.. ) 

 

I have activatede the symbol, but the problem is just to get the window active.. 

 

If i have windows tiled, and click on the border, then tries to place a family, everything works perfect.. 

 

 

 

Daniel 

0 Likes
Message 5 of 10

jeremytammik
Autodesk
Autodesk

Maybe the Windows API SetForegroundWindow function can help?

 

http://thebuildingcoder.typepad.com/blog/2013/12/triggering-immediate-external-event-execute.html

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 10

Revitalizer
Advisor
Advisor

Hi Daniel,

 

There is a UIDocument.RequestViewChange(view) method, maybe you want to have a look at this ?

 

 

Revitalizer (who was also on RTC)




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 7 of 10

daniel
Enthusiast
Enthusiast

Hi,

 

I did try to invoke the  RequestViewChange, now, and it seems to be the same problem.

I think it due to the things arnostlobel said, that the command does not get executed..

 

Maybee I could trigger Revit to do this command first, then continue ?

 

 

I will try the suggestion from Jeremy on getforegroundwindow..

 

 

 

This is how i load the family when dropped today..

 

if (loadedFamily != null)

{

var famsymids = loadedFamily.GetFamilySymbolIds();

var firstSymbol = activUiDoc.Document.GetElement(famsymids.First()) as FamilySymbol;

 

if (firstSymbol != null)

{

if (!firstSymbol.IsActive)

{

 

using (var t = new Transaction(activUiDoc.Document))

{

t.Start("Aktiver symbol");

firstSymbol.Activate();

t.Commit();

}

}

activUiDoc.RequestViewChange(activUiDoc.ActiveGraphicalView);

 

try

{

activUiDoc.PromptForFamilyInstancePlacement(firstSymbol);

}

catch (Exception e)

{

if (e.GetBaseException() is Autodesk.Revit.Exceptions.InvalidOperationException && e.Message.Equals("This family symbol has no command to create an instance."))

{

DialogHelper.InfoMsg("Familien kan ikke plasseres direkte, men er lastet inn i prosjektet");

return;

}

}

}

 

return;

}

 

0 Likes
Message 8 of 10

arnostlobel
Alumni
Alumni
RequestViewChange cannot be used in this scenario. It is an async request that does not get processed until after the API give control back to Revit. ActiveView is the method to use when wanting to switch view and continue working in the newly activate view. However, like I mentioned, there are limitations to it very depending on the time when the method is used. If it is during an event that was triggered by a windows message, such as window focus changed, Idling, etc., changing the active view is unlikely to work, because Revit will not have time to process is while still executing the previous windows message. Arno?t
Arnošt Löbel
0 Likes
Message 9 of 10

daniel
Enthusiast
Enthusiast

So maybee this problem should be raised as a change order request ? 

 

When using "PromptForFamilyInstancePlacement" (and similare) 

The active graphical view should be brougt in focus. 

 

Since the promt placment is going to put someting in a graphical view, it need to be active... 

 

(and it does when clicked once, but then an instance also get placed.. ) 

 

 

 

 

0 Likes
Message 10 of 10

arnostlobel
Alumni
Alumni
Yes, possibly. Either the active graphic window should be brought into focus, or the Placement method could take a view to activate. Arno?t
Arnošt Löbel
0 Likes