专业化管理 > 支持可视化和发布 > WVS 发布规则 > 发布规则的使用条件 > 条件元素
  
条件元素
更高版本的 <condition> 元素使用户能够设置规则以便在 EPMDocument 上查询更多属性,例如生命周期状态 (如,In WorkReleased)、CAD 类型 (如,PartAssembly) 和容器。这包括对 AND、OR 和 NOT 等一些逻辑运算符的说明
属性 - 基础属性元素如下所示:
<attribute name="epmdoc_lifeCycleState" value="Released" />
此元素的 name 属性是要在计算 EPMDocument 时检查的属性。查找全部可用属性的一种方法是在 Creo View 中打开一个表示并查看属性。您将会看到一系列 epmdoc_* 属性,它们都可以用于这些发布规则。此外,任何相关 WTPart 的属性也可供使用。它们在 Creo View 中也都可见,并显示为 part_* 格式。
在此示例中,value 属性是要作为比较对象的值。如果 EPMDocument 的值与此元素的 value 相等 (区分大小写),则此属性被视为真。
用户也可以不使用 value,而是通过 regex XML 属性来使用正则表达式,如下例所示:
<attribute name="epmdoc_CADName" regex=".*\.asm" />
在这种情况下,只要正则表达式模式返回此 EPMDocument 的匹配值,该属性就会被视为“真”。
attribute 元素的另一个用途是检查某个属性在对象中是否存在,但它并不关注具体的值。这将不会使用 nameregex,它看上去类似于:
<attribute name="MyIBA" />
Instance-of - <instance-of> 元素的用法与 <attribute> 元素类似,只不过它是用来查看计算的对象是否为指定类型。它看上去类似于:
<instance-of type=”wt.epm.EPMDocument” />
如果对象是 EPMDocument,则它将在发布规则中计算为“真”。或者,您也可以使用:
<instance-of type="wt.doc.WTDocument" />
如果对象是 WTDocument,它将在发布规则中计算为“真”。
structure - <structure> 元素如下所示:
<structure type=”epm” />
<structure> 与现有的 <structure-type type="epm"> 元素类似,并具有相同的行为。有关这一新元素的详细信息,请参阅发布规则元素的兼容性
Logical Operators - attributeinstance-ofstructure 等元素可以单独使用,但是如果通过逻辑运算符将其组合到一起,则功能会变得更加强大。新支持的运算符有 ANDORNOT。例如:
<and>
<attribute name="epmdoc_lifeCycleState" value="Released" />
<attribute name="epmdoc_docType" value="Assembly"/>
</and>
在本例中,为使语句为真,正在计算的对象必须为装配和已发布状态。OR 的使用方式极为类似:
<or>
<attribute name="epmdoc_lifeCycleState" value="Released" />
<attribute name="epmdoc_lifeCycleState" value="In Work" />
</or>
在此示例中,该对象状态为 ReleasedIn Work<and><or> 可以有两个以上的子元素;但至少需要两个。例如:
<and>
<attribute name="epmdoc_lifeCycleState" value="Released" />
<attribute name="epmdoc_docType" value="Assembly"/>
<instance-of type=”EPMDocument” />
</and>
<NOT> 以类似的方式工作,但可以仅有一个子元素。下面的示例表明正在计算的对象“未发布”:
<not>
<attribute name="epmdoc_lifeCycleState" value="Released" />
</not>
要添加这些语句的能力,可以使用相互嵌套的逻辑运算符来创建复杂的计算。下面的示例表明这是一个处于“正在工作”或“已发布”状态的装配:
<and>
<attribute name="epmdoc_docType" value="Assembly"/>
<or>
<attribute name="epmdoc_lifeCycleState" value="In Work"/>
<attribute name="epmdoc_lifeCycleState" value="Released"/>
</or>
</and>
接下来的示例表明该对象处于“正在工作的绘图”或“已发布的装配”状态
<or>
<and>
<attribute name="epmdoc_lifeCycleState" value="In Work"/>
<attribute name="epmdoc_docType" value="Drawing"/>
</and>
<and>
<attribute name="epmdoc_docType" value="Assembly"/>
<attribute name="epmdoc_lifeCycleState" value="Released"/>
</and>
</or>
嵌套的深度没有层级限制。
条件封套 - 上述全部元素都必须封装在 <条件> 元素中,如下所示:
<condition name="In Work">
<attribute name="epmdoc_lifeCycleState" value="In Work" />
</condition>
<if> 元素 (参见下方) 将使用 "name" 属性来引用此条件。<condition> 元素可以位于根 <rules> 元素下,这时它们可用于全部 <authoring-application> 元素,它们也可以位于特定的 <authoring-application> 下,这时只能用在该上下文中。"name" 属性在整个发布规则文档中必须唯一。下面是另一个使用逻辑运算符的示例:
<condition name="Released Assembly”>
<and>
<attribute name="epmdoc_lifeCycleState" value="Released" />
<attribute name="epmdoc_docType" value="Assembly"/>
</and>
</condition>
if condition - 要使用已定义的 <condition> 元素控制发布,需要按以下方式使用 <if> 元素:
<if condition="Released Assembly">
<publish on="checkin" />
<publish on="create-representation" />
<publish on="schedule" />
</if>
此处,将在规则中定义名称为 Released Assembly 的条件 (如上所述)。