当前位置:   article > 正文

TCL学习(一)——如何在Capture OrCAD中运行脚本_activetcl

activetcl

        本文目标是搭建Capture CIS 17.4环境下的TCL脚本环境。使用的是ActiveTCL,Capture推荐使用8.4版本TCL,本文使用的为Active TCL 8.6。

先上链接:

Active官网下载

(一)环境搭建

        假设用户已经正确安装Capture,在下载完Active TCL后,默认安装,在Windows开始菜单中能看到新增的三个程序:tkcon、Wish、Tclsh。接下来我们需要修改Capture的有关文档,具体步骤如下:

  1. 如果你对Cadence的安装根目录拥有写入权限,你需要修改capinit.tcl文件,该文件位于路径<Cadence Installation Root>\tools\capture\tclscripts定位到capGetTclTkHome并取消以下语句的注释。

    # return [file normalize {TCL/Tk_install_root}]

    大括号内需要指定到ActiveTcl的安装目录。例如return [file normalize {C:/TCL}] 。注意这一操作将会影响这台电脑上使用Cadence的所有用户。

  2. 如果你未拥有Cadence的安装根目录的写入权限,你需要定位%HOME%环境变量对应的目录,在该目录下创建子目录。%HOME%\cdssetup\capture

  3. 在创建了以上目录后,你需要复制capinit.tcl 文件到新建目录并按照第一步修改capinit.tcl

  4. 打开Capture并在Capture Command Window中输入以下命令:

    1. package require Tk
    2. toplevel .new

    这两条命令会启动tk并弹出带有"new"标题的窗口。

