- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Following along with this great sample found at revitapidocs (pasted below), I've changed out the "AsDependent" bits to "WithDetailing", the view Duplicates but does so without detailing. Strangely, line 7 in the code below returns -1 even though a new view is created and appears in the Revit UI. This leaves dependentView = null, so line 9 fails the check.
I also noticed the same behavior in pyRevit's Duplicate Selected Views tool and reported the bug on their github page.
I've checked this in Revit 2022 & 2023.
Here is the sample code. Again, I have changed "AsDependent" to "WithDetailing", otherwise my code is the same as below. The calling function sets up a Transaction. The Transaction succeeds and appears in the UI undo history:
public View CreateDependentCopy(View view)
{
View dependentView = null;
ElementId newViewId = ElementId.InvalidElementId;
if (view.CanViewBeDuplicated(ViewDuplicateOption.AsDependent))
{
newViewId = view.Duplicate(ViewDuplicateOption.AsDependent);
dependentView = view.Document.GetElement(newViewId) as View;
if (null != dependentView)
{
if (dependentView.GetPrimaryViewId() == view.Id)
{
TaskDialog.Show("Dependent View", "Dependent view created successfully!");
}
}
}
return dependentView;
}
Solved! Go to Solution.