Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Referencing View For Multiple Callouts

6 REPLIES 6
Reply
Message 1 of 7
rvtquestions
961 Views, 6 Replies

Change Referencing View For Multiple Callouts

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.

6 REPLIES 6
Message 2 of 7
adelira
in reply to: rvtquestions

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

Message 3 of 7
RPTHOMAS108
in reply to: rvtquestions

Since 2015 they have static method

 

Autodesk.Revit.DB.ReferenceableViewUtils.ChangeReferencedView(Document, ReferenceID, DesiredViewID)

 

Message 4 of 7
Sean_Page
in reply to: rvtquestions

Here is a bit of code that I think can be useful in changing multiple view references.

 

  1. You will need to have a view that you are wanting to change all reference view of.
  2. You will need to have the View of the reference you want to change them too.
    1. Keep in mind that they need to be similar view types Like Section for Section or Elevation for Elevation, etc
  3. It elminates the initial or "primary" view on the premis that the original View Marker will have an Element Id lower than the actual View, and all other reference markers would have a higher Element Id.
    1. I would be more than happy if someone had a more definitive way of doing this, but I was unable to find any specific way of differentiating Reference views from the Actual marker.

 

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();
                }
            }

 

 

Message 5 of 7
adelira
in reply to: rvtquestions

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.

Message 6 of 7
Sean_Page
in reply to: Sean_Page

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();
            }
        }

 

Message 7 of 7
patrickmR&N
in reply to: Sean_Page

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community