(二)运行脚本

        官方提供了部分脚本代码可供学习参考。

  1. 加载脚本。新建笔记本并将文章最后的代码复制粘贴,文本另存为capSyncPropPCBFootprint.tcl,路径为<file_path_to_capSyncPropPCBFootprint.tcl>。注意相较于官方代码,我们注释了头两行代码。这是由于TCL版本不同引起的。
    1. #package require TCL 8.6
    2. #package require DboTclWriteBasic 16.3.0
    打开Capture进入Capture Command Window,使用source命令加载该脚本:
    source [file normalize {<file_path_to_capSyncPropPCBFootprint.tcl>}]
    其中需要将<file_path_to_capSyncPropPCBFootprint.tcl>替换成实际的存放路径。
  2. 调用脚本命令。

    新建Demo,创建Page,并增加/修改其中的内容。在Capture Command Window中键入

    capSyncPropPCBFootprint::syncActiveDesign ReportAllDiffs

    在Capture Command Window中会报告更新信息。

  1. #/
  2. # WARRANTY: NONE. THIS PROGRAM WAS WRITTEN AS "SHAREWARE" AND IS AVAILABLE AS IS
  3. # AND MAY NOT WORK AS ADVERTISED IN ALL ENVIRONMENTS. THERE IS NO
  4. # SUPPORT FOR THIS PROGRAM
  5. # NOTE: YOU ARE STRONGLY ADVISED TO BACKUP YOUR DESIGN
  6. # BEFORE RUNNING THIS PROGRAM
  7. # TCL file: capSyncPropPCBFootprint.tcl
  8. # contains OrCAD Capture Sync PCB Footprint procedures
  9. #/
  10. #package require TCL 8.4
  11. #package require DboTclWriteBasic 16.3.0
  12. package provide capSyncPropPCBFootprint 1.0
  13. namespace eval ::capSyncPropPCBFootprint {
  14. namespace export syncActiveDesign
  15. namespace export syncDesign
  16. variable mOldDiffs [list]
  17. variable mNewDiffs [list]
  18. }
  19. proc ::capSyncPropPCBFootprint::clearList { pList } {
  20. set pList [lreplace $pList 0 end]
  21. return $pList
  22. }
  23. proc ::capSyncPropPCBFootprint::visitPlacedInst { pPlacedInst pMode } {
  24. set lStatus [DboState]
  25. set lNullObj NULL
  26. variable mOldDiffs
  27. variable mNewDiffs
  28. set lCachedPCBFootprintNameStr [DboTclHelper_sMakeCString]
  29. set lPCBFootprintNameStr [DboTclHelper_sMakeCString]
  30. set lRefDesStr [DboTclHelper_sMakeCString]
  31. set lCachedPackage [$pPlacedInst GetPackage $lStatus]
  32. $lCachedPackage GetPCBFootprint $lCachedPCBFootprintNameStr
  33. $pPlacedInst GetPCBFootprint $lPCBFootprintNameStr
  34. set lCachedPCBFootprintName [DboTclHelper_sGetConstCharPtr $lCachedPCBFootprintNameStr]
  35. set lPCBFootprintName [DboTclHelper_sGetConstCharPtr $lPCBFootprintNameStr]
  36. if { $lCachedPCBFootprintName != "" } {
  37. if { $lPCBFootprintName != $lCachedPCBFootprintName} {
  38. $pPlacedInst GetReferenceDesignator $lRefDesStr
  39. set lOldSearchIndex [lsearch $mOldDiffs $pPlacedInst]
  40. if { $pMode == "ReportAllDiffs"} {
  41. lappend mOldDiffs $pPlacedInst
  42. set lMessage [concat $pMode " : PCB Footprint Mismatch :
  43. " [DboTclHelper_sGetConstCharPtr $lRefDesStr] " :
  44. " $lPCBFootprintName " --> " $lCachedPCBFootprintName]
  45. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  46. DboState_WriteToSessionLog $lMessageStr
  47. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  48. }
  49. if { $pMode == "ReportNewDiffs"} {
  50. if { $lOldSearchIndex == -1} {
  51. lappend mNewDiffs $pPlacedInst
  52. set lMessage [concat $pMode " : PCB Footprint Mismatch:
  53. " [DboTclHelper_sGetConstCharPtr $lRefDesStr] " :
  54. " $lPCBFootprintName " --> " $lCachedPCBFootprintName]
  55. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  56. DboState_WriteToSessionLog $lMessageStr
  57. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  58. }
  59. }
  60. set lNewSearchIndex [lsearch $mNewDiffs $pPlacedInst]
  61. if { $pMode == "UpdateNewDiffs"} {
  62. if { $lNewSearchIndex != -1} {
  63. $pPlacedInst SetPCBFootprint $lCachedPCBFootprintNameStr
  64. $pPlacedInst MarkModified
  65. set lMessage [concat $pMode " : PCB Footprint Changed :
  66. " [DboTclHelper_sGetConstCharPtr $lRefDesStr] " :
  67. " $lPCBFootprintName " --> " $lCachedPCBFootprintName]
  68. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  69. DboState_WriteToSessionLog $lMessageStr
  70. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  71. }
  72. }
  73. if { $pMode == "UpdateAllDiffs"} {
  74. $pPlacedInst SetPCBFootprint $lCachedPCBFootprintNameStr
  75. $pPlacedInst MarkModified
  76. set lMessage [concat $pMode " : PCB Footprint Changed :
  77. " [DboTclHelper_sGetConstCharPtr $lRefDesStr] " :
  78. " $lPCBFootprintName " --> " $lCachedPCBFootprintName]
  79. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  80. DboState_WriteToSessionLog $lMessageStr
  81. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  82. }
  83. }
  84. }
  85. $lStatus -delete
  86. return
  87. }
  88. proc ::capSyncPropPCBFootprint::visitPageInsts { pPage pMode } {
  89. set lStatus [DboState]
  90. set lPartInstIter [$pPage NewPartInstsIter $lStatus]
  91. set lPartInst [$lPartInstIter NextPartInst $lStatus]
  92. set lNullObj NULL
  93. while {$lPartInst!=$lNullObj} {
  94. set lPlacedInst [DboPartInstToDboPlacedInst $lPartInst]
  95. if {$lPlacedInst != $lNullObj} {
  96. visitPlacedInst $lPlacedInst $pMode
  97. }
  98. set lPartInst [$lPartInstIter NextPartInst $lStatus]
  99. }
  100. delete_DboPagePartInstsIter $lPartInstIter
  101. $lStatus -delete
  102. return
  103. }
  104. proc ::capSyncPropPCBFootprint::visitPages { pSchematic pMode } {
  105. set lStatus [DboState]
  106. set lPagesIter [$pSchematic NewPagesIter $lStatus]
  107. set lPage [$lPagesIter NextPage $lStatus]
  108. set lNullObj NULL
  109. while {$lPage!=$lNullObj} {
  110. visitPageInsts $lPage $pMode
  111. set lPage [$lPagesIter NextPage $lStatus]
  112. }
  113. delete_DboSchematicPagesIter $lPagesIter
  114. $lStatus -delete
  115. return
  116. }
  117. proc ::capSyncPropPCBFootprint::visitSchematics { pDesign pMode } {
  118. set lStatus [DboState]
  119. set lSchematicIter [$pDesign NewViewsIter $lStatus $::IterDefs_SCHEMATICS]
  120. set lSchematic [$lSchematicIter NextView $lStatus]
  121. set lNullObj NULL
  122. while { $lSchematic!= $lNullObj} {
  123. set lObj [DboViewToDboSchematic $lSchematic]
  124. visitPages $lObj $pMode
  125. set lSchematic [$lSchematicIter NextView $lStatus]
  126. }
  127. delete_DboLibViewsIter $lSchematicIter
  128. $lStatus -delete
  129. return
  130. }
  131. # pMode = ReportAllDiffs | ReportNewDiffs | UpdateAllDiffs | UpdateNewDiffs
  132. proc ::capSyncPropPCBFootprint::syncActiveDesign { pMode } {
  133. set lMessage "---------------------------------------------------------------------------------"
  134. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  135. DboState_WriteToSessionLog $lMessageStr
  136. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  137. set lSession $::DboSession_s_pDboSession
  138. DboSession -this $lSession
  139. set lNullObj NULL
  140. set lDesign [$lSession GetActiveDesign]
  141. if { $lDesign == $lNullObj} {
  142. set lError [DboTclHelper_sMakeCString "Active design not found"]
  143. DboState_WriteToSessionLog $lError
  144. puts [DboTclHelper_sGetConstCharPtr $lError]
  145. return
  146. }
  147. variable mOldDiffs
  148. variable mNewDiffs
  149. if {$pMode == "ReportAllDiffs"} {
  150. set mOldDiffs [clearList $mOldDiffs]
  151. set mNewDiffs [clearList $mNewDiffs]
  152. }
  153. if {$pMode == "ReportNewDiffs"} {
  154. set mOldDiffs [concat $mOldDiffs $mNewDiffs]
  155. set mNewDiffs [clearList $mNewDiffs]
  156. }
  157. #updateNewDiffs should forcibly call ReportNewDiffs first
  158. if {$pMode == "UpdateNewDiffs"} {
  159. set mNewDiffs [clearList $mNewDiffs]
  160. visitSchematics $lDesign "ReportNewDiffs"
  161. }
  162. #updateNewDiffs should forcibly call ReportAllDiffs first
  163. if {$pMode == "UpdateAllDiffs"} {
  164. set mOldDiffs [clearList $mOldDiffs]
  165. set mNewDiffs [clearList $mNewDiffs]
  166. visitSchematics $lDesign "ReportAllDiffs"
  167. }
  168. visitSchematics $lDesign $pMode
  169. if {$pMode == "UpdateAllDiffs"} {
  170. set mOldDiffs [clearList $mOldDiffs]
  171. set mNewDiffs [clearList $mNewDiffs]
  172. }
  173. if {$pMode == "UpdateNewDiffs"} {
  174. set mNewDiffs [clearList $mNewDiffs]
  175. }
  176. DboTclHelper_sReleaseAllCreatedPtrs
  177. set lMessage "---------------------------------------------------------------------------------"
  178. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  179. DboState_WriteToSessionLog $lMessageStr
  180. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  181. return
  182. }
  183. # pMode = ReportAllDiffs | UpdateAllDiffs
  184. proc ::capSyncPropPCBFootprint::syncDesign { pDesignPath pMode } {
  185. set lMessage "---------------------------------------------------------------------------------"
  186. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  187. DboState_WriteToSessionLog $lMessageStr
  188. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  189. set lSession [DboTclHelper_sCreateSession]
  190. set lStatus [DboState]
  191. set lDesignPath [DboTclHelper_sMakeCString $pDesignPath]
  192. set lDesign [DboSession_GetDesignAndSchematics $lSession $lDesignPath $lStatus]
  193. set lNullObj NULL
  194. if { $lDesign == $lNullObj} {
  195. set lError [DboTclHelper_sMakeCString [concat "Design not found : " $pDesignPath]]
  196. DboState_WriteToSessionLog $lError
  197. puts [DboTclHelper_sGetConstCharPtr $lError]
  198. return
  199. }
  200. variable mOldDiffs
  201. variable mNewDiffs
  202. if {$pMode == "ReportAllDiffs"} {
  203. set mOldDiffs [clearList $mOldDiffs]
  204. set mNewDiffs [clearList $mNewDiffs]
  205. }
  206. visitSchematics $lDesign $pMode
  207. if {$pMode == "UpdateAllDiffs"} {
  208. $lSession MarkAllLibForSave $lDesign
  209. $lSession SaveDesign $lDesign
  210. }
  211. if {$pMode == "UpdateAllDiffs"} {
  212. set mOldDiffs [clearList $mOldDiffs]
  213. set mNewDiffs [clearList $mNewDiffs]
  214. }
  215. $lSession RemoveDesign $lDesign
  216. delete_DboSession $lSession
  217. $lStatus -delete
  218. DboTclHelper_sReleaseAllCreatedPtrs
  219. set lMessage "---------------------------------------------------------------------------------"
  220. set lMessageStr [DboTclHelper_sMakeCString $lMessage]
  221. DboState_WriteToSessionLog $lMessageStr
  222. puts [DboTclHelper_sGetConstCharPtr $lMessageStr]
  223. return
  224. }

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/188010?site
推荐阅读
相关标签
  

闽ICP备14008679号