Friday, December 21, 2007

Dumb Revit API Trick...

So I stumbled across something in the Revit API the other day. Probably impractical - but I figured I'd pass it on.

I'd been frustrated in the past with two aspects of Revit development (ok, far, far more than two - but I'm talking about two specific things in this context :) ).

- You can't change the active view in a Revit document.
- Although you can load a document or create a new document, it didn't do it VISUALLY... That is, it's done in Revit's memory - but it's only programmatic, the user never sees it.

Both of these things seem to limit what you could use the API to do - right?

Anyway, I was poking around with RvtMgdDbg, the object browsing tool provided to ADN members - and it has a few test utilities. I tried out the printing one (knowing that the printing API also has so many problems with it that it wasn't worth pursuing) - but I noticed something... views and models were changing on the screen in front of me.

That's when it hit me. If you want to change the Active View - Print the one you want.
If you want to "show" a document you've loaded - Print it.

It's about the dumbest workaround I've ever come up with (and that's saying something) - and it will probably lead to further deforestation - but hey, it works!

Actually, what we would really need to make this almost usable is some kind of "null printer" driver which doesn't actually do anything - it just sends the printer bits into the black hole. Even with that, and as desperate as I sometimes am for a workaround, that's probably not a scalable solution. Of course, you would also need Autodesk to provide a way of specifying that printer, which is not available in 2008 - we can hope for 2009.

Ah well - I figured I'd pass it on.

4 comments:

Dave Baldacchino said...

How about printing to a PDF/DWF and then deleting the file automtically?

Matt Mason said...

Dave,

That would also work - although every time I have to re-figure out how to programmatically specify the PDF/DWF filename, so that it won't pop up a dialog box... I reach for the antacid.

-Matt

mcoviello said...

Hi Matt,
Have you found a way to "close all hidden" views after printing the activatied view?
I'd like to switch to a standard simple view on document saved or ideally on sync to central.
Thanks.

Matt Mason said...

Michael,

I don't know that there's a good way to Close all hidden views.

to switch to a standard view though - I've noticed that in the last couple of releases you can do a "ShowElements" to force the active view to change to something that you want.

-Matt