Showing results for 
Search instead for 
Did you mean: 

Copy ASM with Design Manager by API


Hi everybody,


I'm creating a program in to copy and rename assemblies and all its linked documents and drafts.


I have used the Revisión manger perform rename sample in github solid edge community. Thanks @jnewell.


I am able to get the list of whereused documents (dft's in this case) for any of the linked documents and add them to the lists that are later used to launch the SetActionInRevisionManager method but drafts documents are not copied or nemaned.


If I run the code step by step with the appliclation.visible= true option, I can see that whereused documents are not listed in the Design Manager window. If I run manually the WhereUsed command inmediately before the setActionInRevisionManager method to get the dfts listed in Design Manager window, then all works ok.


Any idea how to make the whereused documents appear in the Design Manager windows programmatically?


The process I follow is as follows:


Open Design Manager.

Open the Asm in Design Manager.

Create three lists, currentName (of string), newName (of string), performAction (of RevisionManagerAction).

For each linkedDocument of asm:

   add the current document name to currentName list.

   add the new name to newName list.

   add the CopyAction constant to performAction.

   get whereused documents and add each of them to the currentName, newName and CopyAction lists.

setActionInRevisionManager(currentName.count, currentName, CopyActions, newName).


Close the Asm.

Close Revision Manager.


All documents are copied and rename but dfts.




Namespace PerformRenameAction
     Friend Class Program
        Shared ListOfInputFileNames As New List(Of String)()
        Shared ListOfNewFileNames As New List(Of String)()
        Shared ListOfInputActions As New List(Of RevisionManager.RevisionManagerAction)()
        Shared application As New RevisionManager.Application
        Shared draftspath As String
        Shared Sub Main(ByVal args() As String)
            ' For testing purposes, change the path to the .asm.
            Dim assemblyPath = "C:\prueba\Coffee Pot.asm"
            draftspath = System.IO.Path.GetDirectoryName(assemblyPath)
            ' Start Revision Manager.
            'Dim application = New RevisionManager.Application()
            ' Open the assembly.
            Dim assemblyDocument = DirectCast(application.OpenFileInRevisionManager(assemblyPath), RevisionManager.Document)
            'application.Visible = True
            application.Visible = 1
            application.DisplayAlerts = 0
            ' Allocate input arrays.
            'Copy/rename asm
            Dim asmDocumentPath = assemblyDocument.AbsolutePath
            Dim asmDocumentDirectory = System.IO.Path.GetDirectoryName(asmDocumentPath)
            Dim asmDocumentFilename = System.IO.Path.GetFileName(asmDocumentPath)
            Dim asmDocumentExtension = System.IO.Path.GetExtension(asmDocumentPath)
            Dim asmDocumentNewPath As String
            asmDocumentNewPath = System.IO.Path.GetFileNameWithoutExtension(asmDocumentFilename) & " - COPY"
            asmDocumentNewPath = System.IO.Path.ChangeExtension(asmDocumentNewPath, asmDocumentExtension)
            asmDocumentNewPath = System.IO.Path.Combine(asmDocumentDirectory & "02", asmDocumentNewPath)
            If asmDocumentNewPath <> asmDocumentPath Then
            End If
            ' Process each linked document.
            ' Set the action.
            application.SetActionInRevisionManager(ListOfInputFileNames.Count, ListOfInputFileNames.ToArray(), ListOfInputActions.ToArray(), ListOfNewFileNames.ToArray())
            ' Perform the action.
            ' Close the assembly.
            ' Close Revision Manager.
        End Sub
        Shared Sub ProcesarEstructura(ByRef asm As RevisionManager.Document)
            Dim linkedDocuments = DirectCast(asm.LinkedDocuments, RevisionManager.LinkedDocuments)
            For i As Integer = 1 To linkedDocuments.Count
                ' Get the specified linked document by index.
                Dim linkedDocument = DirectCast(linkedDocuments.Item(i), RevisionManager.Document)
                ' Get the current path, folder path, filename and extension to the linked document.
                Dim linkedDocumentPath = linkedDocument.AbsolutePath
                ' Find whereused dfts
                application.WhereUsedCriteria("*.dft"True) = draftspath
                Dim usedby As Array
                usedby = Nothing
                application.FindWhereUsedDocuments(linkedDocumentPath, usedby)
                ' Get the newName of whereused dfts
                For Each whereUsedDocument As String In usedby
                    If whereUsedDocument = Nothing Then
                        Continue For
                    End If
                'Get the subassemblies structures.
                Dim suboccurrences As RevisionManager.LinkedDocuments = DirectCast(linkedDocument.LinkedDocuments, RevisionManager.LinkedDocuments)
                If suboccurrences.Count > 0 Then
                End If
        End Sub
        Shared Sub GetNewNameAndAddToArrays(DocumentPath As String)
            Dim currentDocumentPath = DocumentPath
            Dim currentDocumentDirectory = System.IO.Path.GetDirectoryName(currentDocumentPath)
            Dim currentDocumentFilename = System.IO.Path.GetFileName(currentDocumentPath)
            Dim currentDocumentExtension = System.IO.Path.GetExtension(currentDocumentPath)
            ' Generate a new random filename for the linked document.
            Dim newDocumentwPath As String
            If currentDocumentFilename.StartsWith("2017"Then
                newDocumentwPath = "5555" & currentDocumentFilename.Substring(4)
                newDocumentwPath = currentDocumentFilename
            End If
            newDocumentwPath = System.IO.Path.ChangeExtension(newDocumentwPath, currentDocumentExtension)
            newDocumentwPath = System.IO.Path.Combine(currentDocumentDirectory & "02", newDocumentwPath)
            ' Populate the arrays.
            If newDocumentwPath <> currentDocumentPath Then
            End If
        End Sub
    End Class
End Namespace


 I also attach the  asm used for tests.


I read in the sdk documentation that this way of doing it will be deprecated in ST10 version. What would be the correct form thereafter?


Thank in advance.

Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET

Re: Copy ASM with Design Manager by API

Valued Contributor
Valued Contributor

Hello Hector,

It seems we both have simular minds because first you posted something about printing drafts to different printers and now you want to copy all linked drafts from an existing assembly or head draft. Smiley Happy

I've been able to do it but i had to do a work around. Are you still in need for a possible solution? If so let me know something.

Kind regards,