RevisionManager: updating the link between a part and an assembly

 

Hi there

 

I'm having trouble getting the following VB.NET code to work, the purpose of which is to update an assembly to point to a different location for a given part.  The equivalent VB6 code appears to work without problem.  Any ideas?

 

 

 

PrivateSub ReplacePart()

    Dim revisionManager AsNew RevisionManager.Application

    Dim revisionDocument As RevisionManager.Document = Nothing

    Dim linkedDocument As Document = Nothing

     Try

        revisionDocument = revisionManager.Open("d:\new\Assembly001.asm")

 

        ForEach linkedDocument In revisionDocument.LinkedDocuments

            If linkedDocument.FullName = "D:\old\Part001.par"Then

                 linkedDocument.Replace("D:\new\Part001.par", )

            EndIf

        Next

    Finally

        IfNot linkedDocument IsNothingThen Marshal.ReleaseComObject(linkedDocument)

        IfNot revisionDocument IsNothingThen Marshal.ReleaseComObject(revisionDocument)

        IfNot revisionManager IsNothingThen Marshal.ReleaseComObject(revisionManager)

    EndTry

EndSub

 

Posted by: Stuart Davies
Post date: 10/31/2007 2:00:41 AM

7 REPLIES

RE: RevisionManager: updating the link between a part and an assembly

Stuart,

 

You have not given any details about what kind of problem you're having. I have code in C# that does the exact same thing and it works fine.

 

Posted by: Jason Newell
Post date: 11/1/2007 7:25:22 AM

RE: RevisionManager: updating the link between a part and an assembly

Yep, I should have qualified the symptom, which is essentially that the code snippet appears to execute successfully, but doesn't actually update the link i.e. the link to the file in the "old" directory remains.

 

Posted by: Stuart Davies
Post date: 11/1/2007 8:52:25 AM

RE: RevisionManager: updating the link between a part and an assembly

Makes sense now .

 

How about:

 

revisionDocument.SaveAllLinks()

 

Posted by: Jason Newell
Post date: 11/1/2007 8:58:15 AM

RE: RevisionManager: updating the link between a part and an assembly

Yep, I had tried that but still no success.

 

Posted by: Stuart Davies
Post date: 11/2/2007 12:21:53 AM

RE: RevisionManager: updating the link between a part and an assembly

 

Here is my code that works.  I also attached the VB.NET solution to this post compete with an example assembly.  You should be able to just compile and run it to see it work.Imports System.EnvironmentImports System.IOImports System.Runtime.InteropServicesModule Module1 Sub Main() Dim objApplication As RevisionManager.Application = Nothing Dim objDocument As RevisionManager.Document = Nothing Dim objLinks As RevisionManager.LinkedDocuments = Nothing Dim objLink As RevisionManager.Document = Nothing Dim retVal As Integer Try objApplication = Activator.CreateInstance(Type.GetTypeFromProgID("RevisionManager.Application")) objDocument = objApplication.Open(Path.Combine(Environment.CurrentDirectory, "Asm1.asm")) objLinks = objDocument.LinkedDocuments objLink = objLinks.Item(1) ' Replace Part1.par with Part2.par retVal = objLink.Replace(Path.Combine(Environment.CurrentDirectory, "Part2.par")) objDocument.SaveAllLinks() Catch ex As Exception Console.WriteLine(ex.Message) Finally If Not (objLink Is Nothing) Then Marshal.ReleaseComObject(objLink) End If If Not (objLinks Is Nothing) Then Marshal.ReleaseComObject(objLinks) End If If Not (objDocument Is Nothing) Then Marshal.ReleaseComObject(objDocument) End If If Not (objApplication Is Nothing) Then objApplication.Quit() Marshal.ReleaseComObject(objApplication) End If End Try End SubEnd Module

 

Posted by: Jason Newell
Post date: 11/2/2007 7:44:43 AM

RE: RevisionManager: updating the link between a part and an assembly

Thanks Jason, much appreciated - I'll give that a go.

 

Posted by: Stuart Davies
Post date: 11/2/2007 10:38:07 PM

RE: RevisionManager: updating the link between a part and an assembly

I managed to get my original code working after all - some code earlier in the workflow was using the FileProperties object and not garbage collecting afterwards (as some of your examples illustrate). Explicitly triggering a garbage collection appears to have freed up whatever resources the FileProperties object was holding on to, and the subsequent link update now succeeds.

 

Many thanks for your assistance and taking the time to post an example.

 

Posted by: Stuart Davies
Post date: 11/4/2007 3:50:56 AM