使用脚本的目的是为了将重复的手动工作变为自动处理,例如:自动排序元件的属性显示;将元件的Value属性添加NC/的标签,显示GND的名称属性等操作。以后会持续的更新相应功能的Tcl 脚本出来。以此记录一下我的TCL脚本的能力搭建。各位看客也可以发表自己的需求我可以试着能否制作出来相应的功能的脚本。
在ORCAD中使用Tcl Script的方法。
如何让ORCAD自动加载TCL脚本的步骤
1、在安装路径下新建一个xyz的文件夹,用来存放TCL 脚本的文件。文件名为:xxx.tcl
创建前路径
<Cadence_Installation_Root>\tools\capture\tclscripts\
创建后路径
<Cadence_Installation_Root>\tools\capture\tclscripts\xyz
2、在如下路径文件夹下放置一个xyzInit.tcl的脚本
<Cadence_Installation_Root>\tools\capture\tclscripts\capAutoLoad
实例1:实现一个“将选中Wire自动放置offpage,前提Wire已经放置了NetAlias(网络别名)
将以下的代码复制到本地电脑的txt文件后将后缀名改为.tcl并放置在上述所说路径下发即可
分为三个文件
主脚本xxx.tcl脚本内容如下:
注意事项:
第一行"package provide Placeoffpage 1.0" 中的Placeoffpage为文件名,即xxx.tcl为Placeoffpage.tcl
有路径的语句:如“PlaceOffPage $x $y "D:/Cadence/SPB_16.6/tools/capture/library/capsym.olb" OFFPAGELEFT-L $XName”中的路径要为改为本地capsym.olb库的路径。
package provide Placeoffpage 1.0
proc POPLE {} {
set lStatus [DboState]
set lName [DboTclHelper_sMakeCString]
#获取选中的wire
set lWire [GetSelectedObjects]
#获取选中wire的数量
set n [llength $lWire]
#遍历所有wire的网络名,结束点坐标
for {set i 0} {$i<$n} {incr i 1} {
set lWireName [lindex $lWire $i]
$lWireName GetNetName $lName
set XName [DboTclHelper_sGetConstCharPtr $lName]
set xy [$lWireName GetEndPoint $lStatus]
set xp [DboTclHelper_sGetCPointX $xy]
set yp [DboTclHelper_sGetCPointY $xy]
set x [expr $xp/100.00]
set y [expr $yp/100.00-0.1]
PlaceOffPage $x $y "D:/Cadence/SPB_16.6/tools/capture/library/capsym.olb" OFFPAGELEFT-L $XName
}
}
proc POPLS {} {
set lStatus [DboState]
set lName [DboTclHelper_sMakeCString]
#获取选中的wire
set lWire [GetSelectedObjects]
#获取选中wire的数量
set n [llength $lWire]
#遍历所有wire的网络名,结束点坐标
for {set i 0} {$i<$n} {incr i 1} {
set lWireName [lindex $lWire $i]
$lWireName GetNetName $lName
set XName [DboTclHelper_sGetConstCharPtr $lName]
set xy [$lWireName GetStartPoint $lStatus]
set xp [DboTclHelper_sGetCPointX $xy]
set yp [DboTclHelper_sGetCPointY $xy]
set x [expr $xp/100.00]
set y [expr $yp/100.00-0.1]
PlaceOffPage $x $y "D:/Cadence/SPB_16.6/tools/capture/library/capsym.olb" OFFPAGELEFT-L $XName
}
}
proc POPRE {} {
set lStatus [DboState]
set lName [DboTclHelper_sMakeCString]
#获取选中的wire
set lWire [GetSelectedObjects]
#获取选中wire的数量
set n [llength $lWire]
#遍历所有wire的网络名,结束点坐标
for {set i 0} {$i<$n} {incr i 1} {
set lWireName [lindex $lWire $i]
$lWireName GetNetName $lName
set XName [DboTclHelper_sGetConstCharPtr $lName]
set xy [$lWireName GetEndPoint $lStatus]
set xp [DboTclHelper_sGetCPointX $xy]
set yp [DboTclHelper_sGetCPointY $xy]
set x [expr $xp/100.00-0.1]
set y [expr $yp/100.00-0.1]
PlaceOffPage $x $y "D:/Cadence/SPB_16.6/tools/capture/library/capsym.olb" OFFPAGELEFT-R $XName
}
}
proc POPRS {} {
set lStatus [DboState]
set lName [DboTclHelper_sMakeCString]
#获取选中的wire
set lWire [GetSelectedObjects]
#获取选中wire的数量
set n [llength $lWire]
#遍历所有wire的网络名,结束点坐标
for {set i 0} {$i<$n} {incr i 1} {
set lWireName [lindex $lWire $i]
$lWireName GetNetName $lName
set XName [DboTclHelper_sGetConstCharPtr $lName]
set xy [$lWireName GetStartPoint $lStatus]
set xp [DboTclHelper_sGetCPointX $xy]
set yp [DboTclHelper_sGetCPointY $xy]
set x [expr $xp/100.00-0.1]
set y [expr $yp/100.00-0.1]
PlaceOffPage $x $y "D:/Cadence/SPB_16.6/tools/capture/library/capsym.olb" OFFPAGELEFT-R $XName
}
}
自动加载xyzInit.tcl脚本内容:
注意事项:如下语句的中的路径要换成本地电脑的路径
set dir1 {D:\Cadence\SPB_16.6\tools\capture\tclscripts\xyz}
#
#变量dir1*为脚本的路径
#变更tclName*脚本名称
#
#
set dir1 {D:\Cadence\SPB_16.6\tools\capture\tclscripts\xyz}
#set tclName0 dh.tcl
#set tclName1 submenus.tcl
#set tclName2 refreshoffpageName.tcl
#set tclName3 Placeoffpage.tcl
#set tclName [list $tclName0 $tclName1 $tclName2 $tclName3]
set tclName [list dh.tcl submenus.tcl refreshoffpageName.tcl Placeoffpage.tcl Disp_Select_Part_Prop.tcl]
set m [llength $tclName]
for {set n 0} {$n<$m} {incr n 1} {
set fName [lindex $tclName $n]
lappend lcm $fName
}
set lcm
set tmp "pkg_mkIndex"
#list命令中带$的变更会有“{}”导致pkg_index dir {{filename} {filename}}导致eval指令失效
set ocmd [list $tmp $dir1]
set ocmd [append ocmd " " $lcm]
eval $ocmd
#package require [string trimright $tclName4]
#加载需要的脚本文件
set j [llength $tclName]
for {set i 0} {$i < $j} {incr i} {
set tName [lindex $tclName $i]
#去除.tcl后缀名
regexp {([^.]*).} $tName match host
package require $host
}
3、创建自定义的快捷键和子菜单的脚本
copy如下代码,生成.tcl文件,文件名为submenus.tcl,并放置在本地电脑的<Cadence_Installation_Root>\tools\capture\tclscripts\xyz路径下即可
#/
# WARRANTY: NONE. THIS PROGRAM WAS WRITTEN AS "SHAREWARE" AND IS AVAILABLE AS IS
# AND MAY NOT WORK AS ADVERTISED IN ALL ENVIRONMENTS. THERE IS NO
# SUPPORT FOR THIS PROGRAM
# NOTE: YOU ARE STRONGLY ADVISED TO BACKUP YOUR DESIGN
# BEFORE RUNNING THIS PROGRAM
# TCL file: capMenuUtil.tcl
# contains OrCAD Capture Menu utlities
#
# You can run the script in the Capture TCL command window .
#/
package require Tcl 8.4
package require Placeoffpage 1.0
package provide capMenuUtil 1.0
package provide submenus 1.0
namespace eval ::capMenuUtil {
}
proc ::capMenuUtil::addPageAccessoryMenu { } {
# AddAccessoryMenu <User menu under Accessories> <SubMenu under user menu> <TCL callback #handler with 2 parameters pPage and pOcc>
AddAccessoryMenu "offpage" "LE" "::capMenuUtil::OpenPageoffLE"
AddAccessoryMenu "offpage" "LS" "::capMenuUtil::OpenPageoffLS"
AddAccessoryMenu "offpage" "RE" "::capMenuUtil::OpenPageoffRE"
AddAccessoryMenu "offpage" "RS" "::capMenuUtil::OpenPageoffRS"
}
proc ::capMenuUtil::addDesignAccessoryMenu { } {
# AddAccessoryMenu <User menu under Accessories> <SubMenu under user menu> <TCL callback #handler with 1 parameter pLib>
AddAccessoryMenu "offpage" "Design in L" "::capMenuUtil::OpenDesignNotepad"
AddAccessoryMenu "Process Viewer" "Process Explorer" "::capMenuUtil::OpenDesignProcessExplorer"
}
proc ::capMenuUtil::OpenPageoffLE { pPage pOcc } {
POPLE
}
proc ::capMenuUtil::OpenPageoffLS { pPage pOcc } {
POPLS
}
proc ::capMenuUtil::OpenPageoffRE { pPage pOcc } {
POPRE
}
proc ::capMenuUtil::OpenPageoffRS { pPage pOcc } {
POPRS
}
proc ::capMenuUtil::OpenPageScite { pPage pOcc } {
exec "d:/apps/wscite/SciTE.exe"
}
proc ::capMenuUtil::OpenDesignNotepad { pLib } {
exec "C:/WINDOWS/system32/notepad.exe"
}
proc ::capMenuUtil::OpenDesignScite { pLib } {
exec "d:/apps/wscite/SciTE.exe"
}
proc ::capMenuUtil::OpenDesignProcessExplorer { pLib } {
exec "d:/apps/ProcessExplorer/procexp.exe"
}
proc ::capMenuUtil::capTrue { } {
return 1
}
RegisterAction "_cdnCapTclAddPageCustomMenu" "::capMenuUtil::capTrue" "" "::capMenuUtil::addPageAccessoryMenu" ""
RegisterAction "_cdnCapTclAddDesignCustomMenu" "::capMenuUtil::capTrue" "" "::capMenuUtil::addDesignAccessoryMenu" ""
RegisterAction "offpageL" "::capMenuUtil::capTrue" "Ctrl+Shift+L" "POPL" "Schematic"
RegisterAction "offpageR" "::capMenuUtil::capTrue" "Ctrl+Shift+L" "POPR" "Schematic"
你能得到的结果:
选中一个wire或多个wire后右键你会多出一个选项。
其中offpageL会旋转L类型的offpage,offpageR则旋转R类型的offpage.