nested revit linkinstance get parent or children

nested revit linkinstance get parent or children

1368026189
Enthusiast Enthusiast
2,270 Views
14 Replies
Message 1 of 15

nested revit linkinstance get parent or children

1368026189
Enthusiast
Enthusiast

Hello,can somebody help? thanks !

unable to get the children ids of revitlinkinstance while linked and copied in a nested revitlinkinstance.

can only get  RevitLinkType tree. but unbale to get the instance child info.

 

 

the main goal is not only to know the list-hierarchy-of-linked-and-sub-linked-revit...

 

but also the ids of children linkinstance ids in current document  in each linked Revit files.

it gives back the different ids whlie in linkeddocument.

 

https://forums.autodesk.com/t5/revit-api-forum/cannot-find-attachmenttype-correctly-in-link-tree/td-...

 

 @jeremytammik       answered only the revitlinktype tree.this time we focus on the linkinstace.

 

 

 

attached test file link: 

 

https://drive.google.com/file/d/1UiQF11z66-HC51g8wp8-qkqQ4gg6r_iF/view?usp=sharing

  1.rvt is the main rvt project.

 

 

 

1368026189_3-1617257489448.png

 

1368026189_2-1617257470482.png

 

 

 

0 Likes
2,271 Views
14 Replies
Replies (14)
Message 2 of 15

jeremy_tammik
Alumni
Alumni

You need to open each of the linked documents to retrieve nested links.

  

Please do not send me private messages on non-confidential issues! I always prefer to avoid discussing non-confidential issues in private. If we do, nobody else can help us, and we help nobody else. What a waste of time and effort! I think that everything worth doing may be of interest to everybody.

 

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

RPTHOMAS108
Mentor
Mentor

The complication with nested RevitLinkInstances is if they are nested as 'Attached' or 'Overlay'

 

If 'Attached' then an instance of that link is brought through to the main document

If 'Overlay' then an instance is not brought through (since it is not shown)

Loaded / Unloaded status makes no difference to existance of RevitLinkInstance

 

You can do a simple study to test:

I have:

LinkA1 nested and attached in LinkA

LinkAB which contains LinkA & Link B (attached in LinkAB)

LinkCD which contains LinkC & LinkD (overlaid in LinkCD)

 

Both LinkAB and LinkCD are overlaid in main document. This yields the following result where above the red line are the main links (nesting other links and not nested themselves) and below the red line are items of the attached nested links coming through to main document level collector.

 

210401.png

It can be observed:

  • LinkC and LinkD do not come through below the red line because they are overlaid in their host link (LinkCD). 
  • The function RevitLinkInstance.GetLinkDocument works for top level instances only (or those brought through via attaching to become top level e.g. LinkA1).
  • LinkA1 or WithAB_Linked.rvt : LinkA.rvt : LinkA1.rvt (as noted) comes all the way through since it is attached in A and A is in turn attached in AB.
Message 4 of 15

1368026189
Enthusiast
Enthusiast

hello RPTHOMAS108

thanks for your reply!

our concern is that we have one LinkA1 nested and attached in LinkA,and then we copied it many times in LinkA,

 

then we nested and attached  LinkA in LinkAB ,then copied LinkA in LinkAB many times,and even we will have LinkA1 directly nested and attached in LinkAB 

 

like the attachment project shows, then we lost ourself in current document, witch one  LinkA1 belongs to.no tree info.

 

we can filtered linkeddocument,but will not get the RevitLinkInstances id in the current main document, we have to form the tree in current document!

 
0 Likes
Message 5 of 15

1368026189
Enthusiast
Enthusiast

nested_link.gif

the picture above shows the issue,

as for the leaf node linkinstance  4.rvt ,we do not know who holds it.

0 Likes
Message 6 of 15

RPTHOMAS108
Mentor
Mentor

Probably the easiest way is to look at the name of the instance and break it down by ':' then you can form a relationship by that. To get the full picture you probably have to go through an iterative process from all instances you have  in main document (grouping each into a higher level until you reach root). They are nested but in reality the attached are all there in their own instance regardless of nesting.

 

You also get the potential for circular references so checking that also needs to be part of your ultimate process. The links that cause these are ordinarily unloaded by Revit.

0 Likes
Message 7 of 15

