Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to use the Revit API to tag spaces in a linked model.
I see that the CreateNewRoomTagmethod is easier because you can use the LinkElementId class.
However, this is not allowed with the CreateNewSpaceTag method:
public SpaceTag NewSpaceTag( Space space, UV point, View view )
The first argument is Space, and I don't see any way of getting the space from the linked model this way.
I have tried something like:
doc.GetElement(myLinkElementId.LinkedElementId) as Space (I have also tried myLinkElementId.HostElementId)
But this is not working.
Here is my attempt:
public void RDSTag()
{
Document doc = this.ActiveUIDocument.Document;
FilteredElementCollector linkInstanceCollector = new FilteredElementCollector(doc).OfClass(typeof( RevitLinkInstance));
RevitLinkInstance myLink = null;
//get link instance with desired name
foreach(RevitLinkInstance r in linkInstanceCollector)
{
if(r.Name.Contains("HRL")) myLink = r;
}
//get link's document
Document linkDoc = myLink.GetLinkDocument();
// Get linkType
RevitLinkType linkType = doc.GetElement(myLink.GetTypeId() ) as RevitLinkType;
// Check if link is loadedmk
if( RevitLinkType.IsLoaded( doc, linkType.Id ) )
{
// Find spaces for tagging
ICollection<ElementId> spaceCollector = new FilteredElementCollector(linkDoc).OfClass(typeof(SpatialElement)).WhereElementIsNotElementType().ToElementIds();
// string spaceIds = "";
using(Transaction t = new Transaction(doc,"tag Spaces"))
{
t.Start();
string message = "";
foreach(ElementId eid in spaceCollector)
{
LinkElementId linkedSpaceReferenceId = new LinkElementId(myLink.Id, eid);
Space space = doc.GetElement(linkedSpaceReferenceId.LinkedElementId) as Space;
doc.Create.NewSpaceTag(space, new UV(0, 0), doc.ActiveView);
}
t.Commit();
}
Any help is welcome, thanks
Solved! Go to Solution.