Jochen Reichert of the University of Stuttgart asks: How can I determine all the view ports of a drawing sheet and vice versa?
To determine the view ports of a drawing sheet, you can simply use the ViewSheet Views property. It returns the set of all views on the sheet. For the inverse relationship, you can create a mapping of your own as described in the discussion on inverting the relationship between hosted und hosting elements such as doors, windows and walls. Here is some code demonstrating this for the viewport and view sheet relationships. It sets up two mappings, one from each view sheet to all its contained viewports, the other from each viewport to the view sheet containing it, which we expect to be unique:
Application app = commandData.Application; Document doc = app.ActiveDocument; List<Element> sheets = new List<Element>(); doc.get_Elements( typeof( ViewSheet ), sheets ); // map with key = sheet element id and // value = list of viewport element ids: Dictionary<ElementId, List<ElementId>> mapSheetToViewport = new Dictionary<ElementId, List<ElementId>>(); // map with key = viewport element id and // value = sheet element id: Dictionary<ElementId, ElementId> mapViewportToSheet = new Dictionary<ElementId, ElementId>(); foreach( ViewSheet sheet in sheets ) { int n = sheet.Views.Size; Debug.WriteLine( string.Format( "Sheet {0} contains {1} view{2}: ", Util.ElementDescription( sheet ), n, Util.PluralSuffix( n ) ) ); ElementId idSheet = sheet.Id; foreach( View v in sheet.Views ) { Debug.WriteLine( " Viewport " + Util.ElementDescription( v ) ); if( !mapSheetToViewport.ContainsKey( idSheet ) ) { mapSheetToViewport.Add( idSheet, new List<ElementId>() ); } mapSheetToViewport[idSheet].Add( v.Id ); Debug.Assert( !mapViewportToSheet.ContainsKey( v.Id ), "expected viewport to be contained" + " in only one single sheet" ); mapViewportToSheet.Add( v.Id, idSheet ); } }
Here is the output generated for a simple model with three sheets:
Sheet Drawing Sheets <127148 Unnamed> contains 3 views: Viewport Views <29193 East> Viewport Views <29233 South> Viewport Views <29273 Site> Sheet Drawing Sheets <127162 Unnamed> contains 1 view: Viewport Views <13073 Level 1> Sheet Drawing Sheets <127176 Unnamed> contains 1 view: Viewport Views <15915 Level 2>
Here is version 1.0.0.18 of the complete Visual Studio solution with the new command CmdListViews discussed here.
How do I extract the coordinates of the viewports on the sheet? I can place a view on the sheet and supply the specific coordinates, so, I assume I can reverse this and extract the coordinates of the viewpsorts on a sheet. I've tried:
ViewSheet currentSheet = doc.ActiveView as ViewSheet;
foreach (Autodesk.Revit.Elements.View v in currentSheet.Views)
{
BoundingBoxUV loc = v.Outline;
MessageBox.Show("Coordiinates of: " + v.Name + ", " + v.ViewType + "\r\n" + loc.Min.U + ", " + loc.Min.V);
}
but the values returned don't appear correct.
Posted by: HarryC | October 12, 2009 at 16:53
Dear Harry,
I implemented an external command using the sample code you provided and was also initially unable to interpret the resulting coordinates returned by the View Outline property. According to the documentation, it returns the bounds of the view in paper space in inches. Running the code in a simple sample drawing did return something that looked vaguely reasonable:
Coordinates of FloorPlan view 'Level 1': (-0.88,-0.88)
Coordinates of FloorPlan view 'Level 2': (-0.58,-0.38)
Coordinates of Elevation view 'North': (-0.62,-0.06)
Coordinates of Elevation view 'East': (-0.45,-0.06)
On closer inspection, however, these coordinate values have no discernable relationship with the actual position of the views on the sheet.
I checked with my colleagues, and received the answer that you are not doing anything wrong, but unfortunately there is currently simply no API access to this information. Sorry for the bad news!
The information returned by View.Outline is not wrong in any way, it is just describing the size of the view and returning the bounding box of the origin of the view, not its position on the sheet.
Cheers, Jeremy.
Posted by: Jeremy Tammik | October 13, 2009 at 09:30
Thanks for that answer. At least I won't spend any more time trying to figure this one out. IT would be nice, in a future version of the API to be able to do this. I have 50+- typical sheets in our library and if I could programaticaly extract the position of the views, then I could use my complimentary routine to rebuild the sheets when view in the library is updated. I wrote a program to do this with the locations stored in an XML data file. So all our users can dynamically create typical sheets for their projects using the latest versions of our details. Pre assembled sheets are static and a pain to maintain / update as time goes on.
Posted by: HarryC | October 14, 2009 at 11:11
In that same train of thought. In the future API it would be nice to be able to access the GUI feature to "Insert from File -> Views...". Then my application to dynamically create the typical sheets in a project will be completely automated.
Unless there is a way to put all the drafting views into a family file. Then I could use the currently available API functions to do this.
Posted by: HarryC | October 14, 2009 at 11:39
One more question on views / viewports. Using the API can I assign the viewport type (ie: title family style) and the detail number property of the viewport once the view is placed on a sheet?
Posted by: HarryC | October 14, 2009 at 11:44
Dear Harry,
Yes, definitively, I see your point, and thank you for the suggestions and explanation!
This wish has been registered and this functionality will certainly become available at some point.
Cheers, Jeremy.
Posted by: Jeremy Tammik | October 15, 2009 at 04:31
Dear Harry,
Yes, definitively, the detail number property is accessible using the built-in parameter VIEWPORT_DETAIL_NUMBER, and its value can be both read and written to.
Use the Revit API intro built-in parameter checker to find out things like this, as described in
http://thebuildingcoder.typepad.com/blog/2009/04/deeper-parameter-exploration.html
I don't know what property 'viewport type (ie: title family style)' might refer to, but I am sure you will see it as soon as you check it out.
Cheers, Jeremy.
Posted by: Jeremy Tammik | October 15, 2009 at 04:42
Dear Harry,
Please keep good track of these wishes of yours and make sure to submit them all at every official opportunity that is offered, especially when the next API Wish List Survey comes around:
http://thebuildingcoder.typepad.com/blog/2009/07/api-wish-list-survey-reminder.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | October 15, 2009 at 04:47
Jeremy,
any new info around this thread? Will it come with 2012?
I urgently need the coordinates of each view on a certain sheet.
Unfortunately I searched quite a long time until I had the idea to search in your blog.
Kind regards, Thomas
Posted by: Thomas Fink | August 16, 2010 at 14:51
Dear Thomas,
There is no public information at all about any future versions of any products whatsoever that I know about.
When you say '2012', I must answer that I have no idea what you are talking about.
I am glad you thought about searching the blog, though. I try to make all information that I come across available here. It always applies exclusively to existing public versions, of course. I hope it won't take you so long to think of it next time you need something :-)
Wish list items are better handled by an ADN request, though.
Cheers, Jeremy.
Posted by: Jeremy Tammik | August 16, 2010 at 22:23
Hi Jeremy,
I know this is an old thread but I didnt find any thread that similar with my problem.
I want to insert an image on the sheet programatically based on the origin (0, 0, 0) at the bottom left. I knew from your blog that the sheet not provide the information about coordinate.
So to get the exact location for my image, I play around with the coordinate value until I get the correct position which is at top right. I have to hardcoded all the position for each type of sheet.
My question is:
Is there any possibility that the origin are different between type of sheet or if user create their own sheet?
Thank you.
Abby
Posted by: abby | July 11, 2013 at 21:43
Dear Abby,
I would assume yes.
You would have to research for yourself, though, e.g. using RevitLookup.
Here is another old but slightly less outdated post on a related topic:
http://thebuildingcoder.typepad.com/blog/2010/09/view-location-on-sheet.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | July 12, 2013 at 06:40
Hi Jeremy,
I can't figure out a way to get a handle on a Viewport's *title* so as to resize or move it on the ViewSheet (note: I'm referring to the viewport's *title*, not the viewport itself)
A worrying fact is that there's no elementID on the title symbol:
- go to a sheet with at least a viewport whose type defines a title symbol,
- click on the title so as to highlight it
- use Revit's "Element ID" to try to reveal its ID
- but it comes back empty!
I suspect that Viewport title is a private member of the Viewport class and the API does not expose anything about it. Shouldn't it at least expose methods to manipulate 1) the title's position and 2) the title line's length?
Warm regards,
Elias
Posted by: Elias Karakoulakis | February 22, 2014 at 14:04