Vuforia Studio 导航 > 项目窗格 > 资源 > 将 CAD 元数据合并到体验中
  
将 CAD 元数据合并到体验中
本主题提供了支持的函数及其自变量和输出的完整列表。
这些 API 基于 Promise。有关 Promise 的详细信息,请参阅 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
有关在体验中使用 CAD 元数据的完整示例项目文件和逐步教程说明,请参阅用例:3D-Guided Service Instructions
API 函数
声明
参数
说明
get (idpath, propName, categoryName)
{string|string[]} idpath - ID 路径 (例如 '/0/1') 或 ID 路径数组 ['/0/1', '/0/2']
{string|string[]} propName -(可选)例如 'Display Name'['Display Name', 'Part ID Path']
{string|string[]} categoryName -(可选)例如 'PROE Parameters'
* 
如果 propName string [],则 categoryName 也必须是匹配长度(或未定义)的数组。
获取表示指定 idpath propName 的 ID 路径或属性值的元数据对象。
此函数返回表示指定 idpath 的元数据对象,若指定 propName,则返回组件的属性值。
示例:
PTC.Metadata.fromId('model-1').then( (metadata) => {
var result = metadata.get('/0/6', 'Display Name')
});
getProp (propName, categoryName)
{string|string[]} propName -(可选)例如 'Display Name'['Display Name', 'Part ID Path']
{string|string[]} categoryName -(可选)例如 'PROE Parameters'
* 
如果 propName string [],则 categoryName 也必须是匹配长度(或未定义)的数组。
此函数返回单个组件的所有字符串属性值,若无可用的数据/组件,则函数未定义。若指定的 propName 是数组,则返回值的 string[]。
示例:
PTC.Metadata.fromId('model-1').then( (metadata) => {
var result = metadata.get('/0/1').getProp('Display Name');
});
getCategory (categoryName)
{string} categoryName
此函数返回指定类别中所有属性名称和值的对象。
示例:
PTC.Metadata.fromId('model-1').then( (metadata) => {
var result = metadata.get('/0/6'). getCategory ('__PV_SystemProperties');
});
getSelected (selectFunc)
{function} selectFunc -(可选)用于控制所返回数组中的值的函数。为函数指定 idpath,并且自变量和当前元数据如下:
`this` function(idpath) {
return [idpath, this.get(idpath, 'Display Name')];
});
此函数返回指定 selectFunc 所返回的任意数组,若为定义 selectFunc,则返回 ID 路径 string[]。
示例:
PTC.Metadata.fromId('model-1').then( (metadata) => {
var selectFunc = function(idpath) {
return metadata.get(idpath, 'Display Name');
}
var result = metadata.getSelected(selectFunc);
});
find (propName, category)
{string} propName -(必填)
{string} category -(可选)
根据属性值查找组件。另请参阅以下 findCustom
根据指定 propName 和类别返回组件的查找器。
示例:

PTC.Metadata.fromId('model-1').then( (metadata) => {
var displayName = metadata.find('Display Name').like('BOLT');
});
PTC.Metadata.fromId('model-1').then( (metadata) => {
var result = metadata.find('Part Depth').lessThan(3).find('Display Name').like('PRT');
});

