0

I have the following code snippet in C# to open a PowerDesigner Model and I would like to close / exit the PowerDesigner application instance but I do not know how?

PdCommon.Application pdApplication = null;
try{
  //Creating PD Application object...
  pdApplication = new PdCommon.Application();
  //Opening the relevant models of a dedicated directory
  String[] files = System.IO.Directory.GetFiles(ldmSourceDirectory);
  foreach (String curFile in files){
    if(curFile.EndsWith(".cdm")){
      pdApplication.OpenModel(@curFile, PdCommon.OpenModelFlags.omf_DontOpenView);
    }
  }
  //Doing some operations...
}finally{
  if (pdApplication != null){
    //Closing models
    foreach (PdCDM.Model curPDModel in pdApplication.Models){
      curPDModel.Close(false);
    }
    //But how can I close the application?
    pdApplication = null;
  }
}
user2722077
  • 462
  • 1
  • 8
  • 21
  • What happens in your current situation, where you don't "close" the application? Maybe you just need to close the workspace too: `pdApplication.ActiveWorkspace.Close(true)`. – pascal Jun 17 '15 at 08:34
  • The ActiveDocument has no Close method. Maybe the ActiveWorkspace has to be casted to another object class? – user2722077 Jun 17 '15 at 10:00
  • A PowerDesigner process exists still in the background in my current situtation. – user2722077 Jun 17 '15 at 13:12

1 Answers1

0

As commented by pascal, you should close the model, the workspace, and then, kill the process. Don´t forget to add PdWSP (workspace model) reference, and System.Diagnostics using declaration. The process name may be different depending on the PD version.

PdCommon.Application pd = new PdCommon.Application();
var pdm = (PdPDM.Model)pdApplication.OpenModel(fileName);
var wsp = (PdWSP.Workspace)pdApplication.ActiveWorkspace;

pdm.Close(false);
wsp.Close(true);
pd = null;

// close powerdesigner processes
foreach(var process in Process.GetProcesses().Where(pr => pr.ProcessName == "PdShell16"))
{
    process.Kill();
}
Fernando Vieira
  • 3,177
  • 29
  • 26