Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Tagging Linked Elements using Revit API

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
IliaIvanov
3012 Views, 10 Replies

Tagging Linked Elements using Revit API

Hello, Is it real to tag linked element?

Tags (1)
10 REPLIES 10
Message 2 of 11
IliaIvanov
in reply to: IliaIvanov

And also how to get reference of taged linked element? 

Message 3 of 11
IliaIvanov
in reply to: IliaIvanov

Hello, Ihave done it:
RevitLinkInstance link = doc.GetElement(tag.TaggedElementId.LinkInstanceId) as RevitLinkInstance;

Reference refer =new  Reference(link.GetLinkDocument()

.GetElement(tag.TaggedElementId.LinkedElementId))

.CreateLinkReference(link);

Message 4 of 11
jeremytammik
in reply to: IliaIvanov

Dear Ilia,

 

Thank you for your query and thank you ever so much for your solution!

 

Congratulations on that!

 

Well done.

 

What a shame that my answer to you now is completely superfluous.

 

Here is what I originally wrote and you can now (almost) totally ignore:

 

<begin original answer>

 

You thread was automatically escalated to an ADN case, since you logged it with your ADN membership email address.

 

You also escalated it twice manually yourself, so we now have three separate identical cases for this thread:

 

  • 15175390 [Tagging Linked Elements using Revit API]
  • 15175537 [Tagging Linked Elements using Revit API]
  • 15177861 [Tagging Linked Elements using Revit API]

 

I am closing the latter two as duplicates of the first.

 

Thank you for refraining from duplicating cases in future.

 

Furthermore, this topic of yours has been raised several times here in the past, e.g.:

 

 

Please always search for existing threads before raising a new issue.

 

The first one of those is the most relevant in your case.

 

It led to a wish list item in the development database:

 

  • REVIT-90539 [WISH: API : highlight linked elements -- 10027136, 15175390]

 

Unfortunately, that wish has not yet been addressed.

 

I added a note of your request to it to underline its importance and raise its priority.

 

You are welcome to request an update on the status of this issue or to provide us with additional information at any time quoting this wish list item number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team, and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

In addition to the internal wish list item, I would strongly suggest that you add an entry for this in the Revit Idea Station, if there is none already present there yet:

 

 

Tag it as an API wish:

 

 

Ensure it gets as many votes as possible to underline its importance to you and the rest of the developer community.

 

The Revit Idea Station is currently one of the main driving input sources for Revit API enhancements.

 

In fact, I see that these two wishes have already been logged there for this:

 

 

So, please vote for them.

 

Thank you!

 

</end original answer>

 

Ok, now I just have to update those wish list items all over the place and point out your solution there...

 

Thanks again.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 11
jeremytammik
in reply to: IliaIvanov

Could you provide slightly larger snippets of source code showing the context of both creating the tag and retrieving the link from it afterwards? Thank you!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 11
IliaIvanov
in reply to: jeremytammik

Hello, sure

//point near my wall
XYZ xyz = new XYZ(-20,20,0);

//At first need to find our links
FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(RevitLinkInstance)); foreach (Element elem in collector) { //Get linkInstance RevitLinkInstance instance = elem as RevitLinkInstance; //Get linkDocument Document linkDoc = instance.GetLinkDocument(); //Get linkType RevitLinkType type = doc.GetElement(instance.GetTypeId()) as RevitLinkType; //Check if link is loaded if (RevitLinkType.IsLoaded(doc, type.Id)) { //Find walls for tagging FilteredElementCollector newCollector = new FilteredElementCollector(linkDoc); IList<Element> newElems = newCollector .OfCategory(BuiltInCategory.OST_Walls) .ToElements(); //Create reference. For(int i=0;i< newElems.count;i++)
{ Reference newRef = new Reference(newElems[i]) .CreateLinkReference(instance); //Create transaction using (Transaction tx = new Transaction(doc)) { tx.Start("Create tags"); IndependentTag newTag= IndependentTag.Create(doc,doc.ActiveView.Id,newRef,true,TagMode.TM_ADDBY_MATERIAL,TagOrientation.Horizontal,xyz);
//To find information about Link from tag we should use:

ElementId linkInstid = newTag.TaggedElementId
.LinkInstanceId; //to find id of LinkInstance

ElememtId linkedElementId = newTag.TaggedElementId
.LinkInstanceId; //to find id of LinkedElement tx.Commit(); }
}
} }
Tags (1)
Message 7 of 11
jeremytammik
in reply to: IliaIvanov

Dear Ilia,

 

Thank you very much for your fast answer and complete sample code.

 

I saved this for posterity in The Building Coder blog:

 

https://thebuildingcoder.typepad.com/blog/2019/05/tagging-a-linked-element.html#3

 

I also added the sample method to The Building Coder samples as TagAllLinkedWalls for posterity.

 

Here is the slightly cleaned-up code:

 

https://github.com/jeremytammik/the_building_coder_samples/compare/2020.0.145.4...2020.0.145.5

 

  /// <summary>
  /// Tag all walls in all linked documents
  /// </summary>
  void TagAllLinkedWalls( Document doc )
  {
    // Point near my wall
    XYZ xyz = new XYZ( -20, 20, 0 );

    // At first need to find our links
    FilteredElementCollector collector
      = new FilteredElementCollector( doc )
        .OfClass( typeof( RevitLinkInstance ) );

    foreach( Element elem in collector )
    {
      // Get linkInstance
      RevitLinkInstance instance = elem 
        as RevitLinkInstance;

      // Get linkDocument
      Document linkDoc = instance.GetLinkDocument();

      // Get linkType
      RevitLinkType type = doc.GetElement( 
        instance.GetTypeId() ) as RevitLinkType;

      // Check if link is loaded
      if( RevitLinkType.IsLoaded( doc, type.Id ) )
      {
        // Find walls for tagging
        FilteredElementCollector walls
          = new FilteredElementCollector( linkDoc )
            .OfCategory( BuiltInCategory.OST_Walls )
            .OfClass( typeof( Wall ) );

        // Create reference
        foreach( Wall wall in walls )
        {
          Reference newRef = new Reference( wall )
            .CreateLinkReference( instance );

          // Create transaction
          using( Transaction tx = new Transaction( doc ) )
          {
            tx.Start( "Create tags" );

            IndependentTag newTag = IndependentTag.Create( 
              doc, doc.ActiveView.Id, newRef, true, 
              TagMode.TM_ADDBY_MATERIAL, 
              TagOrientation.Horizontal, xyz );

            // Use TaggedElementId.LinkInstanceId and 
            // TaggedElementId.LinkInstanceId to retrieve 
            // the id of the tagged link and element:

            LinkElementId linkId = newTag.TaggedElementId;
            ElementId linkInsancetId = linkId.LinkInstanceId;
            ElementId linkedElementId = linkId.LinkedElementId;

            tx.Commit();
          }
        }
      }
    }
  }

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 8 of 11
IliaIvanov
in reply to: jeremytammik

You are welcome!
BTW As I had one wall in project to tag it I needed only one xyz point,  If somebody are going to use code for not one wall, they should make the variable  different 

Message 9 of 11
jeremytammik
in reply to: IliaIvanov

Yes, I noticed.

 

Left as a good exercise for the interested reader...  🙂

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 10 of 11
bimsmart.hql
in reply to: IliaIvanov

hi..

Do you know why when I move the file link to another location? Then I add a new tag to the object, will the new tag not follow the object?

Message 11 of 11
IliaIvanov
in reply to: bimsmart.hql

Hello,
You need to get XYZ point of tagged element taking into account the transformation of LinkedInstance 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community