PTC.Metadata.fromId('model-1').then( (metadata) => {
var selectFunc = function(idpath) {
return metadata.get(idpath, 'Display Name')
var result = metadata.find('Part Depth').greaterThan(4, selectFunc)
});
比较可能如下所示:
- startsWith,like,sameAs,unlike : string comparison
- equal,notequal,greaterThanEq,lessThanEq,lessThan,greaterThan : numeric comparison
- in,out : numeric range comparison
- before,after : date/time comparison
findCustom (whereFunc, selectFunc)
{function} whereFunc -(必填)
{function} selectFunc -(可选)
另请参阅以上 find
此函数根据自定义 whereFunc 返回组件的查找器。以下示例查找所有具有 depth<2 或名称类似 'ASM' 的组件。
示例:

PTC.Metadata.fromId('model-1').then( (metadata) => {
var whereFunc = function(idpath) {
const depth = metadata.get(idpath, 'Part Depth')
const name = metadata.get(idpath, 'Display Name')
return parseFloat(depth) >= 4 || (name && name.search('ASM') >= 0)
}
var result = metadata.findCustom(whereFunc);
});
支持的查找运算符函数
startsWith (propValue, selectFunc)
not (propValue, selectFunc)
sameAs (propValue, selectFunc)
like (propValue, selectFunc)
unlike (propValue, selectFunc)
equal (propValue, selectFunc)
notEqual (propValue, selectFunc)
lessThanEq (propValue, selectFunc)
greaterThanEq (propValue, selectFunc)
lessThan (propValue, selectFunc)
greatThan (propValue, selectFunc)
in (min, max, selectFunc)
out (min, max, selectFunc)
before (propValue, selectFunc)
after (propValue, selectFunc)
findCustom (whereFunc, selectFunc)
使用示例
PTC.Metadata.fromId('model-1').then (metadata) => {
metadata.get('/0/6', 'Display Name')
=> "BLOWER.ASM"
metadata.get('/0/6'). getCategory ('__PV_SystemProperties')
=> {Component Name: "BLOWER.ASM", Display Name: "BLOWER.ASM", OL File Name: "", Part Depth: "3", Part ID: "6", …}
metadata.find('Display Name').like('PRT')
=> {id: "model-1", _friendlyName: "Display Name like PRT", _selectedPaths: Array(26)}
metadata.find('Display Name').like('PRT').find('Part Depth').in(0,3)
=> {id: "model-1", _friendlyName: "Display Name like PRT AND Part Depth in 0-3", _selectedPaths: Array(10)}
var meta = metadata.find('Part Depth').greaterThan(4);
meta.getSelected();
=>["/0", "/0/1", "/0/1/2", "/0/6"]
var selectFunc = function(idpath) {
return metadata.get(idpath, 'Display Name');
}
meta.getSelected(selectFunc);
=> ["PISTON.PRT", "PISTON_PIN.PRT", "CONNECTING_ROD.PRT"]
metadata.find('Part Depth').greaterThan(4).getSelected(selectFunc)
=> ["PISTON.PRT", "PISTON_PIN.PRT", "CONNECTING_ROD.PRT"]
var selectFunc = function(idpath) {
return metadata.get(idpath, 'Display Name');
}
metadata.find('Part Depth').greaterThan(4, selectFunc)
=> ["PISTON.PRT", "PISTON_PIN.PRT", "CONNECTING_ROD.PRT"]
var selectFunc = function(idpath) {return metadata.get(idpath, 'Display Name');}
metadata.find('Part Depth').greaterThan(4, selectFunc)
=> ["PISTON.PRT", "PISTON_PIN.PRT", "CONNECTING_ROD.PRT"]
var selectFunc = function(idpath) {return metadata.get(idpath, 'Display Name');}
metadata.find('Display Name').like('PISTON', selectFunc)
=> ["PISTON.ASM", "PISTON.PRT", "PISTON_PIN.PRT"]

var whereFunc = function(idpath) {
const depth = metadata.get(idpath, 'Part Depth')
const name = metadata.get(idpath, 'Display Name')
return parseFloat(depth) > 4 || (name && name.search('PISTON') >= 0)
}
var selectFunc = function(idpath) {return metadata.get(idpath, 'Display Name');}
metadata.findCustom(whereFunc,selectFunc)
=>["PISTON.ASM", "PISTON.PRT", "PISTON_PIN.PRT", "CONNECTING_ROD.PRT"]
var selectFunc = function(idpath) {
return metadata.get(idpath).getCategory('__PV_SystemProperties');
}
metadata.find('Part Depth').greaterThan(4, selectFunc)
=> (3) [{…}, {…}, {…}]
0: {Component Name: "PISTON.PRT", Display Name: "PISTON.PRT", OL File Name: "l-Creo 3D_0_ac-40_asm_5.ol" …}
1: {Component Name: "PISTON_PIN.PRT", Display Name: "PISTON_PIN.PRT", OL File Name: "l-Creo 3D_0_ac-40_asm_6.ol",…}
2: {Component Name: "CONNECTING_ROD.PRT", Display Name: "CONNECTING_ROD.PRT", OL File Name: "l-Creo 3D_0_ac-40_asm_7.ol", …}