Softimage SDK Programmer's Guide > Script Development > Debugging Scripts >

# Using the PyWin Debugger

The PyWin Debugger is an interactive GUI that allows you to debug scripts running in Softimage using the power of Python debugging. The module that defines it is debugger, which is built on the pdb module (the standard Python debugger).

## Debug Features

The PyWin Debugger provides the following debugging tools to help you debug your scripts:

Action | Toolbar | Menu | Hotkey
--- | --- | --- | ---
Setting and clearing breakpoints. |  | File > Debug > Toggle Breakpoint | F9
Stepping through scripts. |  | File > Debug > Step in File > Debug > Step out | F10 F11
Viewing the call stack (useful when you are debugging scripts called from within scripts). |  |  |
Setting and viewing variables. |  |  |
See what's available in a Python module (Python Object Browser) or COM typelib (COM Browser) |  | Tools > Browser Tools > COM Browser |
Convert COM libraries into static dispatch Python modules |  | Tools > COM Makepy utility |
Display output from any programs that use win32traceutil |  | Tools > Trace Collector Debugging tool |

## Invoking the PyWin Debugger

If you are using the recommended pywin32 extension for Python, the PyWin Debugger is already installed and waiting to be invoked. Because it is a Python module, you need to import it before you can use it:

    # This loads the debugger module...
    import pywin.debugger as dbg

    # This launches the GUI:
    dbg.brk()

An alternative call to the debugger is:

    dbg.set_trace()

Tip

The context menu in the Script Editor provides an option to auto-insert this snippet:

## Controlling Softimage from the Debugger

Because the PyWin Debugger interacts directly with Softimage you can control Softimage by typing commands in the Interactive Window. For example, if you type Application.LogMessage( "Debug this!" ) in the Debugger's Interactive Window and press Enter, "Debug this!" is logged to the history pane in Softimage.

## Enhancing AutoComplete

You can modify the interactive window in the PyWin debugger to have a Softimage object expose all its methods in the auto-complete prompt.

- Edit this file: %PythonPath%\Lib\site-packages\pythonwin\pywin\scintilla\view.py and add the following lines in the _AutoComplete function (use the context lines to find out where to put the code):

                # The object may be a COM object with typelib support - lets see if we can get its props.
                # (contributed by Stefan Migowsky)
                try:
                    # Get the automation attributes
                    items_dict.update(ob.__class__._prop_map_get_)
                    # See if there is an write only property
                    # could be optimized
                    items_dict.update(ob.__class__._prop_map_put_)
                    # append to the already evaluated list
                except AttributeError:
                    pass
     # BEGIN ADDED LINES
                # The object might be a pure COM dynamic dispatch with typelib support - lets see if we can get its props.
                if hasattr(ob, "_oleobj_"):
                    try:
                        for iTI in xrange(0,ob._oleobj_.GetTypeInfoCount()):
                            typeInfo = ob._oleobj_.GetTypeInfo(iTI)
                            typeAttr = typeInfo.GetTypeAttr()
                            for iFun in xrange(0,typeAttr.cFuncs):
                                funDesc = typeInfo.GetFuncDesc(iFun)
                                funName = typeInfo.GetNames(funDesc.memid)[0]
                                if not items_dict.has_key(funName):
                                    items_dict[funName] = 1
                    except:
                        pass
     # END ADDED LINES
            except:
                win32ui.SetStatusText("Error attempting to get object attributes - %s" % ('sys.exc_info()[0]',))