8 Replies Latest reply on Sep 14, 2009 1:40 PM by 1-LPYIQW

    Move file to new location based on metadata

    Brandon Waggoner

      I have a process that I am trying to test. I am getting stuck with trying to automatically move a file.

      I have a folder in PDM Ent. that will be populated with SW files. Once these files are in PDM I can use Dispatch to automatically check the files in. Is there a way that I can then move them to a new location in PDM Ent. based on a custom Property.

      Ex. Folder named Test is populated from a Knowledge Based Program and contains a SW file Part1.sldprt.  Part1 has a custom property named Project # with a value of 12345.  If folder 12345 is already created in PDM can I somehow automatically move Part1 to folder 12345?


      Thanks in advance.

        • Re: Move file to new location based on metadata
          Justin Dameron



          I have not tested this but I am thinking that using Dispatch, you could...

          1. Create and Action
          2. Check "During Add"
          3. Add a "Check in" command
          4. Set the Folder that it is checked in to to the same as a variable.

          Let me know if this works.

          • Re: Move file to new location based on metadata

            I'll be honest, I haven't touched Dispatch since I was introduced to it in Joy's advanced Enterprise training class. In my humble opinion, I have more control and can do more than Dispatch offers. Think of Dispatch as a layer on top of the API; therefore, you are limited to whatever Dispatch uses in the API.


            So, I'm going to offer an API approach to your problem. This will be pseudocode only and you will need to fill in the details and obvious gaps. Yes, there will be errors, missing pieces, and lack of error handling but this will get you heading in the right direction.


            Public Sub GetAddInInfo()


            End Sub


            Public Sub OnCmd()

                 Dim vault As EdmVault5 = CType(poCmd.mpoVault, EdmVault5)

                 Dim folder As IEdmFolder = Nothing

                 Dim file As IEdmFile5 = Nothing


                 Select Case poCmd.meCmdType


                 Case EdmCmdType.EdmCmd_PostAdd

                      file = vault.GetFileFromPath(cmdData(i).mbsStrData1, folder)

                      If (IsTestFolder(folder.ID)) Then

                           'You must have delete rights if moving file from one location to another in vault using IEdmBatchAdd

                           If (folder.HasRightsEx(EdmLib.EdmRightsFlags.EdmRight_Delete, file.ID)) Then

                                If (Me.LockFile()) Then

                                          Dim projNum As String = Me.GetProjectNumber(file)

                                          If Not (projNum = String.Empty) then

                                               'Move file performed here.

                                               Me.MoveFile(vault, file.ID, folder.ID, poCmd.mlParentWnd)


                                               'Check file in after moving it.

                                               file.UnlockFile(poCmd.mlParentWnd, "Moved file to proper project folder.")

                                          End If

                                End If

                           End If

                      End If

                 End Select

            End Sub


            Private Function IsTestFolder(folderID) As Boolean

                      'BLAH BLAH BLAH....

            End Function


            'I would test for this for added assurance.

            Private Function LockFile() As Boolean

                 Dim status As Boolean = False

                      If Not (file.IsLocked) Then


                           status = True


                           status = True

                      End If

                 Return status

            End Function


            Private function GetProjectNumber(file) As String

                 Dim eVar As IEdmEnumeratorVariable = variable = CType(file.GetEnumeratorVariable(), IEdmEnumeratorVariable6)

                 Dim result As String = Nothing

                 Dim value As Object = Nothing


                 If  (eVar.GetVar("Project#", "", value)) Then

                        result = value.ToString()


                        result = String.Empty

                 End If

                 Return result

            End Function


            Private Function MoveFile(vault, FileID, FolderID, windowID) As Boolean

                Dim batch As IEdmBatch = CType(vault, IEdmVault7).CreateUtility(EdmUtil_BatchAdd)

                 Dim IArg As Long = 0

                 Dim filesAdded() As EdmFileInfo = Nothing

                 batch.AddFileFromVaultToPath(FileID, FolderID, GetDestinationPath(), IArg, "", EdmAdd_DeleteSource)

                 batch.CommitAdd(WindowID, filesAdded, 0)

            End Function


            Private Function GetDestinationPath(SourceFolderPath, ProjectNumber) As String

                 Return "destinationPathGoesHere"

            End Function


            Scott Blackwell

            CADimensions, Inc.

            Application Engineer (PDM and API Specialist)