1368026189
Enthusiast
Enthusiast

for  instances,only can acess  linktype information, and linktype did have parent and children type info,but not for instance...

0 Likes
Message 8 of 15

jeremy_tammik
Alumni
Alumni

Just like all other elements, I would assume that you can use the GetTypeId method to access the link instance's link type:

 

https://www.revitapidocs.com/2021.1/cc66ca8e-302e-f072-edca-d847bcf14c86.htm

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 9 of 15

1368026189
Enthusiast
Enthusiast

 

don't know how to describe  more clearly, 

 

What I want to do is to find the nested relationship of link instances return by filter revitlinkinstance while copied and  nested instance exist!

 

we have one LinkA1 nested and attached in LinkA,and then we copied it many times in LinkA,

then we nested and attached  LinkA in LinkAB ,then copied LinkA in LinkAB many times,and even we will have LinkA1 directly nested and attached in LinkAB 

 

and the test model is on the top floor.

 

while filtering revitlinkinstance , whole revitlinkinstan returns ,both in main document and nested linkinstance in linkdocument. we can't know which child belongs to which parent.

 

unable to get the children ids of revitlinkinstance while linked and copied in a nested revitlinkinstance.

can only get  RevitLinkType tree. but unbale to get the instance child info.

 

the main goal is not only to know the list-hierarchy-of-linked-and-sub-linked-revit...

 

but also the ids of children linkinstance ids in current document  in each linked Revit files.

it gives back the different ids whlie in linkeddocument,so filter in linkinstace document does not work.

 

pls read the full message before  giving your an answer.

if I am not clear enough,I will try my best to improve and update.

0 Likes
Message 10 of 15

jeremy_tammik
Alumni
Alumni

In order to retrieve the children in linked files, you may need to recursively open each linked file and perform the same analysis there as in the top-level main project.

 

In order to determine the hierarchy of link types and link instances, you may need to retrieve all instances and check their type using GetTypeId.

 

If you need the relationship from type to instance (instead of instance to type), you may need to invert the relationship:

 

http://thebuildingcoder.typepad.com/blog/2008/10/relationship-in.html

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 11 of 15

tyler_gorton
Observer
Observer

I understand what you're saying, and I'm currently finding a similar problem. While the linktype hierarchy is available, there is no distinction, when fetching a nested link instance, as to which linkinstance parent it belongs. I'll try to explain as well, and hope this is what you're trying to achieve too.

 

Link A is linked into the active model. Link A has 2 or more instance placed in the active model. 
Link B is linked "attached" into link A one or more times. 

When fetching an instance of link B in the active model, the linktype describes that it is nested into link A. 

Which instance of link A is the current link B instance coming from? Who knows?! 

 

It's true this is a whacky scenario, but possible nonetheless and definitely encountered by the OP.

My latest concern is that the so-called "TotalTransform" of a nested link instance does not appear to include its transformation in the parent INSTANCE! But this is yet to be determined by further testing. In my case, I will be able to take the long route back through the link type hierarchy, and making the assumption that there are no duplicate link instances of the parent links, traverse back to some instance of the parent link type to get the additional transform.

Message 12 of 15

jeremy_tammik
Alumni
Alumni

Thank you for raising this again and sorry that we have no conclusive answer yet. I pointed out this thread to the development team and asked them for advice.

  

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

jeremy_tammik
Alumni
Alumni

Dear all,

 

Thank you very much for bringing this up and your collective perseverance following up on it. Awfully sorry it took me so long to pass it on in an effective manner. The development team has now understood and created a ticket to address this issue:

 

  • REVIT-189187 [Expose RvtLinkInstance getParentId() and getChildIds()]

 

Description: We have the parent/child relationship exposed for the link types, but not for the link instances. If there are multiple placed instances of a link that contains a nested link, there's no actual way for an API user to tell which nested instance goes with which top-level instance. We have very simple functions that do this - RvtLinkInstance::getParentId() and RvtLinkInstance::getChildIds(). We just need to expose them and make a simple test.

 

Best regards,

 

Jeremy

 

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

1368026189
Enthusiast
Enthusiast

thanks @tyler_gorton  

thanks  @jeremy_tammik  

 

Message 15 of 15

Ramoon_Bandeira
Contributor
Contributor

Any update on this?

0 Likes