Rename occurences of assembly in SE

Valued Contributor
Valued Contributor

Hello,

 

Story:

I'm creating a program to rename the selected assembly and it's children. The assembly is a concept, but needs to be converted to valid document numbers. The assembly and each occurence in this assembly already has it's custom properties filled (document number and revision).

 

I already have a function to check if these propertie values are valid values (document number must be like "S#######-####" and some other variants) and the current file name shouldn't already be a valid document number. After this check, i want to save the part/assembly as ("document number").value & ("revision").value.

 

 

Question:

How do I save/rename occurences in a way that the assembly looks at the new file/name? Is it safe to just set a new PartDocument to be the occurence, and save the PartDoc? or is there a way to access the 'edit'-mode in an assembly, and do a 'Save As' there?

 

thanks in advance!

___________________________
The truth is .... I am Dutch
VB.NET - C# - VS Ex 2015 - ST9
1 REPLY

Re: Rename occurences of assembly in SE

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hi JanWillem,

 

I think the best way to do this is to use the Revision Manager API in order to redefine links in the assembly.

 

For each component that needs to be renamed save the fullname  rename the file in Windows then using the revision manager replace the saved fullname with the new calculated name.

 

Try something like that :

 

        Dim InputASSY As String = "c:\MyAssembly.asm"
        Dim FileList As New Hashtable
        FileList.Add("C:\OldNamePart.par", "C:\NewNamePart.par")
        FileList.Add("C:\OldNameAsm.asm", "C:\NewNameAsm.asm")
        FileList.Add("C:\OldNamePsm.psm", "C:\NewNamePsm.psm")

        Dim ObjRev As RevisionManager.Application = CreateObject("RevisionManager.Application")

        Dim ObjDocRev As RevisionManager.Document
        ObjDocRev = ObjRev.OpenFileInRevisionManager(InputASSY)
        Dim objLinkedDocument As RevisionManager.Document

        Dim LinkedDocs As RevisionManager.LinkedDocuments
        LinkedDocs = ObjDocRev.LinkedDocuments(1)

        For i = 1 To LinkedDocs.Count
            objLinkedDocument = LinkedDocs.Item(i)
            If FileList.ContainsKey(objLinkedDocument.FullName) Then
                objLinkedDocument.Replace(FileList(objLinkedDocument.FullName))
            End If
        Next

        ObjRev.PerformActionInRevisionManager()

Good luck

Romuald


Romuald BERTIN