Skip to main content

OrCAD X Tcl Scripts: Automate to Accelerate Turnarounds

View of Command Window on launch

Users can write OrCAD X Tcl scripts in the Command Window for OrCAD X Capture and OrCAD X Presto PCB Editor.

Key Takeaways

  • OrCAD X Tcl scripts improve design turnaround times by automating routine tasks.
  • Tcl interfaces natively with C and has many syntactical similarities. Objects automatically convert to strings in Tcl, though users can force type conversions.
  • Users can look up database classes and subclass inheritance adds additional options to scripting.

Tcl/Tk scripting is a powerful tool that extends OrCAD X functionality with automated scripts. To state the obvious, all GUIs utilize back-end program calls and responses; Tcl/Tk scripting is just the explicit implementation. The advantage of Tcl/Tk scripts is that users can, with practice, eliminate some of the more routine aspects of capture and layout with robust database classes and functions. As with any language, OrCAD X Tcl scripts may be initially overwhelming for those with little programming experience, but they offer unparalleled speed and precision for users looking to take their ECAD design to the next level.

Navbar location of Command Window toggle

Toggling the Command Window option shows/hides the Command Window within the Design Canvas.

OrCAD X Tcl Scripts: General Syntax

In OrCAD X Capture and OrCAD X Presto PCB Editor, users can write and run automation scripts through the Command Window, greatly reducing the time spent on manual, repeatable tasks. Additionally, Tcl/Tk scripts are highly customizable, allowing users to configure script needs to their specific project and organization’s goals. Tcl/Tk script functionality falls into one of three general categories:

  • Standard Tcl commands carved out by the language library.
  • User action Tcl commands to automate manual inputs in the design environment.
  • Database Tcl commands for file storage and operations.

Cadence extends the general Tcl/Tk script options with additional OrCAD X functionality specific to the platform, giving users even greater flexibility in extending the language. 

Writing scripts for Tcl/Tk focuses on commands. Commands encapsulate the whole of Tcl/Tk functionality and have three essential characteristics:

  • Space-separated
  • Newline or “;” terminated
  • Value returning

When put between brackets (e.g., command1[command2]), commands also operate as arguments using the return value of the nested command.

  • Set stores a variable value (e.g., “set x 20”). A “$” before the variable returns this value during a function call.
  • Puts prints a stored value to the screen.
  • Command calls and function variables operate as expected within “ “ (quotation marks); however, the same is not true for { } (curly brackets). Both quotation marks and curly braces can print simple strings.
  • If, for, while, and switch control constructs allow users to manage large code blocks more succinctly.
  • Since all objects in Tcl/Tk are strings, users can use lists for more complex data structures. After generating a list, users can return index positions and elements using “lindex” and “llength”.
  • Procedures are user-defined commands. A procedure consists of three arguments (in order):
    • The procedure name.
    • List of parameters/arguments.
    • The body of the procedure.

Note that users can override Tcl/Tk built-in commands with procedure customization. This is a powerful option; users should exercise caution when implementing it.

Function Prototypes, Inheritance, and Type Conversion

Users looking for a particular command can scope the complete database commands list; for in-program lookup, users can type “info commands *<command substring>*” where the command substring is either the database class type (e.g., DboLib) or the function (e.g, _GetName). OrCAD X will return a list of all database class types that contain the _GetName function when entering “info commands *_GetName*” into the command window. Entering a database command into the command window will return an error message without the appropriate arguments; for _GetName, the function takes (in order) two arguments of the object and the return name. When writing Tcl/Tk scripts, users can call functions in two distinct manners.

Calling the Same Function in Tcl/Tk

Static function (object as input)

Class object function

Prototype

command_with_name $object <parameter>

$object command_without_classname <parameters>

Example

DboLib_GetName $Lib $lName

$lLib GetName $lName

