3DE 知识工程 —— 使用 EKL 操作特征属性

目录

1、EKL 简介

2、使用 EKL 操作特征属性

2.1  获取特征属性

2.2  遍历特征属性

2.3  修改特征属性


1、EKL 简介

EKL ,全称为企业知识语言(Enterprise Knowledge Language),它是 3DE 平台内置的面向对象的解释型脚本语言。使用 EKL 可以将企业设计知识、业务规则等嵌入到用户特征、工程模板及操作中,提高产品设计的自动化程度和质量。

2、使用 EKL 操作特征属性

在进行产品设计的时候,有时候需要对特征的部分属性执行批量操作或者根据特征的属性进行对象过滤,EKL 提供了一系列函数用于操作特征属性。

2.1  获取特征属性

GetAttributeXXX() 系列函数根据属性名称获取特征的 XXX 类型属性,返回相应类型的属性值,具体如下: 

String GetAttributeString(String name)
Real GetAttributeReal(String name)
Integer GetAttributeInteger(String name)
Boolean GetAttributeBoolean(String name)
Date GetAttributeDate(String name)
ValuePointer GetAttributeValuePointer(String name)
Feature GetAttributeObject(String name)
  • GetAttributeString(String name) 用于获取 String 值类型的属性,例如获取特征的名称:
iFeature :  Feature 
--------------------------

let attributeValue(String)
attributeValue = iFeature->GetAttributeString("Name")

Notify("#", attributeValue) // 输出属性值
  • GetAttributeReal(String name) 用于获取 Real 值类型的属性,Real 是 Integer、LENGTH、VOLUME 等的基类(图 1),因此它也可以获取这些类型的属性,可以将返回的属性值赋给对应类型的变量,也可以直接赋给 Real 类型变量(返回值会执行隐式类型转换)。例如获取长度:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(LENGTH)
attributeValue = iFeature->GetAttributeReal("len")

Notify("#", attributeValue)
图 1  EKL 类型继承关系
图 2  参数集特征
  • GetAttributeInteger(String name) 用于获取 Integer 值类型的属性,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(Integer)
attributeValue = iFeature->GetAttributeInteger("int")

Notify("#", attributeValue)
  • GetAttributeBoolean(String name) 用于获取 Boolean 值类型的属性,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(Boolean)
attributeValue = iFeature->GetAttributeBoolean("bool")

Notify("#", attributeValue)
  • GetAttributeDate(String name) 用于获取 Date 值类型的属性,直接输出 Date 会显示一个时间戳,可以使用 DateFormat 对其进行格式化输出,例如:
iFeature :  Feature // VPMRepInstance
--------------------------

let attributeValue(Date)
attributeValue = iFeature->GetAttributeDate("C_created")

Notify("#", attributeValue)

let formatValue(String)
formatValue = DateFormat("%Y/%m/%d %H:%M:%S", attributeValue)

Notify("#", formatValue)
  • GetAttributeValuePointer(String name) 用于获取 Literal 值类型的指针,并可以通过指针修改属性值,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(ValuePointer)
attributeValue = iFeature->GetAttributeValuePointer("str")

Notify("#", attributeValue.Value)

attributeValue->SetValue("Hello") // 方式一
attributeValue.Value = "World" // 方式二
  • GetAttributeObject(String name) 用于获取 Feature 值类型的属性,例如获取直线的端点:
iFeature :  Feature // GSMLinePtPt ,图 3
--------------------------

let attributeValue(Feature)
attributeValue = iFeature->GetAttributeObject("FirstPoint")

Notify("#", attributeValue.Name)
图 3  直线特征

2.2  遍历特征属性

获取特征属性时,需要传入特征的属性名称作为参数,如果不知道特征有哪些属性以及属性名称该怎么办呢?EKL 提供了以下函数获取特征的属性名称:

List ListAttributeNames(String typeFilter, Boolean dynamicOnly)
List ListAttributesValuePointers(String typeFilter)
  • ListAttributeNames(String typeFilter, Boolean dynamicOnly) 用于获取特征指定类型的全部属性名称,并返回属性名称的列表。参数 typeFilter 用于指定要获取的属性值类型,参数 dynamicOnly 指定是否获取动态添加到特征的属性。这个方法不是递归的,它仅获取特征的直接属性名称。

例 1 - 遍历值类型为字符串的属性(其他 Literal 类型用法一样):

iFeature :  Feature 
--------------------------

let nameList(List)
nameList = iFeature->ListAttributeNames("String", FALSE)

