特定管理 > 支援視覺化與發行 > WVS 發佈規則 > 使用發佈規則中的條件 > 條件元素
  
條件元素
較新的 <condition> 元素可讓使用者設定規則來在 EPMDocument 中尋找更多屬性,例如生命週期狀態 (例如,In WorkReleased)、CAD 類型 (例如,PartAssembly) 以及容器。這包括引入一些邏輯運算子,例如 AND、OR 與 NOT
Attribute - 此基本屬性元素看起來像這樣:
<attribute name="epmdoc_lifeCycleState" value="Released" />
此元素的 name 屬性是要對所評估的 EPMDocument 進行檢查的屬性。有一個尋找所有可用屬性的方法是在 Creo View 中開啟表示並查看內容。您會看見一系列 epmdoc_* 內容,這些內容全都可用於發佈規則。此外,相關 WTPart 的任何內容也都可用。這些項目也可在 Creo View 中見到,並且會以 part_* 格式顯示。
此範例中的 value 屬性是要對其進行比較的值。如果 EPMDocument 的值等於此元素的 value (區分字母大小寫),則會將此屬性視為 true。
使用者可以使用 regex XML 屬性來使用一般運算式,而不必使用 value,如下列範例所示:
<attribute name="epmdoc_CADName" regex=".*\.asm" />
在此情況下,只要一般運算式模式傳回符合此 EPMDocument 的結果,便會將屬性視為 true。
attribute 元素的另一個用處是檢查屬性是否存在於物件上,但值是什麼無關緊要。這並不會使用 nameregex,且看起來像這樣:
<attribute name="MyIBA" />
Instance-of - <instance-of> 元素的用法與 <attribute> 元素相似,但主要用來查看所評估的物件是否為指定類型。它看起來像這樣:
<instance-of type=”wt.epm.EPMDocument” />
如果物件是 EPMDocument,它就會在發行規則中評估為 true。或者,您可以使用:
<instance-of type="wt.doc.WTDocument" />
如果物件是 WTDocument,它會在發行規則中評估為 true。
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>
在此範例中,所評估的物件必須同時為「組件」及處於「已發行」狀態,陳述式才能為 true。使用 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 Wrapper - 以上所有元素都必須包含在 <condition> 元素中,如下所示:
<condition name="In Work">
<attribute name="epmdoc_lifeCycleState" value="In Work" />
</condition>
"name" 屬性是 <if> 元素 (請參閱下方) 用來參考此條件的屬性。<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 的條件在規則中定義 (如上所述)。