Thursday, June 05, 2014

View Schedule with Detail Numbers Macro for Revit

A question was posted on http://revitforum.org about showing a view's detail number in a view list schedule. Revit has a parameter for the Detail Number (see first image) but it isn't accessible to add in a view list schedule.

Original post: http://www.revitforum.org/architecture-general-revit-questions/20119-detail-number-view-list-schedule.html




















Solution

Step 1
Create a View List schedule (or edit an existing one) and add a new text Parameter named "Detail_Number" (notice the _ in the name)






















Step 2
Create a new macro with the following routine and run it

public void DetailNumber()
{
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
  
    string strDetailNumber = "Detail_Number";         
  
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    ICollection<Element> collection = collector.OfClass(typeof(View)).ToElements();
  
    using (Transaction t = new Transaction(doc, "Detail Number"))
    {
        t.Start();
      
        foreach(Element e in collection)
        {
            View v = e as View;
          
            try
            {
                Parameter bpDetailNumber = v.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER);
                v.get_Parameter(strDetailNumber).Set(bpDetailNumber.AsString());
            }
            catch
            {
              
            }
          
        }
      
        t.Commit();
    }
}


Results
All the views that are on sheets now have the Detail Number copied into the Detail_Number parameter.



















Run the macro whenever you want to update the values in the new parameter to reflect the current state of the project (aka is doesn't auto update and needs to be run manually).

11 comments:

  1. Could this also work to link door schedules to door details that have been placed on sheets?

    Adding a parameter to the door families that will allow a detail drawings to fill in a head, jamb, sill detail section of the door schedule with the drawings (detail) number and sheet when that detail view is placed on a sheet?

    ReplyDelete
  2. Hi. I am interested in your Macro that does this automatically

    ReplyDelete
  3. Thank for sharing :D

    ReplyDelete
  4. Thank you for making this, I am new to macros, so this may be a stupid question:
    I am getting an error
    'DetailNumber.ThisDocument' does not contain a definition for 'ActiveUIDocument' and no extens:ion method 'ActiveUIDocument' accepting a first argument of type 'DetailNumber.ThisDocument' could be found (are you missing a using directive or an assembly referen

    ReplyDelete
  5. Taylor, yes definitely. You can get the detail number as shown and fill it into a parameter in the door schedule. You would need some type of verification to ensure you are putting the correct detail in the matching door.

    ReplyDelete
  6. Hi Troy, thanks for sharing this macro! Would you be able to edit the post for a step-by-step process on making a macro? I am not sure what to add/delete/amend in the macro/C# interface.

    ReplyDelete
  7. Getting these two errors:

    Argument 1: cannot convert from 'string' to "Autodesk.Revit.DB.BuiltInParameter' (CS1503)
    The best overloaded method match for 'Autodesk.Revit.DB.Element.get_Parameter' has some invalid argument (CS1502)

    Any idea why?

    ReplyDelete
    Replies
    1. The original macro was written in Revit 2014. In Revit 2015 and up the parameter method of get_Parameter has been changed to LookupParameter.

      Change the line:
      v.get_Parameter(strDetailNumber).Set(bpDetailNumber.AsString());

      to this: v.LookupParameter(strDetailNumber).Set(bpDetailNumber.AsString());

      Delete
  8. Getting these two errors:

    -Error CS1061: 'MyDetailNumber.ThisDocument' does not contain a definition for 'ActiveUIDocument' and no extension method 'ActiveUIDocument' accepting a first argument of type 'MyDetailNumber.ThisDocument' could be found (are you missing a using directive or an assembly reference?)

    -Error CS1502: The best overloaded method match for 'Autodesk.Revit.DB.Element.get_Parameter(Autodesk.Revit.DB.BuiltInParameter)' has some invalid arguments

    -Error CS1503: Argument 1: cannot convert from 'string' to 'Autodesk.Revit.DB.BuiltInParameter'
    Build failed.

    ReplyDelete
    Replies
    1. The original macro was written in Revit 2014. In Revit 2015 and up the parameter method of get_Parameter has been changed to LookupParameter.

      Change the line:
      v.get_Parameter(strDetailNumber).Set(bpDetailNumber.AsString());

      to this: v.LookupParameter(strDetailNumber).Set(bpDetailNumber.AsString());

      Delete
    2. Change the line:
      UIDocument uidoc = this.ActiveUIDocument;
      Document doc = uidoc.Document;
      to this
      Document doc = this.ActiveView.Document;

      Delete