let nbAttributes(Integer)
nbAttributes = nameList->Size()

Notify("Number of Attributes is # .|", nbAttributes)

let i(Integer)
for i = 1 while i <= nbAttributes
{
	let name(String)
	name = nameList->GetItem(i)

	Notify("# - <# : #>", i, name, iFeature->GetAttributeString(name))
}

例 2 - 遍历值类型为特征的属性:

iFeature :  Feature 
--------------------------

let nameList(List)
nameList = iFeature->ListAttributeNames("Feature", FALSE)

let nbAttributes(Integer)
nbAttributes = nameList->Size()

Notify("Number of Attributes is # .|", nbAttributes)

let i(Integer)
for i = 1 while i <= nbAttributes
{
	let name(String)
	name = nameList->GetItem(i)

	let attributeFeature(Feature)
	set attributeFeature = iFeature->GetAttributeObject(name)

	Notify("# - <# : #>", i, name, attributeFeature.Name)
}

注意:ListAttributeNames 的参数 typeFilter 指定的类型应为 GetAttributeXXX() 函数的类型或其派生类型。

  • ListAttributesValuePointers(String typeFilter) 用于获取 Literal 值类型的指针,并返回属指针列表。参数 typeFilter 可用于指定 Literal 的派生类型。这个方法不是递归的,它仅获取特征直接属性的指针。

例 3 - 遍历特征 Literal 值类型的指针:

iFeature :  Feature // 图 2
--------------------------

let pointerList(List)
pointerList = iFeature->ListAttributesValuePointers("Literal")

let nbAttributes(Integer)
nbAttributes = pointerList->Size()

Notify("Number of Attributes is # .|", nbAttributes)

let i(Integer)
for i = 1 while i <= nbAttributes
{
	let vp(ValuePointer)
	vp = pointerList->GetItem(i)

	Notify("# - <# : #>", i, vp.Name, vp.Value)
}

注意:ListAttributesValuePointers 根据类型获取值指针列表,GetAttributeValuePointer 根据属性名称获取单个值指针。

2.3  修改特征属性

获取到特征的属性后能进行修改吗?答案是肯定的。EKL 提供了下列函数用于设置特征属性:

void SetAttributeString(String name, String value)
void SetAttributeReal(String name, Real value)
void SetAttributeInteger(String name, Integer value)
void SetAttributeBoolean(String name, Boolean value)
void SetAttributeDate(String name, Date value)
void SetAttributeDimension(String name, Real value, String type)
void SetAttributeObject(String name, Feature value)
  • SetAttributeString(String name, String value) 用于设置 String 属性,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(String)
attributeValue = "Hello World"

iFeature->SetAttributeString("str", attributeValue)
  • SetAttributeReal(String name, Real value) 用于设置 Real 属性,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(Real)
attributeValue = 3.14

iFeature->SetAttributeReal("real", attributeValue)
  • SetAttributeInteger(String name, Integer value) 用于设置 Integer 属性,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(Integer)
attributeValue = 32

iFeature->SetAttributeInteger("int", attributeValue)
  • SetAttributeBoolean(String name, Boolean value) 用于设置 Boolean 属性,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(Boolean)
attributeValue = FALSE

iFeature->SetAttributeBoolean("bool", attributeValue)
  • SetAttributeDate(String name, Date value) 用于设置 Date 属性,例如:
iFeature :  Feature 
--------------------------

let attributeValue(Date)
attributeValue = BuildDate()

// 这只是一个示例,实际上日期属性通常都是只读属性
iFeature->SetAttributeDate("C_created", attributeValue) // 只读
  • SetAttributeDimension(String name, Real value, String type) 用于设置 Dimension 属性,例如:
iFeature :  Feature // 图 2
--------------------------

let attributeValue(MASS)
attributeValue = 60kg

iFeature->SetAttributeDimension("mass", attributeValue, "MASS")

// 实际上,以下这种方式也可以
iFeature->SetAttributeReal("mass", attributeValue)
  • SetAttributeObject(String name, Feature value) 用于设置 Feature 属性,例如设置直线的端点:
iFeature :  Feature // GSMLinePtPt ,图 3
iPoint :  Point 
--------------------------

let attributeValue(Feature)
attributeValue = iPoint

iFeature->SetAttributeObject("FirstPoint", attributeValue)
iFeature->Update()

以上是使用 EKL 操作特征属性的一般通用方法,对于具体的特征对象,还可以通过语言浏览器(图 4)查看特征的属性,然后直接进行操作。

图 4  语言浏览器
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值