Reply

Reading linked files throug Revision manager fails

[ Edited ]

Dear experts,

 

I will programatically read all the occurences in an asm file using RevisionManager and wrote code like this:

 

 public void ReadLinkedDocs(string filename)
        {
            try
            {
                bool stopFile = false;
                RevisionManager.Application revApp = new RevisionManager.Application();
                revApp.DisplayAlerts = 0; //???
RevisionManager.RevisionRuleType revRuleOption =  RevisionManager.RevisionRuleType.LastSavedType; RevisionManager.Document revDoc = revApp.Open(filename, revRuleOption, stopFile); linkedDocs = (RevisionManager.LinkedDocuments)revDoc.get_LinkedDocuments(RevisionManager.LinkTypeConstants.seLinkTypeAll); int linkedDocsCount = linkedDocs.Count; string s = revDoc.FullName; foreach (var item in linkedDocs) { // do something } } catch (Exception ex) { throw ex; } finally { if (linkedDocs != null) { Marshal.ReleaseComObject(linkedDocs); linkedDocs = null; } if (refDoc != null) { Marshal.ReleaseComObject(refDoc); refDoc = null; } if (revApp != null) { revApp .Quit(); Marshal.ReleaseComObject(revApp); revApp = null; } } }

First I was wondering why the property DisplayAlerts is from type int while all the templates here are from type boolean.

 

The main concern is that after reaching the open statement programm will go back to the calling method without reaching the linkedDocs.Count statement.

 

Does anybody knows what is getting wrong?

2 REPLIES

Re: Reading linked files throug Revision manager fails

Miike,

the code is working for me. Make sure that the filename you are passing really exists. I also did NOT disable the DisplayAlerts to see, if any error message pops up when opening the file.

RevisionManager.Application revApp = null;
RevisionManager.Document revDoc = null;
RevisionManager.LinkedDocuments linkedDocs = null;
try
{
  bool stopFile = false;
  revApp = new RevisionManager.Application();
  //revApp.DisplayAlerts = 0;
  RevisionManager.RevisionRuleType revRuleOption = RevisionManager.RevisionRuleType.LastSavedType;
  revDoc = (RevisionManager.Document)revApp.Open("C:\\TEMP\\Asm1.asm", revRuleOption, stopFile);
  linkedDocs = (RevisionManager.LinkedDocuments)revDoc.get_LinkedDocuments(RevisionManager.LinkTypeConstants.seLinkTypeAll);

  int linkedDocsCount = linkedDocs.Count;
  string s = revDoc.FullName;
  foreach (RevisionManager.Document doc in linkedDocs)
  {
    // do something
    System.Diagnostics.Debug.WriteLine("Document: " + doc.FullName);
  }
}
catch (Exception ex)
{
  throw ex;
}
finally
{
  //... Release all COM objects ...
}

 

Re: Reading linked files throug Revision manager fails

Martin,

This code is running indeed.

 

The untimely return to the calling method is maybe the result of a specific characteristic (or settings?) in Visual Studio 2012.

 

Thank you for helping me out.