Change the sheet issue date on sheets filtered by project parameter

Change the sheet issue date on sheets filtered by project parameter

Joost____
Participant Participant
1,782 Views
8 Replies
Message 1 of 9

Change the sheet issue date on sheets filtered by project parameter

Joost____
Participant
Participant

Hello, 

 

I am new and still learning the Revit API & C#. I want to change the sheet issue date to the current date. I know how to do this for all the sheets, but now I want to do it for only a couple of sheets. For example only for the sheets that are under the "test2" how can i do this with C#? 

Thank you! Example.PNG

0 Likes
Accepted solutions (1)
1,783 Views
8 Replies
Replies (8)
Message 2 of 9

jeremy_tammik
Alumni
Alumni

Welcome to the Revit API! For starters, I would suggest snooping with RevitLookup. Explore your sheets and their relation ships with other elements, their properties and parameters. Maybe you will find out how to determine the 'test2' characteristic, and maybe you can use that to implement a filtered element collector that will extract exactly the desired sheets. Good luck and have fun!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 9

Joost____
Participant
Participant
Hi Jeremy. Thank you for the quick reply. I used RevitLookup but I could not find the test2 characteristics anywhere.
0 Likes
Message 4 of 9

RPTHOMAS108
Mentor
Mentor

You will have to look at the browser organisation to understand what parameter 'test2' is a value of. This will be one of the parameters associated with the sheets.

 

Via the API you have limited access to browser organisation

BrowserOrganization.GetCurrentBrowserOrganizationForSheets

The property BrowserOrganization.SortingParameterId may be of interest but in reality the project browser has many levels of sorting/grouping so it doesn't seem current API object fully encompasses that.

 

There is also BrowserOrganization.GetFolderItems but you have to supply the View.Id of a view within such a folder. Then each such item has properties ElementId  (the folder parameter id) and Name (the folder name).

 

If you are working with a known browser organisation with the same company template then you can establish the above by investigating in the UI.

 

Regardless 'test2' will likely be a value of a parameter on a sheet.

 

This is another intriguing example of StorageType.None i.e. BrowserOrganisation object contains parameters named Filter and Folders (not accessible to API). 

 

 

Message 5 of 9

RPTHOMAS108
Mentor
Mentor

Thinking further about this you can filter a set of sheets via LINQ similar to below:

 

Public Function Obj_210920a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result

        Dim uidoc = commandData.Application.ActiveUIDocument
        Dim doc = uidoc.Document
        Dim app = uidoc.Application.Application

        Dim bOrg = BrowserOrganization.GetCurrentBrowserOrganizationForSheets(doc)

        Dim FEC As New FilteredElementCollector(doc)
        Dim ECF As New ElementClassFilter(GetType(ViewSheet))

        Dim Els As List(Of ElementId) = FEC.WherePasses(ECF).ToElementIds _
                 .Where(Function(k) bOrg.GetFolderItems(k)(1).Name = "Type 1") _
                 .ToList

        'For above (k)(0) is first level i.e. '00' and (k)(1) is second i.e. 'Type 1'

        For i = 0 To Els.Count - 1
            Dim El As ViewSheet = doc.GetElement(Els(i))
            Debug.WriteLine(String.Format("{0} - {1}", El.SheetNumber, El.Name))
        Next

        Return Result.Succeeded

End Function

 

210920.png

 

Result:

00002 - Unnamed
00003 - Unnamed

Message 6 of 9

Joost____
Participant
Participant
Thank you so much for the comprehensive answer, it really helped. I am only having some trouble converting the code into C# especially this line:

"Dim Els As List(Of ElementId) = FEC.WherePasses(ECF).ToElementIds _
.Where(Function(k) bOrg.GetFolderItems(k)(1).Name = "Type 1") _
.ToList"

Do you know how to rewrite this in C#?

0 Likes
Message 7 of 9

jeremy_tammik
Alumni
Alumni

Here is a solution that does away with the FEC and ECF variables:

   

 

  string t = "Type 1";

  BrowserOrganization bOrg = BrowserOrganization
    .GetCurrentBrowserOrganizationForSheets( doc );

  IEnumerable<ElementId> ids
    = new FilteredElementCollector( doc )
      .OfClass( typeof( ViewSheet ) )
      .Where( s => bOrg.GetFolderItems( s.Id ).First().Name.Equals( t ) )
      .Select<Element, ElementId>( e => e.Id );

 

  

It also eliminates the unnecessary and slightly performance- and memory-consuming calls to the ToElements and ToList  methods. Makes no difference in this case, I guess, except less strain on human reader's eyes 🙂

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 8 of 9

jeremy_tammik
Alumni
Alumni
Accepted solution

On second thoughts, cleaned it up furhter and added it to The Building Coder samples like this:

 

IEnumerable<ElementId> FilterForSheetsByBrowserOrganisation( 
  Document doc, 
  string folder_name )
{
  BrowserOrganization bOrg = BrowserOrganization
    .GetCurrentBrowserOrganizationForSheets( doc );

  IEnumerable<ElementId> ids
    = new FilteredElementCollector( doc )
      .OfClass( typeof( ViewSheet ) )
      .Where( s => bOrg.GetFolderItems( s.Id ).First().Name.Equals( 
        folder_name ) )
      .Select<Element, ElementId>( e => e.Id );

  return ids;
}

 

Can you confirm that it works?

 

Thank you!

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 9 of 9

Joost____
Participant
Participant

I used your code and it worked! Thank you very much. With this code I can update the date of a group of sheets. The next step for me to figure out is how to create a drop-down menu with all the sheet group names. This way the user can easily select which set of sheets need to be updated. 

 

using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Transaction Name");

                DateTime thisDay = DateTime.Today;
                string today = thisDay.ToString("d");

                string t = "test 1";

                BrowserOrganization bOrg = BrowserOrganization
                  .GetCurrentBrowserOrganizationForSheets(doc);

                IEnumerable<ElementId> ids
                  = new FilteredElementCollector(doc)
                    .OfClass(typeof(ViewSheet))
                    .Where(s => bOrg.GetFolderItems(s.Id).First().Name.Equals(t))
                    .Select<Element, ElementId>(e => e.Id);

                foreach (var idNumber in ids)
                {
                    ViewSheet vs = doc.GetElement(idNumber) as ViewSheet;
                    vs.LookupParameter("Sheet Issue Date").Set(today);
                }


                tx.Commit();
            }

 

Thanks @jeremy_tammik@RPTHOMAS108 for your time and effort.