Message 1 of 17
Not able to add views on sheet correctly - viewport

Not applicable
04-17-2018
01:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good afternoon all,
I'm trying to create a viewport on a sheet by adding the view on a sheet but the code doesn't seem to be working for me. Because whenever I run the code the Viewport.CanAddViewToSheet() method returns false. I'm not sure what I'm doing wrong. Here's the code below, would appreciate any help.
public static void MoveViewOnSheet(View view, Sheet sheet, Document doc) { var revitView = doc.GetElement(view.ElementID) as ViewPlan; var revitSheet = doc.GetElement(sheet.ElementID) as ViewSheet; // Map the view on sheet using (Transaction transaction = new Transaction(doc, "Mapping views on sheet")) { if (Viewport.CanAddViewToSheet(doc, revitSheet.Id, revitView.Id)) { transaction.Start(); Viewport.Create(doc, revitSheet.Id, revitView.Id, XYZ.Zero); transaction.Commit(); } } }