[Circuit] Orcad TCL 介紹

程式語言:Tcl
Orcad 官方文件
GitHub 範例

功能:可用 Tcl 語言控制 Orcad

執行方法

View->Toolbar->Command Window Menu

查詢指令

  • 查詢
    • info command *xxx*
  • 印出目前動作指令
    • SetOptionBool Journaling TRUE
      SetOptionBool DisplayCommands TRUE
  • 記錄動作過程的指令
    • Macro -> record
      Macro -> configure -> saveas

基本介紹

  • Design Database Object Model
    • 使用於電路
  • Library Database Object Model
    • 使用於 library
  • Database class hierarchy
    • 查詢指令必須連同繼承的一併查詢,才足夠完整
      例如:DboLib
      info commands DboLib_* 和 info commands DboBaseObject_*
  • 基本
    • 變數
      • 賦值
        • 名字前不用加上 $
        • set x 20
      • 印值
        • 名字前需加上 $
        • puts $x
    • command 中的 subcommand
      • [subcommand]
        • puts [set x 20]
      • 可多個,不限定個數
    • 字串
      • puts "xxx $abc"
        後者的 $abc 將被當作變數替換掉
      • puts {xxx $abc}
        當作 raw data 直接輸出 xxx $abc
    • List
      • 賦值:list xxx yyy
        • set ls [list "Cadence Design" Systems]
      • 長度:llength $ls
        • puts [llength $ls]
      • 第 n 個的值:lindex $ls n
        • puts [lindex $ls 0]
    • 數學
    • 自定函數
      • proc
        • proc mul {i j} {
          expr {$i*$j}
          }
      • 輸入變數前不用加上 $
    • if、foreach、proc 等的大括號 { 必須在同一行,不然會出錯
    • Tcl 版本
      • puts $tcl_version
    • 呼叫的方法
      • command_with_classname $object <parameters>
        • DboLib_GetName $lLib $lName
      • $object command_without_classname <parameters>
        • $lLib GetName $lName
    • 字串轉換
      • set lName [DboTclHelper_sMakeCString]
        • 因大部分的指令參數皆為 CString,需進行轉換
      • puts [DboTclHelper_sGetConstCharPtr $lName]
        • 要印出時,還得再轉換回來
    • 內建的轉換函式
      • DboTclHelper_sMakeLOGFONT
      • DboTclHelper_sMakeBitmap
      • DboTclHelper_sMakeBitMapData
      • DboTclHelper_sMakeDboValue
      • DboTclHelper_sMakeStdVector
      • DboTclHelper_sMakeInt
      • DboTclHelper_sMakeStdStr
      • DboTclHelper_sMakeCPoint
      • DboTclHelper_sMakeCString
      • DboTclHelper_sMakeDboValueType
      • DboTclHelper_sMakeCRect
      • DboTclHelper_sGetCRectTopLeft
      • DboTclHelper_sGetCPointX
      • DboTclHelper_sGetCPointY
      • DboTclHelper_sGetVectorSize
      • DboTclHelper_sGetConstCharPtr
      • DboTclHelper_sGetCRectBottomRight
      • DboTclHelper_sGetConstCharPtrFromVector
    • source {xxx.tcl}
      • 執行 tcl script
    • set lSelObjs [GetSelectedObjects]
      • 得到選取的物件
    • RegisterAction <Label> <Enabler> <Accel> <Callback> <ViewType>
      • 註冊指令至右鍵 more
      • <Label>
        • 顯示的名字
      • <Enabler>
        • Enable 的條件
      • <Accel>
        • 快捷鍵
      • <Callback>
        • 執行的 function
      • <ViewType>
        • 指定可作用的 View,例: Schematic, PM, Empty; Value
      RegisterAction "Context-Aware Rotate" "::capGUIUtils::capCARotateEnabler" "Ctrl+R" "::capGUIUtils::capCARotate" "Schematic
    • 得到 Parts 的 attributes
      1. # get the name
      2. set lName [DboTclHelper_sMakeCString]
      3. $lInst GetName $lName
      4. # get the location point
      5. set lLocation [$lInst GetLocation $lStatus]
      6. # get the location x
      7. set lStartx [DboTclHelper_sGetCPointX $lLocation]
      8. # get the location y
      9. set lStarty [DboTclHelper_sGetCPointY $lLocation]
      10. # get the source library name
      11. set lLibName [DboTclHelper_sMakeCString]
      12. $lInst GetSourceLibName $lLibName
      13. # get the device designator
      14. set lDeviceDesignator [DboTclHelper_sMakeCString]
      15. $lInst GetReferenceDesignator $lDeviceDesignator
      16. # get the rotation
      17. set lRot [$lInst GetRotation $lStatus]
      18. #get the contents lib name
      19. set lContentsLibName [DboTclHelper_sMakeCString]
      20. $lInst GetContentsLibName $lContentsLibName
      21. # get the contents view name
      22. set lContentsViewName [DboTclHelper_sMakeCString]
      23. $lInst GetContentsViewName $lContentsViewName
      24. # get the contents view type
      25. set lType [$lInst GetContentsViewType $lStatus]
      26. # get the primitive type
      27. set lPrimitiveType [$lInst GetIsPrimitiveProp $lStatus]
      28. # get the part value
      29. set lValue [DboTclHelper_sMakeCString]
      30. $lInst GetPartValue $lValue
      31. # get the reference
      32. set lReferenceName [DboTclHelper_sMakeCString]
      33. $lInst GetReference $lReferenceName
      34. # get the bounding box on the page
      35. set lBBox [$lInst GetOffsetBoundingBox $lStatus]
      36. # get the top-left of the bbox
      37. set lTopLeft [DboTclHelper_sGetCRectTopLeft $lBBox]
      38. # get the bottom-right of the bbox
      39. set lBottomRight [DboTclHelper_sGetCRectBottomRight $lBBox]
      40. # get the x1
      41. set lStartx [DboTclHelper_sGetCPointX $lTopLeft]
      42. # get the y1
      43. set lStarty [DboTclHelper_sGetCPointY $lTopLeft]
      44. # get the x2
      45. set lEndx [DboTclHelper_sGetCPointX $lBottomRight]
      46. # get the y2
      47. set lEndy [DboTclHelper_sGetCPointY $lBottomRight]
    • 得到 wire attributes
      1. # get the name
      2. set lName [DboTclHelper_sMakeCString]
      3. $ lWire GetName $lName
      4.  
      5. # get the net name
      6. set lNetName [DboTclHelper_sMakeCString]
      7. $lWire GetNetName $lNetName
      8.  
      9. # get the start point
      10. set lStart [$lWire GetStartPoint $lStatus]
      11. set lStartx [DboTclHelper_sGetCPointX $lStart]
      12. set lStarty [DboTclHelper_sGetCPointY $lStart]
      13.  
      14. # get the end point
      15. set lEnd [$lWire GetEndPoint $lStatus]
      16. set lEndx [DboTclHelper_sGetCPointX $lEnd]
      17. set lEndy [DboTclHelper_sGetCPointY $lEnd]
      18.  
      19. # get the color
      20. set lColor [$lWire GetColor $lStatus]
      21.  
      22. # get the net
      23. set lNet [$lWire GetNet $lStatus]
    • 其他範例可參考官方文件的 3.2.2~3.2.28.6

程式碼

Custom_Launch.tcl
放到右鍵執行
  1. # 放到 C:\Cadence\SPB_16.6\tools\capture\tclscripts\capAutoLoad
  2.  
  3. package require Tcl 8.4
  4. package require DboTclWriteBasic 16.3.0
  5. package provide capGUIUtils 1.0
  6.  
  7. set root {D:\Sun\Work\Software\MyCode\Tcl\Orcad}
  8.  
  9. source [file join $root replaceGlobalPower.tcl]
  10. source [file join $root AddNetsToParts.tcl]
  11. source [file join $root showProperty.tcl]
  12. source [file join $root controlDBC.tcl]
showProperty.tcl
顯示所有的 Property
  1. # source {D:\Sun\Work\Software\MyCode\Tcl\Orcad\showProperty.tcl}
  2. package require Tcl 8.4
  3. package require DboTclWriteBasic 16.3.0
  4.  
  5. namespace eval ::capGUIUtils {
  6. RegisterAction "ShowProperty" "::capGUIUtils::capShowPropertyEnabler" "" "::capGUIUtils::capShowProperty" "Schematic"
  7. }
  8.  
  9. proc ::capGUIUtils::capShowPropertyEnabler {} {
  10. set lEnableAdd 0
  11. # Get the selected objects
  12. set lSelObjs [GetSelectedObjects]
  13.  
  14. # Enable only for single object selection
  15. if { [llength $lSelObjs] == 1 } {
  16. # Enable only if a part or a hierarchical block is selected
  17. set lObj [lindex $lSelObjs 0]
  18. set lObjType [DboBaseObject_GetObjectType $lObj]
  19. set lEnableAdd 1
  20. }
  21. return $lEnableAdd
  22. }
  23.  
  24. proc ::capGUIUtils::capShowProperty {} {
  25. set lStatus [DboState]
  26. set lNullObj NULL
  27. set lSelObjs [GetSelectedObjects]
  28. set lInst [lindex $lSelObjs 0]
  29. ::capGUIUtils::showUserPropsIter $lInst
  30. ::capGUIUtils::showDisplayProps $lInst
  31. ::capGUIUtils::showEffectiveProps $lInst
  32. }
  33.  
  34. proc ::capGUIUtils::showUserPropsIter {lObject} {
  35. set lStatus [DboState]
  36. set lPropsIter [$lObject NewUserPropsIter $lStatus]
  37.  
  38. set lNullObj NULL
  39.  
  40. #get the first user property on the object
  41. set lUProp [$lPropsIter NextUserProp $lStatus]
  42.  
  43. while {$lUProp != $lNullObj } {
  44.  
  45. #placeholder: do your processing on $lUProp
  46. set lName [DboTclHelper_sMakeCString]
  47.  
  48. set lValue [DboTclHelper_sMakeCString]
  49.  
  50. $lUProp GetName $lName
  51. $lUProp GetStringValue $lValue
  52. puts "[DboTclHelper_sGetConstCharPtr $lName]: [DboTclHelper_sGetConstCharPtr $lValue]"
  53.  
  54.  
  55. #get the next user property on the object
  56. set lUProp [$lPropsIter NextUserProp $lStatus]
  57.  
  58. }
  59.  
  60. delete_DboUserPropsIter $lPropsIter
  61. }
  62.  
  63. proc ::capGUIUtils::showDisplayProps {lObject} {
  64. set lStatus [DboState]
  65. set lPropsIter [$lObject NewDisplayPropsIter $lStatus]
  66.  
  67. set lNullObj NULL
  68.  
  69. #get the first display property on the object
  70. set lDProp [$lPropsIter NextProp $lStatus]
  71.  
  72. while {$lDProp != $lNullObj } {
  73.  
  74. #placeholder: do your processing on $lDProp
  75.  
  76. #get the name
  77. set lName [DboTclHelper_sMakeCString]
  78. $lDProp GetName $lName
  79.  
  80. #get the location
  81. set lLocation [$lDProp GetLocation $lStatus]
  82.  
  83. #get the rotation
  84. set lRot [$lDProp GetRotation $lStatus]
  85.  
  86. #get the font
  87. set lFont [DboTclHelper_sMakeLOGFONT]
  88. set lStatus [$lDProp GetFont $::DboLib_DEFAULT_FONT_PROPERTY $lFont]
  89.  
  90. #get the color
  91. set lColor [$lDProp GetColor $lStatus]
  92. puts "lName:[DboTclHelper_sGetConstCharPtr $lName], lLocation:([DboTclHelper_sGetCPointX $lLocation], [DboTclHelper_sGetCPointY $lLocation]), lRot:$lRot, lFont:$lFont, lColor:$lColor"
  93.  
  94. #get the next display property on the object
  95. set lDProp [$lPropsIter NextProp $lStatus]
  96.  
  97. }
  98.  
  99. delete_DboDisplayPropsIter $lPropsIter
  100. }
  101.  
  102. proc ::capGUIUtils::showEffectiveProps {lObject} {
  103. set lStatus [DboState]
  104. set lPropsIter [$lObject NewEffectivePropsIter $lStatus]
  105.  
  106. set lNullObj NULL
  107.  
  108. #create the input/output parameters
  109. set lPrpName [DboTclHelper_sMakeCString]
  110. set lPrpValue [DboTclHelper_sMakeCString]
  111. set lPrpType [DboTclHelper_sMakeDboValueType]
  112. set lEditable [DboTclHelper_sMakeInt]
  113.  
  114. #get the first effective property
  115. set lStatus [$lPropsIter NextEffectiveProp $lPrpName $lPrpValue $lPrpType $lEditable]
  116.  
  117. while {[$lStatus OK] == 1} {
  118.  
  119. #placeholder: do your processing for $lPrpName $lPrpValue $lPrpType $lEditable
  120. puts "lPrpName:[DboTclHelper_sGetConstCharPtr $lPrpName], lPrpValue:[DboTclHelper_sGetConstCharPtr $lPrpValue], lPrpType:$lPrpType, lEditable:$lEditable"
  121.  
  122. #get the next effective property
  123. set lStatus [$lPropsIter NextEffectiveProp $lPrpName $lPrpValue $lPrpType $lEditable]
  124.  
  125. }
  126.  
  127. delete_DboEffectivePropsIter $lPropsIter
  128. }
replaceGlobalPower.tcl
取代 Global Power 改為命名的線
  1. # source {D:\Sun\Work\Software\MyCode\Tcl\Orcad\replaceGlobalPower.tcl}
  2. package require Tcl 8.4
  3. package require DboTclWriteBasic 16.3.0
  4. # package provide capGUIUtils 1.0
  5.  
  6. namespace eval ::capGUIUtils {
  7. # namespace export capRemoveSelectedGlobalsEnabler
  8. # namespace export capRemoveSelectedGlobals
  9. # namespace export capRemoveAllGlobals
  10.  
  11. RegisterAction "Remove Selected Globals" "::capGUIUtils::capRemoveSelectedGlobalsEnabler" "" "::capGUIUtils::capRemoveSelectedGlobals" "Schematic"
  12. RegisterAction "Remove All Globals" "return 1" "" "::capGUIUtils::capRemoveAllGlobals" "Schematic"
  13. }
  14.  
  15. proc ::capGUIUtils::capRemoveSelectedGlobalsEnabler {} {
  16. set lEnableDS 0
  17. # Get the selected objects
  18. set lSelObjs [GetSelectedObjects]
  19.  
  20. # Enable only for single object selection
  21. foreach lSelObj $lSelObjs {
  22. set lObjType [DboBaseObject_GetObjectType $lSelObj]
  23. puts "objType: $lObjType"
  24. if { $lObjType == 37} {
  25. return 1
  26. }
  27. }
  28. return $lEnableDS
  29. }
  30.  
  31. proc ::capGUIUtils::capRemoveAllGlobals {} {
  32. set lStatus [DboState]
  33. set lNullObj NULL
  34. set lSession $::DboSession_s_pDboSession
  35. DboSession -this $lSession
  36. # set lDesignsIter [$lSession NewDesignsIter $lStatus]
  37. # get the first design
  38. # set lDesign [$lDesignsIter NextDesign $lStatus]
  39. # delete_DboSessionDesignsIter $lDesignsIter
  40. set lDesign [$lSession GetActiveDesign]
  41.  
  42. set lSchematicIter [$lDesign NewViewsIter $lStatus $::IterDefs_SCHEMATICS]
  43. #get the first schematic view
  44. set lView [$lSchematicIter NextView $lStatus]
  45. while {$lView != $lNullObj} {
  46. #dynamic cast from DboView to DboSchematic
  47. set lSchematic [DboViewToDboSchematic $lView]
  48. set lSchematicName [_getName $lSchematic]
  49. #placeholder: do your processing on $lSchematic
  50. set lPagesIter [$lSchematic NewPagesIter $lStatus]
  51. #get the first page
  52. set lPage [$lPagesIter NextPage $lStatus]
  53. while {$lPage != $lNullObj} {
  54. #placeholder: do your processing on $lPage
  55. set lPageName [_getName $lPage]
  56. OPage $lSchematicName $lPageName
  57. ::capGUIUtils::IterAllGlobal $lPage
  58. #get the next page
  59. set lPage [$lPagesIter NextPage $lStatus]
  60. }
  61. delete_DboSchematicPagesIter $lPagesIter
  62. #get the next schematic view
  63. set lView [$lSchematicIter NextView $lStatus]
  64. }
  65. delete_DboLibViewsIter $lSchematicIter
  66. }
  67.  
  68. proc ::capGUIUtils::replaceNowPageAll {} {
  69. if { [IsSchematicViewActive] == 1 } {
  70. set lPage [GetActivePage]
  71. ::capGUIUtils::IterAllGlobal $lPage
  72. } else {
  73. capDisplayMessageBox "No schematic view active" "warning"
  74. }
  75. }
  76.  
  77. proc ::capGUIUtils::IterAllGlobal {lPage} {
  78. set lStatus [DboState]
  79. set lNullObj NULL
  80. #placeholder: do your processing on $lPage
  81. set lGlobalsIter [$lPage NewGlobalsIter $lStatus]
  82. #get the first global
  83. set lGlobal [$lGlobalsIter NextGlobal $lStatus]
  84. while { $lGlobal != $lNullObj } {
  85. #placeholder: do your processing on $lGlobal
  86. ::capGUIUtils::replacePowerToNetName $lGlobal
  87.  
  88. #get the next global
  89. set lGlobal [$lGlobalsIter NextGlobal $lStatus]
  90. }
  91. delete_DboPageGlobalsIter $lGlobalsIter
  92. }
  93. proc ::capGUIUtils::capRemoveSelectedGlobals {} {
  94. set lSelObjs [GetSelectedObjects]
  95. foreach lSelObj $lSelObjs {
  96. set lObjType [DboBaseObject_GetObjectType $lSelObj]
  97. # puts $lObjType
  98. if { $lObjType == 37} {
  99. ::capGUIUtils::replacePowerToNetName $lSelObj
  100. }
  101. }
  102. }
  103.  
  104. proc ::capGUIUtils::replacePowerToNetName {lGlobal} {
  105. set ClSymbolName [DboTclHelper_sMakeCString]
  106. $lGlobal GetSourceSymbolName $ClSymbolName
  107. set lSymbolName [DboTclHelper_sGetConstCharPtr $ClSymbolName]
  108. puts "\nSymbolName: $lSymbolName"
  109. # 得到名字
  110. set lGlobalName [DboTclHelper_sMakeCString]
  111. $lGlobal GetName $lGlobalName
  112. set lWireName [DboTclHelper_sGetConstCharPtr $lGlobalName]
  113. puts "WireName: $lWireName"
  114. if { [regexp {GND} $lWireName] } {
  115. return
  116. }
  117. # 得到座標
  118. set lStatus [DboState]
  119. set lLocation [$lGlobal GetLocation $lStatus]
  120. set lStartX [expr [DboTclHelper_sGetCPointX $lLocation]/100.0]
  121. set lStartY [expr [DboTclHelper_sGetCPointY $lLocation]/100.0]
  122. puts "Start: $lStartX , $lStartY"
  123. # 得到端點座標
  124. set lHotSpotPoint [$lGlobal GetOffsetHotSpot $lStatus]
  125. set lHotSpotPointX [expr [DboTclHelper_sGetCPointX $lHotSpotPoint]/100.0]
  126. set lHotSpotPointY [expr [DboTclHelper_sGetCPointY $lHotSpotPoint]/100.0]
  127. puts "HotSpotPointY: $lHotSpotPointX , $lHotSpotPointY"
  128. # 得到中心座標
  129. set center [::capGUIUtils::_getCenter $lGlobal]
  130. set centerX [expr [DboTclHelper_sGetCPointX $center]/100.0]
  131. set centerY [expr [DboTclHelper_sGetCPointY $center]/100.0]
  132. puts "center: $centerX , $centerY"
  133. # 得到旋轉方向
  134. set rotattion [$lGlobal GetRotation $lStatus]
  135. # 命名線並畫線
  136. switch $rotattion {
  137. 0 { # 上
  138. set wireX [expr $lHotSpotPointX]
  139. set wireY [expr $lHotSpotPointY]
  140. PlaceWire $lHotSpotPointX $lHotSpotPointY [expr $lHotSpotPointX+0.01] [expr $lHotSpotPointY+0]
  141. }
  142. 1 { # 左
  143. set wireX [expr $lHotSpotPointX]
  144. set wireY [expr $lHotSpotPointY]
  145. PlaceWire $lHotSpotPointX $lHotSpotPointY [expr $lHotSpotPointX+0] [expr $lHotSpotPointY-0.01]
  146. }
  147. 2 { # 下
  148. set wireX [expr $lHotSpotPointX]
  149. set wireY [expr $lHotSpotPointY]
  150. PlaceWire $lHotSpotPointX $lHotSpotPointY [expr $lHotSpotPointX+0.01] [expr $lHotSpotPointY+0]
  151. }
  152. 3 { # 右
  153. set wireX [expr $lHotSpotPointX]
  154. set wireY [expr $lHotSpotPointY]
  155. PlaceWire $lHotSpotPointX $lHotSpotPointY [expr $lHotSpotPointX+0] [expr $lHotSpotPointY-0.01]
  156. }
  157. default {
  158. puts "No define $rotattion"
  159. }
  160. }
  161. puts "wire: $wireX , $wireY"
  162. # 刪除 Global
  163. UnSelectAll
  164. SelectObject [expr $centerX] [expr $centerY] True
  165. Delete
  166. PlaceNetAlias $wireX $wireY $lWireName
  167. }
  168.  
  169. proc ::capGUIUtils::_getName {obj} {
  170. set lname [DboTclHelper_sMakeCString]
  171. $obj GetName $lname
  172. return [DboTclHelper_sGetConstCharPtr $lname]
  173. }
  174.  
  175. proc ::capGUIUtils::_getCenter {obj} {
  176. set lStatus [DboState]
  177. # set lBBox [$obj GetBoundingBox]
  178. # set left [DboTclHelper_sGetCPointX [DboTclHelper_sGetCRectTopLeft $lBBox]]
  179. # set top [DboTclHelper_sGetCPointY [DboTclHelper_sGetCRectTopLeft $lBBox]]
  180. # set right [DboTclHelper_sGetCPointX [DboTclHelper_sGetCRectBottomRight $lBBox]]
  181. # set Bottom [DboTclHelper_sGetCPointY [DboTclHelper_sGetCRectBottomRight $lBBox]]
  182. # 得到端點座標
  183. set lHotSpotPoint [$obj GetOffsetHotSpot $lStatus]
  184. set lHotSpotPointX [DboTclHelper_sGetCPointX $lHotSpotPoint]
  185. set lHotSpotPointY [DboTclHelper_sGetCPointY $lHotSpotPoint]
  186. # 加入 offset
  187. switch [$obj GetRotation $lStatus] {
  188. 0 { # 上
  189. set offsetX 0
  190. set offsetY -5
  191. }
  192. 1 { # 左
  193. set offsetX -5
  194. set offsetY 0
  195. }
  196. 2 { # 下
  197. set offsetX 0
  198. set offsetY 5
  199. }
  200. 3 { # 右
  201. set offsetX 5
  202. set offsetY 0
  203. }
  204. default {
  205. set offsetX 0
  206. set offsetY 0
  207. }
  208. }
  209. set centerX [expr $lHotSpotPointX + $offsetX]
  210. set centerY [expr $lHotSpotPointY + $offsetY]
  211. set center [DboTclHelper_sMakeCPoint $centerX $centerY]
  212. return $center
  213. }
AddNetsToParts.tcl
將 Parts 的 Pin 畫上線
  1. # source {D:\Sun\Work\Software\MyCode\Tcl\Orcad\AddNetsToParts.tcl}
  2. package require Tcl 8.4
  3. package require DboTclWriteBasic 16.3.0
  4. # package provide capGUIUtils 1.0
  5.  
  6. namespace eval ::capGUIUtils {
  7. # namespace export capAddNetsToPartEnabler
  8. # namespace export capAddNetsToPart
  9.  
  10. RegisterAction "Add Nets To Part" "::capGUIUtils::capAddNetsToPartEnabler" "" "::capGUIUtils::capAddNetsToPart" "Schematic"
  11. }
  12.  
  13. proc ::capGUIUtils::capAddNetsToPartEnabler {} {
  14. set lEnableAdd 0
  15. # Get the selected objects
  16. set lSelObjs [GetSelectedObjects]
  17.  
  18. # Enable only for single object selection
  19. if { [llength $lSelObjs] == 1 } {
  20. # Enable only if a part or a hierarchical block is selected
  21. set lObj [lindex $lSelObjs 0]
  22. set lObjType [DboBaseObject_GetObjectType $lObj]
  23. puts "objType: $lObjType"
  24. if { $lObjType == 13} {
  25. set lEnableAdd 1
  26. }
  27. }
  28. return $lEnableAdd
  29. }
  30.  
  31. proc ::capGUIUtils::capAddNetsToPart {} {
  32. set lPage [GetActivePage]
  33. set lUnits [$lPage GetIsMetric]
  34. if { $lUnits } {
  35. capDisplayMessageBox "請將 Page Units 改為 inch" "Error"
  36. return
  37. }
  38. set lStatus [DboState]
  39. set lNullObj NULL
  40. set lSelObjs [GetSelectedObjects]
  41. set lInst [lindex $lSelObjs 0]
  42. set lIter [$lInst NewPinsIter $lStatus]
  43.  
  44. #get the first pin of the part
  45. set lPin [$lIter NextPin $lStatus]
  46.  
  47. while {$lPin != $lNullObj } {
  48. #placeholder: do your processing on $lPin
  49. ::capGUIUtils::capAddNetToPin $lPin
  50.  
  51. #get the next pin of the part
  52. set lPin [$lIter NextPin $lStatus]
  53. }
  54. delete_DboPartInstPinsIter $lIter
  55. }
  56.  
  57. proc ::capGUIUtils::capAddNetToPin {lPin} {
  58. set lStatus [DboState]
  59. set lNullObj NULL
  60. set lWireLength 0.5
  61. # 跳過已畫線
  62. set lWire [$lPin GetWire $lStatus]
  63. puts "lWire:$lWire"
  64. if {$lWire != $lNullObj} {
  65. return
  66. }
  67. # 得到 Pin Name
  68. set lPinName [DboTclHelper_sMakeCString]
  69. $lPin GetPinName $lPinName
  70. set lPinName [DboTclHelper_sGetConstCharPtr $lPinName]
  71. puts "lPinName: $lPinName"
  72. # 得到起始座標
  73. set lStatus [DboState]
  74. set lStartPoint [$lPin GetOffsetStartPoint $lStatus]
  75. set lStartPointX [expr [DboTclHelper_sGetCPointX $lStartPoint]/100.0]
  76. set lStartPointY [expr [DboTclHelper_sGetCPointY $lStartPoint]/100.0]
  77. puts "Start: $lStartPointX , $lStartPointY"
  78. # 得到端點座標
  79. set lHotSpotPoint [$lPin GetOffsetHotSpot $lStatus]
  80. set lHotSpotPointX [expr [DboTclHelper_sGetCPointX $lHotSpotPoint]/100.0]
  81. set lHotSpotPointY [expr [DboTclHelper_sGetCPointY $lHotSpotPoint]/100.0]
  82. puts "HotSpotPointY: $lHotSpotPointX , $lHotSpotPointY"
  83.  
  84. # 畫線方向
  85. set offsetX 0
  86. set offsetY 0
  87. if {$lHotSpotPointX > $lStartPointX} {
  88. set offsetX $lWireLength
  89. } elseif {$lHotSpotPointX < $lStartPointX} {
  90. set offsetX [expr -$lWireLength]
  91. }
  92. if {$lHotSpotPointY > $lStartPointY} {
  93. set offsetY $lWireLength
  94. } elseif {$lHotSpotPointY < $lStartPointY} {
  95. set offsetY [expr -$lWireLength]
  96. }
  97. puts "offset: $offsetX , $offsetY"
  98. PlaceWire $lHotSpotPointX $lHotSpotPointY [expr $lHotSpotPointX+$offsetX] [expr $lHotSpotPointY+$offsetY]
  99. PlaceNetAlias [expr $lHotSpotPointX+$offsetX/2] [expr $lHotSpotPointY+$offsetY/2] $lPinName
  100. if {$offsetY != 0} {
  101. set lWire [$lPin GetWire $lStatus]
  102. set lAliasIter [$lWire NewAliasesIter $lStatus]
  103. #get the first alias of wire
  104. set lAlias [$lAliasIter NextAlias $lStatus]
  105. $lAlias SetRotation 3
  106. delete_DboWireAliasesIter $lAliasIter
  107. }
  108. }
controlDBC.tcl
控制 Database
  1. # source {D:\Sun\Work\Software\MyCode\Tcl\Orcad\controlDBC.tcl}
  2.  
  3. # 顯示 DBC 路徑
  4. proc showDBCName {} {
  5. set lCfg [OrCISGetDbcConfig]
  6. set lString [::CPMgtCfg_GetIniDBCName $lCfg]
  7. puts [DboTclHelper_sGetConstCharPtr $lString]
  8. }
  9.  
  10. # 進資料庫選擇元件,並擺放位置
  11. proc placePartsInDB {value x y} {
  12. MenuCommand "14567"
  13. # "0402/0R*"
  14. CISAddSearchQuery VALUE = $value
  15. CISExecuteQuery
  16. CISExplorerSelectOption 1 1 0
  17. CISExplorerSelectOption 1 1 1
  18. capMoveMouseAndClick $x $y
  19. EndPlace()
  20. }
  21.  
  22. #選擇指定值的零件
  23. proc selectRefbyValue {lregValue} {
  24. set lSession $::DboSession_s_pDboSession
  25. DboSession -this $lSession
  26.  
  27. set lStatus [DboState]
  28. set lNullObj NULL
  29.  
  30. set lDesignsIter [$lSession NewDesignsIter $lStatus]
  31. # get the first design
  32. set lDesign [$lDesignsIter NextDesign $lStatus]
  33.  
  34. while {$lDesign != $lNullObj} {
  35. # placeholder: do your processing on $lDesign
  36. set lSchematicIter [$lDesign NewViewsIter $lStatus $::IterDefs_SCHEMATICS]
  37. #get the first schematic view
  38. set lView [$lSchematicIter NextView $lStatus]
  39. while {$lView != $lNullObj} {
  40. #dynamic cast from DboView to DboSchematic
  41. set lSchematic [DboViewToDboSchematic $lView]
  42. #placeholder: do your processing on $lSchematic
  43. set lPagesIter [$lSchematic NewPagesIter $lStatus]
  44. #get the first page
  45. set lPage [$lPagesIter NextPage $lStatus]
  46. set lNullObj NULL
  47. while {$lPage != $lNullObj} {
  48. #placeholder: do your processing on $lPage
  49. set lPartInstsIter [$lPage NewPartInstsIter $lStatus]
  50. #get the first part inst
  51. set lInst [$lPartInstsIter NextPartInst $lStatus]
  52. while { $lInst != $lNullObj } {
  53. set lRef [DboTclHelper_sMakeCString]
  54. $lInst GetReference $lRef
  55. set lRef [DboTclHelper_sGetConstCharPtr $lRef]
  56. set lValue [DboTclHelper_sMakeCString]
  57. $lInst GetPartValue $lValue
  58. set lValue [DboTclHelper_sGetConstCharPtr $lValue]
  59. puts "$lRef: $lValue"
  60. if { [regexp $lregValue $lValue] } {
  61. selectRefInDBC $lRef
  62. }
  63.  
  64. set lInst [$lPartInstsIter NextPartInst $lStatus]
  65. }
  66. delete_DboPagePartInstsIter $lPartInstsIter
  67. #get the next page
  68. set lPage [$lPagesIter NextPage $lStatus]
  69. }
  70. delete_DboSchematicPagesIter $lPagesIter
  71.  
  72. #get the next schematic view
  73. set lView [$lSchematicIter NextView $lStatus]
  74. }
  75. delete_DboLibViewsIter $lSchematicIter
  76.  
  77.  
  78. # get the next design
  79. set lDesign [$lDesignsIter NextDesign $lStatus]
  80. }
  81. delete_DboSessionDesignsIter $lDesignsIter
  82. }
  83.  
  84.  
  85. proc selectRefInDBC {lRef} {
  86. # ui::PMActivate "c:/users/chihchieh.sun/desktop/test/tt.opj"
  87. # Menu "Tools::Part Manager::Open"
  88. # set lPM [GetPartManagerView]
  89. SelectGroup Groups Common $lRef
  90. }
  91.  
  92. proc linkDB {} {
  93. LinkDataBasePart
  94. CISExplorerSelectOption 1 1 0
  95. CISExplorerSelectOption 1 1 1
  96. }
  97.  
  98. proc deleteSelect {} {
  99. MenuCommand "33014" | MessageBox "YES" "INFO(ORCIS-6327): Are you sure"
  100. }

參考

Tcl/Tk 教學文件
Welcome to the Tclers Wiki!

留言