Extending the Renumber command for Viewports & Detail Number

Here is a response to the comment from Jeff at https://boostyourbim.wordpress.com/2013/01/17/quick-way-to-renumber-doors-grids-and-levels/ on how to extend that tool to work with the Viewport > Detail Number parameter.

2012 2013
private Parameter getParameterForReference(Document doc, Reference r)
{
    Element e = doc.GetElement(r);
    Parameter p = null;
    if (e is Grid)
        p = e.get_Parameter("Name");
    else if (e is Autodesk.Revit.DB.Architecture.Room)
        p = e.get_Parameter("Number");
    else if (e is FamilyInstance)
        p = e.get_Parameter("Mark");
    else
    {
        p = e.get_Parameter("Detail Number");
        if (p == null)
        {
            TaskDialog.Show("Error", "Unsupported element");
            return null;
        }
    }
    return p;
}
private Parameter getParameterForReference(Document doc, Reference r)
{
    Element e = doc.GetElement(r);
    Parameter p = null;
    if (e is Grid)
        p = e.get_Parameter("Name");
    else if (e is Room)
        p = e.get_Parameter("Number");
    else if (e is FamilyInstance)
        p = e.get_Parameter("Mark");
    else if (e is Viewport) // Viewport class is new to Revit 2013 API
        p = e.get_Parameter("Detail Number");
    else
    {
        TaskDialog.Show("Error","Unsupported element");
        return null;
    }
    return p;
}    

The 2012 code can be used in 2013, but I like the 2013 version a bit better for being more explicit about which classes are being checked.

Advertisements

7 thoughts on “Extending the Renumber command for Viewports & Detail Number

  1. Thanks Harry for showing this!!! No wonder why I have no luck when I was spending an hour yesterday to try to find the Viewport class in Revit 2012 which indeed was not available yet. Good to know that this Viewport class is now available in R2013!

  2. Thanks Harry re-arranging viewport section/detail number is realy helpfull… it will be nice if re-names the view name in the view browser as well…

  3. Thanks Harry. Works like a charm. I’m wondering if there is a way to renumber viewports in a different way so that the first one doesn’t have to be number 1. That way you can pick any viewport first, and it makes that one then continues along until all have been selected in the order you want. Thanks.

    • Hi Mike,

      Glad you like it. This code can be modified to achieve whatever numbering algorithm you prefer

      int ctr = 1;
      int startValue = 0;
      foreach (Reference r in refList)
      {
      Parameter p = getParameterForReference(doc, r);

      // get the value of the first element to use as the start value for the renumbering in the next loop
      if (ctr == 1)
      startValue = Convert.ToInt16(p.AsString());

      setParameterToValue(p, ctr + 12345); // hope this # is unused (could use Failure API to make this more robust
      ctr++;
      }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s