在 Autodesk forge 中选择的项目中获取不同的 3d 视图
Get different 3d views within item selected in Autodesk forge
我们使用 Autodesk Forge 中的数据管理 API 获取中心、文件夹列表、文件夹内的项目。
参考:https://forge.autodesk.com/en/docs/data/v2/reference/http/
如果我们想要显示所选项目(例如,file1.rvt)中存在的所有 3d 视图(名称和缩略图),如何获取数据?
为此,您需要提取要为其显示 Views/Thumbnails 的文件项版本的清单和元数据。在您的 Item 负载中,您将找到所有可用的版本。拿最新的一个,找到它的 'id',它看起来像这样:
"id": "urn:adsk.wipprod:fs.file:vf.7aKButAtTo-VRvSJqZl0jg?version=13",
将其编码为安全的 Base64 编码。对 ID 进行安全编码很重要,否则您最终可能会得到 '=' '-' '/' 字符,这些字符稍后在 GET URL 路径上无效。
dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLjdhS0J1dEF0VG8tVlJ2U0pxWmwwamc_dmVyc2lvbj0xMw
要获得观看次数,您通常会拉 metadata 并获得如下内容:
{
"data": {
"type": "metadata",
"metadata": [
{
"name": "3D View: View 01",
"role": "3d",
"guid": "a6128518-dcf0-967b-31a1-3439a375daeb"
},
{
"name": "3D View: View 02",
"role": "3d",
"guid": "488e0550-6e79-38b3-9f56-ae8fd21416bb"
},
{
"name": "Sheet: A00 - SITE PLAN",
"role": "2d",
"guid": "beaab4e2-9abc-8ca2-4e65-23df60e4b6a7"
}
]
}
}
有两种缩略图 - 文件缩略图,通常是上次保存文件时处于活动状态的视图。您可以通过 GET /thumbnail API. But if you want to get all Views' Thumbnail, you need to pull the manifest 获取该缩略图并解析 JSON 响应。你会得到这样的回复(为了让阅读更容易post,我简化了下面的回复)。
您将搜索具有“角色”===“缩略图”的子节点。它的父级会告诉您它附加到哪个视图。这里需要注意的是,您实际上并不需要调用 /metadata 端点,因为清单已经为您提供了所有信息,只要您知道在哪里阅读它即可。例如,假设我想为 Sheet 视图获取 200x200 的缩略图分辨率。
我将搜索“type”===“geometry”&&“role”===“2d”的节点,然后在其子节点中搜索“role”===“thumbnail”的节点&& "决议" === [200, 200]。从该节点,我得到派生 URN(即“urn”:“urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_200.png”,)现在我可以使用GET :urn/manifest/:derivativeurn 获取缩略图文件的端点。就是这样。
请注意,父节点具有视图名称,其子节点之一具有“角色”===“图形”&&“mime”:“application/autodesk-f2d”和一个 属性与元数据响应中的条目匹配的“guid”。因此,您可以从元数据端点的清单中提取名称和 guid 视图。 (对于 3D 视图,您需要搜索“mime”:“application/autodesk-svf”或“mime”:“application/autodesk-svf2”,具体取决于您将模型转换为的格式)。
{
"urn": "dXJuOm...uZHdmeA",
"derivatives": [
{
"hasThumbnail": "true",
"children": [
{
"role": "3d",
"hasThumbnail": "true",
"children": [
{
"role": "graphics",
"mime": "application/autodesk-svf2",
"guid": "a6128518-dcf0-967b-31a1-3439a375daeb",
"type": "resource"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/f0224dd3-8767-45c1-ff99-5c9c881b9fee/0.svf.png01_thumb_400x400.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "630d764b-6e55-4d17-8446-6858454d8158",
"type": "resource",
"resolution": [400, 400]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/f0224dd3-8767-45c1-ff99-5c9c881b9fee/0.svf.png01_thumb_200x200.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "7294c4f7-55ec-41d7-94e5-98c7294d1ae1",
"type": "resource",
"resolution": [200, 200]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/f0224dd3-8767-45c1-ff99-5c9c881b9fee/0.svf.png01_thumb_100x100.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "d1f2f54d-1ce7-49e0-8360-24f212a0cb33",
"type": "resource",
"resolution": [100, 100]
},
...
],
"name": "3D View: View 01",
"guid": "f0224dd3-8767-45c1-ff99-5c9c881b9fee",
"progress": "complete",
"type": "geometry",
"properties": {...},
"status": "success",
"viewableID": "f0224dd3-8767-45c1-ff99-5c9c881b9fee"
},
{
"role": "3d",
"hasThumbnail": "true",
"children": [
{
"role": "graphics",
"mime": "application/autodesk-svf2",
"guid": "488e0550-6e79-38b3-9f56-ae8fd21416bb",
"type": "resource"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/5f6ae103-9de8-048e-f858-c7b0b0b9f46c/1.svf.png01_thumb_400x400.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "e4ff0fb3-20a0-43c2-b01a-e35f08205ea9",
"type": "resource",
"resolution": [ 400, 400 ]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/5f6ae103-9de8-048e-f858-c7b0b0b9f46c/1.svf.png01_thumb_200x200.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "0fe4e17a-8eb9-49c3-bfca-7f8e747ae779",
"type": "resource",
"resolution": [ 200, 200 ]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/5f6ae103-9de8-048e-f858-c7b0b0b9f46c/1.svf.png01_thumb_100x100.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "b0353527-cade-48bb-bbfc-7b544ea2d0ae",
"type": "resource",
"resolution": [ 100, 100 ]
},
...
],
"name": "3D View: View 02",
"guid": "5f6ae103-9de8-048e-f858-c7b0b0b9f46c",
"progress": "complete",
"type": "geometry",
"properties": {...},
"status": "success",
"viewableID": "5f6ae103-9de8-048e-f858-c7b0b0b9f46c"
},
{
"guid": "e28378ef-7b4a-878f-cb72-26fbb1a28b2e",
"type": "geometry",
"role": "2d",
"name": "Sheet: A00 - SITE PLAN",
"status": "success",
"hasThumbnail": "true",
"progress": "complete",
"viewableID": "com.autodesk.dwf.ePlot_281AFDC7-8CE7-4D19-BE69-A47E6364BF53",
"children": [
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/primaryGraphics.f2d",
"role": "graphics",
"mime": "application/autodesk-f2d",
"guid": "beaab4e2-9abc-8ca2-4e65-23df60e4b6a7",
"type": "resource",
"status": "success"
},
{
"guid": "382e91af-fb2f-4782-a058-6bff5a477c89",
"type": "view",
"role": "2d",
"name": "Sheet: A00 - SITE PLAN",
"viewbox": [...]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_400.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "74d8c07b-0703-2505-8c78-c4d7c95fd620",
"type": "resource",
"resolution": [400, 400],
"status": "success"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_200.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "0aec7773-5a02-c9ed-37b2-0e92020dc63a",
"type": "resource",
"resolution": [200, 200],
"status": "success"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_100.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "91011625-63a4-1165-4e6f-700dedff94a7",
"type": "resource",
"resolution": [ 100, 100 ],
"status": "success"
},
...
]
}
],
"name": "Myfile.rvt",
"progress": "complete",
"outputType": "svf2",
"status": "success"
}
],
"hasThumbnail": "true",
"progress": "complete",
"type": "manifest",
"region": "US",
"version": "1.0",
"status": "success"
}
我们使用 Autodesk Forge 中的数据管理 API 获取中心、文件夹列表、文件夹内的项目。
参考:https://forge.autodesk.com/en/docs/data/v2/reference/http/
如果我们想要显示所选项目(例如,file1.rvt)中存在的所有 3d 视图(名称和缩略图),如何获取数据?
为此,您需要提取要为其显示 Views/Thumbnails 的文件项版本的清单和元数据。在您的 Item 负载中,您将找到所有可用的版本。拿最新的一个,找到它的 'id',它看起来像这样:
"id": "urn:adsk.wipprod:fs.file:vf.7aKButAtTo-VRvSJqZl0jg?version=13",
将其编码为安全的 Base64 编码。对 ID 进行安全编码很重要,否则您最终可能会得到 '=' '-' '/' 字符,这些字符稍后在 GET URL 路径上无效。
dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLjdhS0J1dEF0VG8tVlJ2U0pxWmwwamc_dmVyc2lvbj0xMw
要获得观看次数,您通常会拉 metadata 并获得如下内容:
{
"data": {
"type": "metadata",
"metadata": [
{
"name": "3D View: View 01",
"role": "3d",
"guid": "a6128518-dcf0-967b-31a1-3439a375daeb"
},
{
"name": "3D View: View 02",
"role": "3d",
"guid": "488e0550-6e79-38b3-9f56-ae8fd21416bb"
},
{
"name": "Sheet: A00 - SITE PLAN",
"role": "2d",
"guid": "beaab4e2-9abc-8ca2-4e65-23df60e4b6a7"
}
]
}
}
有两种缩略图 - 文件缩略图,通常是上次保存文件时处于活动状态的视图。您可以通过 GET /thumbnail API. But if you want to get all Views' Thumbnail, you need to pull the manifest 获取该缩略图并解析 JSON 响应。你会得到这样的回复(为了让阅读更容易post,我简化了下面的回复)。
您将搜索具有“角色”===“缩略图”的子节点。它的父级会告诉您它附加到哪个视图。这里需要注意的是,您实际上并不需要调用 /metadata 端点,因为清单已经为您提供了所有信息,只要您知道在哪里阅读它即可。例如,假设我想为 Sheet 视图获取 200x200 的缩略图分辨率。
我将搜索“type”===“geometry”&&“role”===“2d”的节点,然后在其子节点中搜索“role”===“thumbnail”的节点&& "决议" === [200, 200]。从该节点,我得到派生 URN(即“urn”:“urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_200.png”,)现在我可以使用GET :urn/manifest/:derivativeurn 获取缩略图文件的端点。就是这样。
请注意,父节点具有视图名称,其子节点之一具有“角色”===“图形”&&“mime”:“application/autodesk-f2d”和一个 属性与元数据响应中的条目匹配的“guid”。因此,您可以从元数据端点的清单中提取名称和 guid 视图。 (对于 3D 视图,您需要搜索“mime”:“application/autodesk-svf”或“mime”:“application/autodesk-svf2”,具体取决于您将模型转换为的格式)。
{
"urn": "dXJuOm...uZHdmeA",
"derivatives": [
{
"hasThumbnail": "true",
"children": [
{
"role": "3d",
"hasThumbnail": "true",
"children": [
{
"role": "graphics",
"mime": "application/autodesk-svf2",
"guid": "a6128518-dcf0-967b-31a1-3439a375daeb",
"type": "resource"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/f0224dd3-8767-45c1-ff99-5c9c881b9fee/0.svf.png01_thumb_400x400.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "630d764b-6e55-4d17-8446-6858454d8158",
"type": "resource",
"resolution": [400, 400]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/f0224dd3-8767-45c1-ff99-5c9c881b9fee/0.svf.png01_thumb_200x200.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "7294c4f7-55ec-41d7-94e5-98c7294d1ae1",
"type": "resource",
"resolution": [200, 200]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/f0224dd3-8767-45c1-ff99-5c9c881b9fee/0.svf.png01_thumb_100x100.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "d1f2f54d-1ce7-49e0-8360-24f212a0cb33",
"type": "resource",
"resolution": [100, 100]
},
...
],
"name": "3D View: View 01",
"guid": "f0224dd3-8767-45c1-ff99-5c9c881b9fee",
"progress": "complete",
"type": "geometry",
"properties": {...},
"status": "success",
"viewableID": "f0224dd3-8767-45c1-ff99-5c9c881b9fee"
},
{
"role": "3d",
"hasThumbnail": "true",
"children": [
{
"role": "graphics",
"mime": "application/autodesk-svf2",
"guid": "488e0550-6e79-38b3-9f56-ae8fd21416bb",
"type": "resource"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/5f6ae103-9de8-048e-f858-c7b0b0b9f46c/1.svf.png01_thumb_400x400.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "e4ff0fb3-20a0-43c2-b01a-e35f08205ea9",
"type": "resource",
"resolution": [ 400, 400 ]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/5f6ae103-9de8-048e-f858-c7b0b0b9f46c/1.svf.png01_thumb_200x200.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "0fe4e17a-8eb9-49c3-bfca-7f8e747ae779",
"type": "resource",
"resolution": [ 200, 200 ]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/5f6ae103-9de8-048e-f858-c7b0b0b9f46c/1.svf.png01_thumb_100x100.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "b0353527-cade-48bb-bbfc-7b544ea2d0ae",
"type": "resource",
"resolution": [ 100, 100 ]
},
...
],
"name": "3D View: View 02",
"guid": "5f6ae103-9de8-048e-f858-c7b0b0b9f46c",
"progress": "complete",
"type": "geometry",
"properties": {...},
"status": "success",
"viewableID": "5f6ae103-9de8-048e-f858-c7b0b0b9f46c"
},
{
"guid": "e28378ef-7b4a-878f-cb72-26fbb1a28b2e",
"type": "geometry",
"role": "2d",
"name": "Sheet: A00 - SITE PLAN",
"status": "success",
"hasThumbnail": "true",
"progress": "complete",
"viewableID": "com.autodesk.dwf.ePlot_281AFDC7-8CE7-4D19-BE69-A47E6364BF53",
"children": [
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/primaryGraphics.f2d",
"role": "graphics",
"mime": "application/autodesk-f2d",
"guid": "beaab4e2-9abc-8ca2-4e65-23df60e4b6a7",
"type": "resource",
"status": "success"
},
{
"guid": "382e91af-fb2f-4782-a058-6bff5a477c89",
"type": "view",
"role": "2d",
"name": "Sheet: A00 - SITE PLAN",
"viewbox": [...]
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_400.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "74d8c07b-0703-2505-8c78-c4d7c95fd620",
"type": "resource",
"resolution": [400, 400],
"status": "success"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_200.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "0aec7773-5a02-c9ed-37b2-0e92020dc63a",
"type": "resource",
"resolution": [200, 200],
"status": "success"
},
{
"urn": "urn:adsk.viewing:fs.file:dXJuOm...uZHdmeA/output/e28378ef-7b4a-878f-cb72-26fbb1a28b2e_f2d/thumbnail_100.png",
"role": "thumbnail",
"mime": "image/png",
"guid": "91011625-63a4-1165-4e6f-700dedff94a7",
"type": "resource",
"resolution": [ 100, 100 ],
"status": "success"
},
...
]
}
],
"name": "Myfile.rvt",
"progress": "complete",
"outputType": "svf2",
"status": "success"
}
],
"hasThumbnail": "true",
"progress": "complete",
"type": "manifest",
"region": "US",
"version": "1.0",
"status": "success"
}