[英]How to get a list of nested links for a Revit model using Forge APIs
I can acquire the full list of nested links in a Revit model using Revit APIs by this query:我可以通过以下查询使用 Revit API 获取 Revit model 中嵌套链接的完整列表:
FilteredElementCollector collector = new FilteredElementCollector(document);
return collector.OfCategory(BuiltInCategory.OST_RvtLinks)
.OfClass(typeof(RevitLinkInstance))
.Cast<RevitLinkInstance>()
.Select(linkInstance => document.GetElement(linkInstance.GetTypeId()) as RevitLinkType)
.Where(revitLinkType => revitLinkType.IsNestedLink)
.Select(type => type.Name)
.Distinct()
.ToList();
I am trying to replicate the same function using Forge APIs.我正在尝试使用 Forge API 复制相同的 function。 While I can't get the nested links directly, I am hoping to get it in two steps.
虽然我无法直接获取嵌套链接,但我希望分两步获取。
First: acquire the list of linked docs, Second: query the linked docs on every linked document acquired in step one.第一:获取链接文档列表,第二:在第一步获取的每个链接文档上查询链接文档。
I am using this API to get the list of linked docs for step one:我正在使用这个 API 来获取第一步的链接文档列表:
'https://developer.api.autodesk.com/data/v1/projects/[project_id]/versions/[version_id]/relationships/refs' 'https://developer.api.autodesk.com/data/v1/projects/[project_id]/versions/[version_id]/relationships/refs'
That returns a list that includes: linked docs, the document itself, and any document that has the document linked in. So for example:这将返回一个列表,其中包括:链接的文档、文档本身以及链接了该文档的任何文档。例如:
If A links B, and B links C, When I call the API on B, I get A, B and C. Now, it's easy to eliminate B from the response, but it's a bit confusing to figure out between A and C which one is a linked document.如果 A 链接 B,B 链接 C,当我在 B 上调用 API 时,我得到 A、B 和 C。现在,很容易从响应中消除 B,但在 A 和 C 之间弄清楚哪个有点令人困惑一个是链接文档。
I checked all the attributes and couldn't find anything, is there something I am missing?我检查了所有属性,但找不到任何东西,是不是我遗漏了什么? Also, is this the best way to acquire the list of nested linked documents?
另外,这是获取嵌套链接文档列表的最佳方法吗?
To identify which file is the host or link, we can take a look at the direction
attribute of the responses of GET projects/:project_id/versions/:version_id/relationships/refs要确定哪个文件是主机或链接,我们可以查看GET projects/:project_id/versions/:version_id/relationships/refs响应的
direction
属性
Here are two example responses representing the host and link correspondingly.下面是两个示例响应,分别表示主机和链接。
//Host Model
"data": [
{
"type": "versions",
"id": "urn:adsk.wipprod:fs.file:vf.n4QEQGINSWid8VvcBVds1w?version=1",
"meta": {
"refType": "xrefs",
"fromId": "urn:adsk.wipprod:fs.file:vf.n4QEQGINSWid8VvcBVds1w?version=1",
"fromType": "versions",
"toId": "urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1",
"toType": "versions",
"direction": "to",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"schema": {
"href": "https://developer.api.autodesk.com/schema/v1/versions/xrefs:autodesk.core:Xref-1.1"
},
"data": {
"nestedType": "overlay"
}
}
}
}
],
// Link model
"data": [
{
"type": "versions",
"id": "urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1",
"meta": {
"refType": "xrefs",
"fromId": "urn:adsk.wipprod:fs.file:vf.n4QEQGINSWid8VvcBVds1w?version=1",
"fromType": "versions",
"toId": "urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1",
"toType": "versions",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"schema": {
"href": "https://developer.api.autodesk.com/schema/v1/versions/xrefs:autodesk.core:Xref-1.1"
},
"data": {
"nestedType": "overlay"
}
}
}
}
],
The direction
attribute has two possible values, one is to
and another is from
. direction
属性有两个可能的值,一个是to
,另一个是from
。
In the above example, host urn:adsk.wipprod:fs.file:vf.n4QEQGINSWid8VvcBVds1w?version=1
is linked to urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1
.在上面的示例中,主机
urn:adsk.wipprod:fs.file:vf.n4QEQGINSWid8VvcBVds1w?version=1
链接到urn:adsk.wipprod:fs.file:vf.y6GJ2scBSVSyIRM_wtEsDA?version=1
。 Consider it like an arrow with the head pointing to
-wards the link model.把它想象成一个箭头,箭头
to
链接 model。
What you see from link model perspective is simply the reverse, the arrow is coming from the host urn:adsk.wipprod:fs.file:vf.n4QEQGINSWid8VvcBVds1w?version=1
.您从链接 model 的角度看到的完全相反,箭头来自主机
urn:adsk.wipprod:fs.file:vf.n4QEQGINSWid8VvcBVds1w?version=1
。
In both example responses, the fromId
and toId
don't change, only the direction
of the arrow
depending from which perspective you're looking at.在这两个示例响应中,
fromId
和toId
都没有改变,只有arrow
的direction
取决于您从哪个角度看。
Thanks for the response Eason.感谢伊森的回应。 Ok so if I use the 'GET' equivalent it works as you described.
好的,如果我使用等效的“GET”,它会按照您的描述工作。 However, I can only get it to work on smaller test models, the API simply returns an empty array for data, even though the project does have several linked document:
然而,我只能让它在较小的测试模型上工作,API 只是返回一个空的数据数组,即使该项目确实有几个链接文档:
{
"jsonapi": {
"version": "1.0"
},
"links": {
"self": {
"href": "https://developer.api.autodesk.com/data/v1/projects/b.19e2199f-4132-4c47-9972-37d4708ea59f/versions/urn:adsk.wipprod:fs.file:vf.ZhP9FgAOTx6T4EV8acbrJg%3Fversion=27/relationships/refs"
},
"related": {
"href": "https://developer.api.autodesk.com/data/v1/projects/b.19e2199f-4132-4c47-9972-37d4708ea59f/versions/urn:adsk.wipprod:fs.file:vf.ZhP9FgAOTx6T4EV8acbrJg%3Fversion=27/refs"
}
},
"data": []
}
Are there any limits for this API?这个API有没有限制? Why would this work on some models and not on the other ones?
为什么这适用于某些模型而不适用于其他模型?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.