Automating Microsoft Visio

This example opens a Microsoft Visio document and prints the save-time and creation-time of the Visio document:

import sys, win32com.client

doc = sys.argv[1]
try:
     visio = win32com.client.Dispatch("Visio.Application")
     visio.Visible = 0
     try:
          dwg = visio.Documents.Open(doc)
          print dwg.TimeCreated, ",", dwg.TimeSaved
     except Exception, e:
          print "Error", e
     dwg.Close()
     visio.Quit()
except Exception, e:
     print "Error opening file",e

Printwatcher

This script watches for activity at the installed printers and writes a logfile. It shows how much a user has printed on wich printer (works also with network printers).

But it has a proplem with counting the right amount of printed pages 🙁

It uses the wmi-class from Tim Golden, which you can download from his webpages. Please put the wmi.py in the same directory where you run this script from.

import wmi
c = wmi.WMI ()

print_job_watcher = c.watch_for (
  notification_type="Creation",
  wmi_class="Win32_PrintJob",
  delay_secs=1
)
while 1:
  pj = print_job_watcher ()
  print "User %s has submitted %d pages to printer %s" % \
    (pj.Owner, pj.TotalPages, pj.Name)

Userdefined Commands in CATIA V5

With “startCommand” one can start userdefined commands in the same
way as you type the command in the command prompt in CATIA V5.

try:
    import win32com.client 
except:
    print "Oops PYwin32 from Marc Hammond needed" 
catapp = win32com.client.Dispatch("CATIA.application") 
#Attention: runs only if you have set TOOLS/CUSTOMIZE/OPTIONS to Englisch. 
catapp.StartCommand("Open") 
#Starts the "File open"-Menu 
#other examples: 
#catapp.StartCommand("What's This?") 
# Runs the Online-Help (Strg+F1)
#catapp.StartCommand("CompassDisplayOff") 
# Compass visible 
#catapp.StartCommand("CompassDisplayOn") 
# Compass invisible