Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, Is it real to tag linked element?
Solved! Go to Solution.
Hello, Is it real to tag linked element?
Solved! Go to Solution.
And also how to get reference of taged linked element?
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);
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:
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:
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:
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
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!
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(); }
}
} }
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
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
Yes, I noticed.
Left as a good exercise for the interested reader... 🙂
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?
Hello,
You need to get XYZ point of tagged element taking into account the transformation of LinkedInstance