1 Reply Latest reply on Nov 30, 2018 9:05 AM by Patrick.Cashman

    Script to transfer parts to new partition at Library Manager


      We are planning to create new parts partition and at the same time delete parts partition at our existing library.

      How to create, delete parts partition and assigning the existing parts to the newly created parts at Library manager partition using an excel file which contains where the parts should go to?

        • 1. Re: Script to transfer parts to new partition at Library Manager

          You can use the part.copy function to copy a part into the same partition as the source part. 


          You can use partition.newpart to create a new part, then add properties, cell and symbol references, and so forth based on an existing part, then part.delete to remove the old part.


          So there's no way I know of to move a part from one partition to another, or copy into a new partition, but the functions I've referenced here will get you to the same thing. I don't have a script to do exactly what you are asking but here is a bare-bones example of copying a part within the same partition. It should at least get you started with the hooks to the library and the basics of a framework to use the commands I've listed above:


          (note this is all done in vb.net so if you do this in a vbscript or EFM you'll have to modify it accordingly.)


          Public central_library_path As String

          Public part_ed_dlg As MGCPCBPartsEditor.PartsEditorDlg

          Public pdb_db As MGCPCBPartsEditor.PartsDB


          Public partitions As MGCPCBPartsEditor.Partitions

          Public partition As MGCPCBPartsEditor.Partition

          Public parts As MGCPCBPartsEditor.Parts

          Public part As MGCPCBPartsEditor.Part




             Sub copy_pdbs()


          'note copy_part_list is created earlier. It's dictionary of old part number, new part number


                  Dim old_pn, new_pn As String

                  Dim new_part As MGCPCBPartsEditor.Part




                  partitions = pdb_db.Partitions



                  For Each partition In partitions

                      parts = partition.Parts

                      For Each part In parts

                          old_pn = part.Number

                          If copy_part_list.ContainsKey(old_pn) Then

                              new_pn = copy_part_list(old_pn)


                                  'copy the existing part with the new part number

                                  new_part = part.Copy(new_pn, new_pn, part.Label)

                              Catch ex As Exception

                                  'create a failure message

                              End Try

                          End If







              End Sub




          Public Sub Get_Part_Editor()

                  'Creates a handle to the Parts Editor in Library Manager



                  part_ed_dlg = CreateObject("MGCPCBLibraries.PartsEditorDlg" & "." & prog_id.ToString)

                  pdb_db = part_ed_dlg.OpenDatabaseEx(central_library_path, False)



                  If part_ed_dlg.LockServer() Then

          'do nothing


          msgbox("Could not lock database for writing")

          End If

          End Sub




          Public Sub Drop_Part_Editor()

          'Close the open library and release hooks





          pdb_db = Nothing

          part_ed_dlg = Nothing

          End Sub