Tag All Not Tagged - in ActiveView - tag linked arch rooms in host MEP model

Tag All Not Tagged - in ActiveView - tag linked arch rooms in host MEP model

K.Calero_Arup
Contributor Contributor
490 Views
4 Replies
Message 1 of 5

Tag All Not Tagged - in ActiveView - tag linked arch rooms in host MEP model

K.Calero_Arup
Contributor
Contributor

Hi, I've seen a couple posts similar to tagging linked elements but have yet to see one specifically for tagging all linked rooms in the active view.

 

Can I please get a glimpse into the code for the Revit 2022 interface 'Tag All Not Tagged' ? In other words, when 'include elements from linked file' is checked, what method(s) are used to find ALL linked rooms in the ActiveView? Solids+ intersects? Would like to understand how this feature is finding all the linked rooms in view.

 

KCalero_Arup_0-1704161797456.png

 

@jeremytammik  I can't find any samples in the building coder samples specifically for arch rooms using Create.NewRoomTag(). The only sample 'CmdLinkedFileElements.cs' only shows for all walls

var newTag = IndependentTag.Create(...

 

0 Likes
491 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Happy New Year. So, you looked at The Building Coder samples? Good for you! Before doing so, did you check out the official Revit SDK samples? I see the following in the Rooms and AutoTagRooms SDK samples:

 

~/a/src/rvt/RevitSdkSamples/SDK/Samples/Rooms/CS/RoomsData.cs:
  207                      //create room tag
  208                      RoomTag tmpTag;
  209:                     tmpTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(new LinkElementId(tmpRoom.Id), point, null);
  210                      if (null != tmpTag)
  211                      {

~/a/src/rvt/RevitSdkSamples/SDK/Samples/Rooms/CS/ReadMe_Rooms.rtf:
   89  \par }\pard \ltrpar\ql \fi-360\li360\ri0\nowidctlpar\tx360\wrapdefault\faauto\rin0\lin360\itap0 {\rtlch\fcs1 \af1\afs20 \ltrch\fcs0 \f1\fs20\insrsid4524958 -\tab \hich\af1\dbch\af31505\loch\f1 Room objects can be gotten via ActiveDocument.Elements property}{
   90  \rtlch\fcs1 \af0\afs20 \ltrch\fcs0 \f0\fs20\insrsid4524958 .
   91: \par }\pard \ltrpar\ql \fi-360\li360\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin360\itap0 {\rtlch\fcs1 \af1\afs20 \ltrch\fcs0 \f1\fs20\insrsid4524958 -\tab \hich\af1\dbch\af31505\loch\f1 To add Tags for Room, use Document.Create.NewRoomTag method}{\rtlch\fcs1 
   92  \af0\afs20 \ltrch\fcs0 \f0\fs20\insrsid4524958 .
   93  \par }{\rtlch\fcs1 \af1\afs20 \ltrch\fcs0 \f1\fs20\insrsid4524958 -\tab \hich\af1\dbch\af31505\loch\f1 To get department and area of Room, use BuiltInParameter.ROOM_DEPARTMENT and BuiltInParameter.ROOM_AREA as parameters for Room.get_Parameter() methods}{

~/a/src/rvt/RevitSdkSamples/SDK/Samples/AutoTagRooms/CS/RoomsData.cs:
  174                      LocationPoint locationPoint = tmpRoom.Location as LocationPoint;
  175                      Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV(locationPoint.Point.X, locationPoint.Point.Y);
  176:                     RoomTag newTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(new LinkElementId(tmpRoom.Id), point, null);
  177                      newTag.RoomTagType = tagType;
  178  

~/a/src/rvt/RevitSdkSamples/SDK/Samples/AutoTagRooms/CS/ReadMe_AutoTagRooms.rtf:
   31  \pard\ltrpar\nowidctlpar\fi-360\li360\f0 -\tab PlanTopology.Rooms property can be used to get all rooms in each PlanTopology. \f1\par
   32  \f0 -\tab All the room tags can be retrieved by iterating all the elements in the active documen\f2 t\f1 .\par
   33: \f0 -\tab To tag a room, use the Document.Create.NewRoomTag method\f1 .\par
   34  \pard\ltrpar\nowidctlpar\li360\f0\par
   35  \pard\ltrpar\nowidctlpar\b Instructions:\cf1\b0  \cf0\par

~/a/src/rvt/RevitSdkSamples/SDK/Macro Samples/Rooms/Source/Rooms/RoomsData.cs:
  217                  	//create room tag
  218                  
  219:                 	m_thisApp.ActiveUIDocument.Document.Create.NewRoomTag(new LinkElementId(tmpRoom.Id), point, null);
  220                  }
  221              }

 

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

