Hi,
I was wondering if there was any development on being able to change a callout's referencing view? For example if there were multiple callouts across a project referencing a view/sheet A-200, is there a way in the API to collect all those callouts and change their references to another view like A-201? I know this has been in discussion a few times but I can't seem to find a solution. The main issue is being able to change the reference.
This is also a big problem for our company.
When selected one callout, a combobox allowing you to change the reference appears in the Modify|Views tab. When selecting multiple callouts however the combobox disappears.
When we need to change a reference that has 10, 20 or maybe 50 callouts contained over many different views this is an issue. Simply keeping that combobox would save us lots of time.
-Thank you
Since 2015 they have static method
Autodesk.Revit.DB.ReferenceableViewUtils.ChangeReferencedView(Document, ReferenceID, DesiredViewID)
Here is a bit of code that I think can be useful in changing multiple view references.
View Oldview = (View)cboViews.SelectedValue;
FilterRule rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.VIEW_NAME), Oldview.Name, true);
ElementParameterFilter filter = new ElementParameterFilter(rule);
using (FilteredElementCollector fec = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Viewers).WherePasses(filter).WhereElementIsNotElementType())
{
using (Transaction trans = new Transaction(doc))
{
trans.Start("Change View Ref");
foreach (Element viewer in fec.ToElements())
{
if (viewer.Id.IntegerValue > Oldview.Id.IntegerValue)
{
ReferenceableViewUtils.ChangeReferencedView(doc, viewer.Id, newView.Id);
}
}
trans.Commit();
}
}
RPTHOMAS and Spage, thank you both.
I didn't know about ReferenceViewUtils, but this is exactly what I wanted.
I would mark as solution if I was the post owner.
I thought I would give a follow up to this as I have further developed it for inclusion in an add-in package, but realized the ElementId > View.Id does not work since you may be trying to change references that were created Long before the View you want to change them too.
To remedy this, I reviewed that noticed that the Viewers have about half as many parameters as a "real" view has. I have elected to look for the "Discipline" parameter as the Reference Views do not contain that parameter. There are others, but that was just the first one that didn't show up on the list. I also added a handler for checking that the View Types are the same.
private void BtnChange_Click(object sender, RoutedEventArgs e)
{
//Use a try so an exception doesn't crash revit
try
{
//Cast the Old and New views from the Combobox Selected Values
View OldView = (View)ComboBoxOldReference.SelectedValue;
View NewView = (View)ComboBoxNewReference.SelectedValue;
//Use a Filter Rule to Collect ONLY views that have the View Name of the OldView
FilterRule rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.VIEW_NAME), OldView.Name, true);
//Create a Filter from the Filter Rule
ElementParameterFilter filter = new ElementParameterFilter(rule);
//Use a Collecter with the Filter to get Viewers that are not ElementTypes
if (OldView.ViewType == NewView.ViewType)
{
using (FilteredElementCollector fec = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Viewers).WherePasses(filter).WhereElementIsNotElementType())
{
//Create a new Transaction to make make changes to the Document
using (Transaction Trans = new Transaction(doc))
{
//Start the Transaction and Name it for the Undo/rdo Menu
Trans.Start("Change View Reference");
//Iterate each Viewer returned by the Collector
foreach (Element viewer in fec.ToElements())
{
//The Viewers do not contain the same parameters as the actual views, so we check for one of them
if (viewer.GetParameters("Discipline").Count == 0)
{
ReferenceableViewUtils.ChangeReferencedView(doc, viewer.Id, NewView.Id);
}
}
//Commit the Transaction to save the changes
Trans.Commit();
}
}
//Set the Dialog result to true so the Command will keep the changes
DialogResult = true;
//Close the Form
Close();
}
else
{
TaskDialog.Show("View Type Mismatch", "Current View and New View are not of the Same View Type\n\nCurrent View Type: "+OldView.ViewType.ToString()+"\nNew View Type: "+NewView.ViewType.ToString());
}
}
//Catch and Display any Exeptions that are thrown
catch (Exception ex)
{
TaskDialog.Show("Error", ex.ToString());
//Set the Dialog result to False so the Command will not keep any changes
DialogResult = false;
//Close the Form
Close();
}
}
Any idea how to do this with View References elements of category 'OST_ReferenceViewer' and wanting to associate them to View3D instances? it seems that 'OST_Viewers' only shows the main floor plans and nothing else.