OrCad Macros

OrCad Macros come in two flavors: Basic and TCL/TK. When a Macro is recorded, it is saved in Cypress Enable Scripting Language, which is similar to Visual Basic. When saved, these files may be edited. The other type of Macro is another scripting language — TCL/TK. These Macros can be found under the Accessories menu.

Documentation for the Cypress Enable Scripting Language may be found in your installation directory, under tools\capture, and is called enduser.doc. Documentation for TCL/TK may be found in your installation directory, under tools\capture\tclscripts, and is called OrCAD_Capture_Tcltk_Extensions.pdf.

Basic

Examples of Basic Macros may be found in your installation directory, under tools\capture\macros. However, it is unlikely they will show functions you will be interested in. I have created my own macro, which actually selects a part on the current page, and changes a property of that part:

SUB TmpMacroExample
  'MACROMENU 
  'MACROKEY 
  'MACRODESCRIPTION 
  FindParts "U2", 0
  SetProperty "Manufacturer", "Tonka"
  ShowSpreadsheet
  UnSelectAll
END SUB

Basic Macros may only be run on the current sheet. Available function declarations may be found here. Subroutine Declarations. The other method of controlling OrCad is to use SendKeys. However, this function no longer works under windows for security reasons. Also, delcaring API functions in the subroutine does not seem to work.
Place functions use relative positions. Use GotoAbsolute x, y before place functions for absolute positioning.
Do not mix variable types in For loops: For x = 1 to 10 step 0.5 will never stop. For x = 1 to 10.0 step 1.5 will also not stop!

Tcl/Tk

Tcl/Tk functions may be executed from the Command Window (View | Command Window). Also, everything that happens to control OrCad is translated into Tcl/Tk for execution. It is possible to see these commands by typing at the command prompt:

SetOptionBool Journaling TRUE
SetOptionBool DisplayCommands TRUE

You will want to set both options to FALSE when you are done.

GetSelectedObjects, IsSchematicViewActive, and GetActivePage are all useful functions. Installation of a stand-alone macro is a complex thing, so I patched in some code to the PDF Export. The PDF Export only runs if the Project Manager is active and there is one and only one design selected. I added my code where an error message is printed, to specify that the program does not run in Schematic View. Well, Schematic View is exactly where I wanted my code. Here is the snippet:

proc capPdfLaunch::checkEnviroment { } {
     if { [IsSchematicViewActive]  == 1}  {
           set lStatus [DboState]
           set lWiresIter [[GetActivePage] NewWiresIter $lStatus]
           set lWire [$lWiresIter NextWire $lStatus]
           set lNullObj NULL
           while {$lWire != $lNullObj} {
               set lRect [DboWire_GetBoundingBox $lWire]
               set lPt00 [DboTclHelper_sGetCRectTopLeft $lRect]
               set lPt11 [DboTclHelper_sGetCRectBottomRight $lRect]
               set lX00  [DboTclHelper_sGetCPointX $lPt00]
               set lX11  [DboTclHelper_sGetCPointX $lPt11]
               set lY00  [DboTclHelper_sGetCPointY $lPt00]
               set lY11  [DboTclHelper_sGetCPointY $lPt11]
               if {(abs($lX00 - $lX11) > 0 && abs($lX00 - $lX11) < 10) || (abs($lY00 - $lY11) > 0 && abs($lY00 - $lY11) < 10)} {
		        set lMessage "Tiny Wire at: $lX00, $lY00"
		        set lMessageStr [DboTclHelper_sMakeCString $lMessage]
		        DboState_WriteToSessionLog $lMessageStr
               }
               set lWire [$lWiresIter NextWire $lStatus]
           }
		set lMessage "Processed [DboPage_GetWireCount [GetActivePage] $lStatus] Wires..."
		set lMessageStr [DboTclHelper_sMakeCString $lMessage]
		DboState_WriteToSessionLog $lMessageStr
	tk_messageBox -type ok -message "The Export PDF command runs only when PM View is active and design is selected" -title "Export PDF Message"
	return 0
    }

After I call GetActivePage, I cycle through every wire on the page and check the length. Anything under 10 cannot be on grid, and I then report it. You can see that it is a complex process to go from the wire to the endpoints to the coordinates of those endpoints. The documentation did a fair job of describing these functions. However, the documentation was lax about actual arithmetic and logical functions. Tcl/Tk is a standard, and documentation on the web helps.

Complete functions (including loops) may be pasted into the Command Window. Therefore, the above code may be run that way. However, tk_messageBox may not be available without the rest of the program.

Good Luck! and Happy Coding

More 'Puter Info

The Microsoft Paint Palette, when saving to GIF is NOT the web-safe palette. Here it is, for VB6 consumption.