Skip to Content
Author's profile photo Phillip Lam

Automate PowerDesigner Using Microsoft Powershell Script — Part One

We can use programming language C#, C++ ,Visual Basic and JAVA to automate PowerDesigner. But these languages are very complicated. It may take

a professional programmer days or weeks to get job down. In addition, we have to install Microsoft Visual Studio or Eclipse as development tool, which

is not always available to everyone.

Microsoft Powershell, by contrast, is simple, powerful and available to almost all Windows users. Powershell 2.0 is already installed  on Windows 7.

Plus a lot of automation solutions are already available in Powershell community.

I’m going to separate the topic in three parts:

Part one        Create a model

Part two         Emulate mouse and keyboard to control Powerdesigner GUI

Part three      Automate Powerdesigner Portal Server login process

In this article, I’m going to work on part one.

I’m on Windows 7 64bit with PowerDesigner 16.5.4 64bit.  I have not tested 32bit PowerDesigner.

First of all, for those who are unfamiliar with Powershell, go to Internet, search for Powershell, you’ll get tons of information and tutorials.

Here we only need learn three commands:

new-object              this command allows us create a new object

add-type                we use this command to load external assembly files.

get-member           given an object, list all its member functions

Windows 7 64bit has both 32bit and 64bit Powershell installed. But by default, it runs 64bit version.
Let’s start Powershell 64bit.

Click Start button. search for Windows PowerShell . Click the Windows PowerShell tile


Click Start button. Click Run…  Type powershell.  Click OK.

Powershell window pops up.

At command prompt, type or paste the following code and hit Return

$PowerDesigner = new-object -com powerdesigner.application

Powerdesigner starts.

In command prompt, type or paste the following code and hit Return

$Powerdesigner | Get-Member

The output lists all functions $Powerdesigner COM object owned.

   TypeName: System.__ComObject#{57c91ea5-68ef-4877-bb3e-757b12ecae55}

Name                     MemberType Definition
—-                     ———- ———-
BeginTransaction         Method     void BeginTransaction ()
CancelTransaction        Method     void CancelTransaction ()
ConvertToUTF16           Method     void ConvertToUTF16 (string, string)
ConvertToUTF8            Method     void ConvertToUTF8 (string, string)
CreateModel              Method     BaseObject CreateModel (int, string, OpenModelFlags)
CreateModelFromTemplate  Method     BaseObject CreateModelFromTemplate (string, OpenModelFlags)
CreateModelWithDialog    Method     BaseObject CreateModelWithDialog (int, string, OpenModelFlags)
EndTransaction           Method     void EndTransaction ()
EvaluateNamedPath        Method     string EvaluateNamedPath (string, bool, bool)
ExecuteCommand           Method     string ExecuteCommand (string, string, CommandExecutionMode)
FileImport               Method     BaseObject FileImport (string, string, int, string, OpenModelFlags)
GetModuleForModelFile    Method     BaseObject GetModuleForModelFile (string)
IsKindOf                 Method     bool IsKindOf (int, int)
MapToNamedPath           Method     string MapToNamedPath (string)
NewGUID                  Method     string NewGUID ()
newPoint                 Method     APoint newPoint (int, int)
NewPtList                Method     PtList NewPtList ()
NewRect                  Method     ARect NewRect (int, int, int, int)
OpenModel                Method     BaseObject OpenModel (string, OpenModelFlags)
Output                   Method     void Output (string)
ProfileSnap              Method     void ProfileSnap (string, bool, int)
Progress                 Method     BaseObject Progress (string, bool)
Rtf2Ascii                Method     string Rtf2Ascii (string)
Rtf2Html                 Method     string Rtf2Html (string)
ShowHelp                 Method     void ShowHelp (int)
ActiveDiagram            Property   BaseObject ActiveDiagram () {get}
ActiveGlossary           Property   BaseObject ActiveGlossary () {get}
ActiveModel              Property   BaseObject ActiveModel () {get}
ActivePackage            Property   BaseObject ActivePackage () {get}
ActiveSelection          Property   ObjectSet ActiveSelection () {get}
ActiveWorkspace          Property   BaseObject ActiveWorkspace () {get}
CheckPermissionsMode     Property   bool CheckPermissionsMode () {get} {set}
EclipseWorkspace         Property   string EclipseWorkspace () {get}
ExternalClientAdapter    Property   IDispatch ExternalClientAdapter () {get}
HomeDirectory            Property   string HomeDirectory () {get}
InteractiveMode          Property   InteractiveModeValue InteractiveMode () {get} {set}
LicenceParameters        Property   string LicenceParameters () {get}
LicenceStatus            Property   string LicenceStatus () {get}
Locked                   Property   bool Locked () {get} {set}
MainWindowHandle         Property   LONG_PTR MainWindowHandle () {get}
MetaModel                Property   BaseObject MetaModel () {get}
Models                   Property   ObjectSet Models () {get}
PicturesTransparentColor Property   OLE_COLOR PicturesTransparentColor () {get} {set}
RegistryHome             Property   string RegistryHome () {get}
RepositoryConnection     Property   BaseObject RepositoryConnection () {get}
ScriptInputArray         Property   Variant ScriptInputArray () {get}
ScriptInputParameters    Property   string ScriptInputParameters () {get}
ScriptResult             Property   string ScriptResult () {get} {set}
ShowMode                 Property   bool ShowMode () {get} {set}
UserDataDictionary       Property   IStringDataDictionary UserDataDictionary () {get}
UserName                 Property   string UserName () {get}
ValidationMode           Property   bool ValidationMode () {get} {set}
Version                  Property   string Version () {get}
Viewer                   Property   bool Viewer () {get}

