1

I am creating a plugin that makes use of the code available from BCFier to select elements from an external server version of the file and highlight them in a Revit view, except the elements are clearly not found in Revit as all elements appear and none are highlighted. The specific pieces of code I am using are:

private void SelectElements(Viewpoint v)
    {
        var elementsToSelect = new List<ElementId>();
        var elementsToHide = new List<ElementId>();
        var elementsToShow = new List<ElementId>();

        var visibleElems = new FilteredElementCollector(OpenPlugin.doc, OpenPlugin.doc.ActiveView.Id)
        .WhereElementIsNotElementType()
        .WhereElementIsViewIndependent()
        .ToElementIds()
        .Where(e => OpenPlugin.doc.GetElement(e).CanBeHidden(OpenPlugin.doc.ActiveView)); //might affect performance, but it's necessary


        bool canSetVisibility = (v.Components.Visibility != null &&
          v.Components.Visibility.DefaultVisibility &&
          v.Components.Visibility.Exceptions.Any());
        bool canSetSelection = (v.Components.Selection != null && v.Components.Selection.Any());



        //loop elements
        foreach (var e in visibleElems)
        {
            //string guid = ExportUtils.GetExportId(OpenPlugin.doc, e).ToString();
            var guid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(OpenPlugin.doc, e));

            Trace.WriteLine(guid.ToString());

            if (canSetVisibility)
            {
                if (v.Components.Visibility.DefaultVisibility)
                {
                    if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
                        elementsToHide.Add(e);
                }
                else
                {
                    if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
                        elementsToShow.Add(e);
                }
            }

            if (canSetSelection)
            {
                if (v.Components.Selection.Any(x => x.IfcGuid == guid))
                    elementsToSelect.Add(e);
            }
        }
        try
        {
            OpenPlugin.HandlerSelect.elementsToSelect = elementsToSelect;
            OpenPlugin.HandlerSelect.elementsToHide = elementsToHide;
            OpenPlugin.HandlerSelect.elementsToShow = elementsToShow;
            OpenPlugin.selectEvent.Raise();
        } catch (System.Exception ex)
        {
            TaskDialog.Show("Exception", ex.Message);
        }
    }

Which is the section that should filter the lists, which it does do as it produces IDs that look like this: 3GB5RcUGnAzQe9amE4i4IN 3GB5RcUGnAzQe9amE4i4Ib 3GB5RcUGnAzQe9amE4i4J6 3GB5RcUGnAzQe9amE4i4JH 3GB5RcUGnAzQe9amE4i4Ji 3GB5RcUGnAzQe9amE4i4J$ 3GB5RcUGnAzQe9amE4i4GD 3GB5RcUGnAzQe9amE4i4Gy 3GB5RcUGnAzQe9amE4i4HM 3GB5RcUGnAzQe9amE4i4HX 3GB5RcUGnAzQe9amE4i4Hf 068MKId$X7hf9uMEB2S_no

The trouble with this is, comparing it to the list of IDs in the IFC file that we imported it from reveals that these IDs do not appear in the IFC file, and looking at it in Revit I found that none of the Guids in Revit weren't in the list that appeared either. Almost all the objects also matched the same main part of the IDs as well, and I'm not experienced enough to know how likely that is.

So my question is, is it something in this code that is an issue?

Tom Paganuzzi
  • 45
  • 1
  • 4

1 Answers1

0

The IFC GUID is based on the Revit UniqueId but not identical. Please read about the Element Identifiers in RVT, IFC, NW and Forge to learn how they are connected.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Reading through your articles helped me realise the main crux of my issue was that when importing an IFC file, Revit assigns new IDs to it when it makes a Revit project out of the ifc file, the issue was that the IFC file we were using to generate the issues was created before importing into Revit, so it had no real relation to the Revit file. – Tom Paganuzzi Nov 20 '20 at 11:49
  • Possibly you can link the IFC file instead of importing it. Possibly that will enable retaining the existing element ids when the file is updated? I would suggest researching that manually in the user interface first. You can also discuss best practices in the open source IFC discussion forum: https://sourceforge.net/p/ifcexporter/discussion/general – Jeremy Tammik Nov 21 '20 at 13:38