Issues with Viewport.CanAddViewToSheet method

Issues with Viewport.CanAddViewToSheet method

Anonymous
Not applicable
718 Views
6 Replies
Message 1 of 7

Issues with Viewport.CanAddViewToSheet method

Anonymous
Not applicable

Dear All,

Despite the fact,  all the conditions for view placement on sheet are met, Viewport.CanAddViewToSheet method constantly returns false value;

 

bool result = Viewport.CanAddViewToSheet(view.Document, view.Id, sheet.Id);

 

However, if I try to place the view on the sheet without checking whether the view CanAddViewToSheet, everything works fine. I provide the same input arguments in both cases.

 

Viewport.Create(view.Document, sheet.Id, view.Id, new XYZ(000));

 

I have seen, that a year ago @Anonymous asked the same question in the post:

https://forums.autodesk.com/t5/revit-api-forum/how-to-add-views-on-a-sheet/td-p/7935024

and was not answered. Does anyone experienced similar issues with this method?

Edit: I use views of ViewPlan class 

 

0 Likes
719 Views
6 Replies
Replies (6)
Message 2 of 7

recepagah12
Advocate
Advocate

I tried the same code you provided in Revit 2020 and it returned true. Maybe your file has been corrupted or your sheet, the view has a problem about that method. Can you provide a sample file?

 

I hope this helps,

Recep.

0 Likes
Message 3 of 7

Anonymous
Not applicable

Here is the file.

Views are placed on sheets only if this line is off: (full code is provided in the macro)

 

Capture.JPG

0 Likes
Message 4 of 7

Anonymous
Not applicable

Does anyone?

I was looking for workarounds, and what I noticed is that views that are placed on sheet has the parameter:

'Sheet Number', whilst views that are not placed don't. Do you think this could be a good direction to check whether view is already placed on sheet?

 

Capture.JPG

 

0 Likes
Message 5 of 7

mizrachi_amir2
Advocate
Advocate

@Anonymous , 5 years later - did you manage to figure it out?

0 Likes
Message 6 of 7

Speed_CAD
Collaborator
Collaborator

Hi,

 

When a view belongs to a sheet Revit adds the Sheet Name parameter, otherwise, when the view does not belong to a sheet the Sheet Name parameter does not exist.

 

I implemented this simple method to check if it is possible to add a view to a sheet:

private bool CanAddViewToSheet(Autodesk.Revit.DB.View view)
{
    ParameterSet parameterSet = view.Parameters;
    Parameter sheetName = view.get_Parameter(BuiltInParameter.VIEWPORT_SHEET_NAME);

    return !parameterSet.Contains(sheetName);
}

 Use:

if (CanAddViewToSheet(view))
{
    //Create
}

 

Mauricio Jorquera
0 Likes
Message 7 of 7

alexander.tomkeyev
Participant
Participant

Seems like you've passing parameters in the wrong order here. The sheet id should be the second, the view id should be the third parameter.

bool result = Viewport.CanAddViewToSheet(view.Document, sheet.Id, view.Id);

 

0 Likes