The list is very helpful. It tells user which function is available and for what purpose.

Next, in order to create a PDM we need load two Powerdesigner COM assemblies



By default, all PowerDesigner COM assemblies are located at PowerDesigner Home folder.

But you can move them to other place. In my case, I put them in D:\PD folder.
Type or paste the following code and hit Return:

add-type -path “D:\PD\Interop.PdCommon.dll”
add-type -path “D:\PD\Interop.PdPDM.dll”

The assemblies are loaded.

We want to create a PDM, which contains a table with a column.
Type or paste the code below. Don’t forget hit Return.

$model=$PowerDesigner.createmodel([PdPDM.PdPDM_Classes]::cls_Model,”|DBMS=ORACLE Version 11g”,0)
if ($model -eq $null )
  [Windows.Forms.MessageBox]::Show(“Cannot create PDM”)
  $ =”PDMexample”
  $model.code =”PDMexample”
  $tbl=$model.createobject([PdPDM.PdPDM_Classes]::cls_Table,”” , -1, $false)
  $tbl.Comment=”Customer table”
  $tbl.Description=”The customer table stores customer data”


A PDM with a table is created. It uses Oracle 11g as DBMS.

You can copy above code in notepad and save as, say CreatePDM.ps1(ps1 means Powershell script). In PowerShell prompt, go to the same folder where

CreatePDM.ps1 located, type


The program will do its job.

Attached is CreatePDM.ps1.

Enjoy coding!

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Phillip,

      I was following along and got an error at the step that adds the two PD assemblies. The error: "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded". I've only have one version of PD installed.

      I'm running PD 32bit and tried using powershell 32bit but no luck.

      Thanks for the info though.


      Author's profile photo Phillip Lam
      Phillip Lam
      Blog Post Author

      Hi Mark,

      I try 32bit with Powershell(x86) and it works for me.

      But if I run the code in Powershell(64bit), it fails with error "cannot load assembly".

      So if you run 32bit Powerdesigner, use 32bit Powershell.


      Author's profile photo Former Member
      Former Member

      Hi Philip,

      There was a problem with the 64bit interop (for Java at least). With 64 bit PD SAP delivered the 32bit interop which did not work. I have created a support call for that and have adjusted the jar file so talking to 64bit powerdesigner works for me now. I don't know if they have fixed that with the latest release.

      Best Regards,

      Marcel Schot

      Author's profile photo Former Member
      Former Member

      Was is the long .vs int argument to CoCreateInstance per chance? I'm facing that issue right now in


      Author's profile photo Former Member
      Former Member

      Yup, that is the one. The java sources for the interop were in the Jar file so I unzipped the jar, changed the definition to long at the appropriate places, rezipped it and after that the interop was functioning fine.

      That process is a bit more difficult with the DLL's i suspect....

      Author's profile photo Former Member
      Former Member

      Turns out it requires at least PowerShell 3.0 to run.

      I had the exact same error, installed the Windows Management Framework 3.0 which includes PS 3.0 and now Add-Type and the other commands work just fine:

      PS C:\> $psversiontable
      Name                           Value
      ----                           -----
      PSVersion                      3.0
      WSManStackVersion              3.0
      CLRVersion                     4.0.30319.18444
      BuildVersion                   6.2.9200.16398
      PSCompatibleVersions           {1.0, 2.0, 3.0}
      PSRemotingProtocolVersion      2.2
      Author's profile photo dirk jaeckel
      dirk jaeckel

      Nice idea, i am awaiting your  "mouse and keyboard event" emulation, that will free us from the horrible API.

      Author's profile photo Former Member
      Former Member

      Hi Philip,

      I am using Sikuli (Sikuli Script - Home) with the API via COM, Sikuli handles the mouse and keyboard and the connecting via COM helps me to interact with PowerDesigner via the API.

      Have you gotten Event handling to work from Powershell?

      Best regards,

      Marcel Schot

      Author's profile photo Phillip Lam
      Phillip Lam
      Blog Post Author

      YES. I'll publish the code soon. There are two parts in coming article:

      1) Using open source library.

      2) Develop your own code in Poweshell

      Author's profile photo José Rodríguez Luis
      José Rodríguez Luis

      Can somebody help me? Do you know how to use the file import method?

      I can not find documentation and I need to import an excel file from the command line.