i wrote a MS_INITAPP and then started a process of microstation and used the -WA command line parameter to start it. all that is working but the exit code i get from the process is always zero.
here is how im calling up the process Im doing this from a stand alone app...
Process P = new Process(); P.StartInfo.FileName = MSCexePath; P.StartInfo.Arguments = "\"-WK" + WorkSpaceName + "\" \"-WW" + projName + "\" -WAOHDOTAssignWorksettoSeed \"-IPATH" + DestinationPath + "\\990-WorkSetStandards\\Seed\\\""; P.Start(); P.WaitForExit(); int result = P.ExitCode;
and then my MS_INITAPP code (OHODTAssignWorksettoSeed)
protected override int Run(string[] commandLine) { try { if (commandLine.Contains("MS_INITAPPS") || commandLine.Contains("-WA")) { string passedWorkSpaceName = ""; string passedWorkSetName = ""; List<string> filesToProcess = new List<string>(); foreach (string curCLP in commandLine) {//get paramaters if (curCLP.ToUpper().StartsWith("-WK")) { passedWorkSpaceName = curCLP.Trim().Remove(0, 3); } if (curCLP.ToUpper().StartsWith("-WW")) { passedWorkSetName = curCLP.Trim().Remove(0, 3); } if (curCLP.ToUpper().StartsWith("-IPATH")) { if (Directory.Exists(curCLP.Trim().Remove(0, 6))) { string tempPath = curCLP.Trim().Remove(0, 6); filesToProcess.AddRange(Directory.GetFiles(tempPath, "*.dgn", SearchOption.AllDirectories).ToList<string>()); filesToProcess.AddRange(Directory.GetFiles(tempPath, "*.cel", SearchOption.AllDirectories).ToList<string>()); filesToProcess.AddRange(Directory.GetFiles(tempPath, "*.dgnlib", SearchOption.AllDirectories).ToList<string>()); } } if (curCLP.ToUpper().StartsWith("-IFILE")) { if (File.Exists(curCLP.Trim().Remove(0, 6)) && (curCLP.ToUpper().EndsWith(".DGN") || curCLP.ToUpper().EndsWith(".CEL") || curCLP.ToUpper().EndsWith(".DGNLIB"))) { filesToProcess.Add(curCLP.Trim().Remove(0, 6)); } } } if (filesToProcess.Count > 0) { if (passedWorkSetName != "" && passedWorkSpaceName != "") { if (Bentley.MstnPlatformNET.Internal.WorkSpaceManager.ActiveWorkSetName.ToUpper() == passedWorkSetName.ToUpper()) {//active workset/workspace match what was passed...means the desired workset was found //must set this to force the creation of the dgnws file if it does not exist Bentley.MstnPlatformNET.Internal.WorkSpaceManager.ActiveWorkSet = Bentley.MstnPlatformNET.Internal.WorkSpaceManager.ActiveWorkSet; //first get template worksetinfo BD.DgnWorkSetInfo SeedWorkSetInfo; string dgnwsFullPath = BD.ConfigurationManager.GetVariable("_USTN_WORKSETDGNWS"); BD.DgnFileOwner DGNWSfileowner; BD.DgnFile DGNWSfile = null; BD.DgnDocument DGNWSDoc = BD.DgnDocument.CreateForLocalFile(dgnwsFullPath); DGNWSfileowner = BD.DgnFile.Create(DGNWSDoc, BD.DgnFileOpenMode.ReadOnly); DGNWSfile = DGNWSfileowner.DgnFile; BD.StatusInt openstatus; DGNWSfile.LoadDgnFile(out openstatus); if (openstatus == BD.StatusInt.Success) { SeedWorkSetInfo = BD.DgnWorkSetInfo.ExtractFromDgnFile(DGNWSfile); //close file DGNWSfile.Release(); //loop files to process and assign workset int counter = 0; //now open seed dgn file and apply this worksetinfo to it foreach (string curdgn in filesToProcess) { try { BD.DgnFileOwner fileowner; BD.DgnFile curfile = null; BD.DgnDocument dgndoc = BD.DgnDocument.CreateForLocalFile(curdgn); fileowner = BD.DgnFile.Create(dgndoc, BD.DgnFileOpenMode.ReadWrite); curfile = fileowner.DgnFile; curfile.LoadDgnFile(out openstatus); if (openstatus == BD.StatusInt.Success) {//opened file SeedWorkSetInfo.Write(curfile); BD.StatusInt result = curfile.ProcessChanges(BD.DgnSaveReason.FileClose); if (result == BD.StatusInt.Success) {//saved file //close file curfile.Release(); counter = counter + 1; } else {//failed to save file //close file curfile.Release(); } } else {//failed to open file } } catch {//something went wrong processing this file..move on } } Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit(); return counter; } else {//failed to open dgnws file Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit(); return -5; } } else {//active workset name does not match what was passed..failed to find desired workset Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit(); return -4; } } else {//failed to get required command line parameters Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit(); return -3; } } else {//no files to process Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit(); return 0; } } else {//not run as MS_INITAPPS Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit(); return -2; } } catch { Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit(); return -1; } }
you can see in the code if the process failed it should return a negative number. if the process was successful it should return the number of files it successfully processed. but its always 0.
anyone else have any luck in this area?
Hi John,
FWIW. The Microsoft Process.ExitCode documentation and sample may provide some additional tests and insights to perform to help answer when and why codes other than success can successfully be obtained.
HTH,Bob
Hi,
I would guess you have to remove all the Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.Quit( ) calls because they 'kill' your process - the returns after that will be ignored. A MS_INITAPP session should terminate automatically after your Run method is done, if your addin stays invisible - AFAIK.
Regards Harmen
i thought I needed the ComApp.Quit(). but I removed them and ran again and still only returns zero But also now i know i don't need those lines any more (for invisible apps).
i know the code is working because the files get updated.
im thinking this is returning to microstation and then microstation process is ending and returning its own exitcode. Anyone from Bentley want to weight in/confirm this?
Has anyone ever gotten an exit code returned to their MS_INITAPP? in any language?? would be helpful to know.