K.Calero_Arup
Contributor
Contributor

Thanks Jeremy, I had looked at the those SDK samples but none provide examples for dealing w/Linked rooms and getting the number of them visible in the host model ActiveView.

 

To clarify, creating room tags seems straightforward, the problem I'm facing is identifying the number of link rooms for the ActiveView (for each RevitLinkInstance if there are multiple instances). I am trying a function that can get link rooms in view using intersect solids (view crop region vs room solids) but would like to know from the developers if that is the right approach or if there's an alternate more efficient approach.

 

To do this manually in Revit UI: I open any ViewPlan (ie floorplan or ceiling plan) then select 'TagAllNotTagged', then check 'Include elements from linked file', then select Room Tag, then OK.  Then magically, Revit knows how many linked rooms there are in the ActiveView because it tags each one 🙊

 

I'd like to get some guidance or a snippet of the code that drives Revit (2022) UI 'Tag All Not Tagged' when 'include elements from linked file' is checked, what method(s) are used? 

 

0 Likes
Message 4 of 5

K.Calero_Arup
Contributor
Contributor

So far this is the function to get link rooms in view

public List<Room> LinkRoomsInView(Document doc, RevitLinkInstance link, View view)
{
    ElementId typeId = link.GetTypeId();
    ElementType type = doc.GetElement(typeId) as ElementType;

    if (RevitLinkType.IsLoaded(doc, typeId))
    {
        FilteredElementCollector linkedDocCollector = new FilteredElementCollector(link.GetLinkDocument());
        List<Room> rooms = linkedDocCollector.OfCategory(BuiltInCategory.OST_Rooms).ToElements().Cast<Room>().ToList();

        double minArea = rooms.Min(x => x.Area);
        double minHeight = rooms.Min(r => r.get_Parameter(BuiltInParameter.ROOM_HEIGHT).AsDouble());

        List<Solid> virtualLinkSolidInfo = SolidFromView(view);
        Solid virtualLinkSolid = virtualLinkSolidInfo[0];
        double offset = virtualLinkSolidInfo[1];

        Transform transform = link.GetTransform();
        if (!transform.AlmostEqual(Transform.Identity))
        {
            virtualLinkSolid = SolidUtils.CreateTransformed(virtualLinkSolid, transform.Inverse);
        }

        List<Solid> roomSolids = RSolids(rooms);

        List<Room> roomsInView = new List<Room>();
        List<Solid> iSolidsRvt = new List<Solid>();  // Optional list of solids to visualize in Dynamo

        for (int i = 0; i < rooms.Count; i++)
        {
            Room room = rooms[i];
            Solid roomSolid = roomSolids[i];

            try
            {
                Solid iSolid = BooleanOperationsUtils.ExecuteBooleanOperation(virtualLinkSolid, roomSolid, BooleanOperationsType.Intersect);

                // Get room height
                double roomHeight = room.get_Parameter(BuiltInParameter.ROOM_HEIGHT).AsDouble();

                // Get area of the iSolid solid
                double iSolidArea = iSolid.Volume / offset;  // Volume = area * offset

                if (iSolidArea >= minArea && roomHeight >= minHeight)
                {
                    roomsInView.Add(room);
                    iSolidsRvt.Add(iSolid);
                }
            }
            catch
            {
                // Ignore exceptions and continue to the next room
            }
        }

        return roomsInView;
    }
    else
    {
        return new List<Room>();
    }
}


0 Likes
Message 5 of 5

frankloftus
Contributor
Contributor

@K.Calero_Arup, thank you for posting your code. This has helped me to understand your approach.

 

There are some parts I don't understand, though. In particular, these two functions:

 

SolidFromView()

RSolids()

 

Can you post the code for these functions? Or briefly describe the process for creating your solids?

 

I have succeeded in creating solids from linked rooms, but the solids are always centered on the project origin, so they fail to intersect the view crop like they should. Do you know a way to translate them to the room's original position in the linked model? Using the link instance transform does not work because that is the transform for the whole building, not the location of the room within the building.

 

Thank you.

0 Likes