Because classes follow inheritance (i.e., the functions of a subclass include all of the functions of its superclass(es)), it’s helpful for users to know the overall database class hierarchy:

  • DbBasePrep
  • DboUserPrep
  • DboBaseObject
  • DboAlias
  • DboBusEntry
  • DboDevice
  • DboDisplayProp
  • DboFlatNet
  • DboGraphicInstance
  • DboCustomItemInstance
  • DboGraphicArcInst
  • DboGraphicBezierInst
  • DboGraphicBitMapInst
  • DboGraphicBoxInst
  • DboGraphicCommentTextInst
  • DboGraphicEllipseInst
  • DboGraphicLineInst
  • DboGraphicOleEmbedInst
  • DboGraphicPolygonInst
  • DboGraphicPolylineInst
  • DboGraphicSymbolVectorInst
  • DboNetSymbolInstance
  • DboBookMark
  • DboERC
  • DboGlobal
  • DboOffPageConnector
  • DboPart
  • DboPartInst
  • DboDrawnInst
  • DboPlacedInst
  • DboPlacedInst
  • DboTitleBlock
  • DboLib
  • DboDesign
  • DboLibObject
  • DboCell
  • DboGraphicObject
  • DboSymbol
  • DboLibPart
  • DboTitleBlockSymbol
  • DboPackage
  • DboView
  • DboSchematic
  • DboNet
  • DboNetBust
  • DboNetScalar
  • DboOccurrence
  • DboInstOccurrence
  • DboNetOccurrence
  • DboOffPageConnectorOccurrence
  • DboPortOccurrence
  • DboPortBusMemberOccurence
  • DboTitleBlockOccurrence
  • DboPage
  • DboPortInst
  • DboPortInstBus
  • DboPortInstScalar
  • DboPortInstBusMember
  • DboSymbolPin
  • DboSymbolPinBus
  • DboSymbolPinScalar
  • DboVector
  • DboArc
  • DboBezier
  • DboBitMap
  • DboBox
  • DboCommentText
  • DboEllipse
  • DboFill
  • DboLine
  • DboOleEmbed
  • DboPolygon
  • DboPolyline
  • DboSymbolVector
  • DboWire
  • DboWireBus
  • DboWireScalar

However, info command calls only show commands by database class type. For example, calling “info commands DboLib_*” will only provide the explicit commands of that database class type, but since DboLib inherits from DboBaseObject, DboLib also has access to all the commands provided by “info commands DboBaseObject_*

Lastly, users may want to convert data types for manipulation outside of Tcl (note that by default, most capture commands take string parameters as CString ). Helper commands manage these data type conversions:

  • DboTclHelper_sMakeLOGFONT
  • DboTclHelper_sMakeBitMap
  • DboTclHelper_sMakeBitMapData
  • DboTclHelper_sMakeDboValue
  • DboTclHelper_sMakeStdVector
  • DboTclHelper_sMakeInt
  • DboTclHelper_sMakeStdStr
  • DboTclHelper_sMakeCPoint
  • DboTclHelper_sMakeCString
  • DboTclHelper_sMakeDboValueType
  • DboTclHelper_sMakeCRect
  • DboTclHelper_sGetRectTopLeft
  • DboTclHelper_sGetCPointX
  • DboTclHelper_sGetCPointY
  • DboTclHelper_sGetVectorSize
  • DboTclHelper_sGetConstantCharPtr
  • DboTclHelper_sGetRectBottomRight
  • DboTclHelper_sGetConstCharPtrFromVector

Cadence Solutions for Faster Design Turnaround

OrCAD X Tcl scripts are a powerful tool for users to automate rote ECAD processes so they can focus their design acumen elsewhere. Tcl scripts extend the already powerful OrCAD X platform while also granting users greater customization options for their design environment. Finally, Tcl read/write scripts make communication with standalone programs easier with native C. Looking to push your PCB design further? See how Cadence PCB Design and Analysis Software is helping designers build the next generation of cutting-edge boards.

Leading electronics providers rely on Cadence products to optimize power, space, and energy needs for a wide variety of market applications. To learn more about our innovative solutions, talk to our team of experts or subscribe to our YouTube channel.