编辑自定义命令 > 自定义命令定义示例
  
自定义命令定义示例
示例:用替代属性替换部分 URL
自定义命令的标签为 Button Label,有一个工具提示等。而且,当此命令处于激活状态时,它会检查当前选定的部分是否有指定的属性 (Source_file_name)。如果没有找到,则不会启用该按钮。如果找到了,该属性则会替换 URL 中的子字符串。
<menu
ui="rmb"
view="all"
    pane="all"   
select="any"
    visible="getSelectedCount()==1 &amp;&amp; getPropertyExists(&apos;Source_file_name&apos;)">   
<command_name >MyCommand 1</command_name>
    <label >Button Label</label>  
<tooltip>This is a new command.</tooltip>
<icon>\my\icons\location\icon16x16.png</icon>
<action 
 target="browser">   
http://somewhere.com/content.jsp?partName=&lt;!Source_file_name!&gt;
</action>
</menu>
示例:选择多个部分时,替换 URL 的一个部分
在此示例中,当用户选择两个部分时,Creo View 会获取这两部分的 Featrue_Id 属性值 (通过 getSelectedPartProperty 返回)。然后用这些值替换 URL 的两个子字符串。
<menu
 ui="rmb"
view="all"
pane="all"
select="any"
visible="getSelectedCount()==2 &amp;&amp; getSelectedPartProperty(1,&apos;Feature_Id&apos;,&apos;featureId1&apos;) &amp;&amp;
getSelectedPartProperty(2,&apos;Feature_Id&apos;,&apos;featureId2&apos;)">
 <command_name >MyCommand 2</command_name>
<label >Button Label</label>
<action
target="browser">
http://www.somewhere.com/index.jsp?Id1=&lt;!featureId1!&gt;&amp;Id2=&lt;!featureId2!&gt;
</action>
</menu>