• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X Scripting - TCL
  3. How to properly move a part between OLBs with TCL?

Stats

  • State Verified Answer
  • Replies 11
  • Subscribers 15
  • Views 1781
  • Members are here 0
More Content

How to properly move a part between OLBs with TCL?

andakConsultingLtd
andakConsultingLtd 3 months ago

I am trying to clean up some old libraries i.e. move unused parts from active.olb to unused.olb. The code is presented below. Everything works pretty well except that there is something hanging inside active.olb that prevents creating a part that was there before. E.g. if PART_123 was moved from active olb to unused.olb, I can not create PART_123 again. If I look inside active.olb file, PART_123 is still mentioned, despite not being shown in the lib tree structure. I guess I am missing some cleanup in my code, but I can't figure what exactly, so I am asking for your help.

set lSession [DboTclHelper_sCreateSession]
set lStatus [DboState]
set lNullObj NULL

#Provide the location of olb FROM which package should be copied.
set lSourceLibPath [file normalize {D:\ACTIVE.OLB}]
set lSourceLibPathCstring [DboTclHelper_sMakeCString $lSourceLibPath]
set lSourceLib [$lSession GetLib $lSourceLibPathCstring $lStatus]

#Provide the location of olb TO which package should be copied.
set lDestnLibPath [file normalize {D:\UNUSED.OLB}]
set lDsctnLibPathCstring [DboTclHelper_sMakeCString $lDestnLibPath]
set lDestnLib [$lSession GetLib $lDsctnLibPathCstring $lStatus]

#parse all packages in the olb
set pkgIter [$lSourceLib NewPackagesIter $lStatus]
set pPkg [$pkgIter NextPackage $lStatus]

while {$pPkg!=$lNullObj} {
    set pActualPkgName [DboTclHelper_sMakeCString]
    $pPkg GetName $pActualPkgName
    $lDestnLib CopyPackageAll $pPkg $pActualPkgName $lStatus
    $lSourceLib DeletePackage $pPkg

    puts [DboTclHelper_sGetConstCharPtr $pActualPkgName]
    set pPkg [$pkgIter NextPackage $lStatus]
}

$lDestnLib MarkModified
$lSourceLib MarkModified

$lSession MarkAllLibForSave $lDestnLib
$lSession SaveLib $lDestnLib
$lSession RemoveLib $lDestnLib

$lSession MarkAllLibForSave $lSourceLib
$lSession SaveLib $lSourceLib
$lSession RemoveLib $lSourceLib

DboTclHelper_sDeleteSession $lSession

  • Sign in to reply
  • Cancel
  • CadAP
    0 CadAP 3 months ago

     andakConsultingLtd 

    Please use below article available on ASK portal.

    Article (20508160)
    Title: How to copy symbols or packages from one library (.olb) to another using Tcl script in OrCAD Capture
    URL: https://support.cadence.com/apex/ArticleAttachmentPortal?id=a1O3w000009lgEWEAY&pageName=ArticleContent

    Hope it helps.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • andakConsultingLtd
    0 andakConsultingLtd 3 months ago in reply to CadAP

    Hi CadAP 

    Thanks for sharing, I wasn't aware of that resource.

    Back to the solution you suggested, it doesn't solve the problem, as the code provided there only copies from source to destination. The code presented by me succesfuly does this too.

    The problem in my code is that deleting the package from the source olb leaves some garbage behind. Deleting is not addressed in the article you suggested.

    Regards

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP 3 months ago in reply to andakConsultingLtd

     andakConsultingLtd 

    Please use below code to delete the package

    set lSession $::DboSession_s_pDboSession
    DboSession -this $lSession
    set lNullObj NULL
    set lOlbName "test.olb" ; #provide your library which is open in capture.
    set lPackageCString [DboTclHelper_sMakeCString ]
    set lStatus [DboState]
    set libname [DboTclHelper_sMakeCString "$lOlbName"]
    # set lNewDboLib [$lSession CreateLib $llibNamecstring $lStatus]
    set lDboLibrary [DboSession_GetOpenLib $lSession $libname $lStatus]
    set lNameCStr [DboTclHelper_sMakeCString]
    set lPackageIter [$lDboLibrary NewPackagesIter $lStatus]
    set pPackage [$lPackageIter NextPackage $lStatus]
    # $lDboLibrary GetName $libname
    set lLibLocation [file normalize [DboTclHelper_sGetConstCharPtr $libname]]
    puts [file normalize $lLibLocation]
    while {$pPackage != $lNullObj} {
    $pPackage GetName $lPackageCString
    set lpackagename [DboTclHelper_sGetConstCharPtr $lPackageCString]
    puts $lpackagename
    set lState [$lDboLibrary DeletePackage $pPackage]
    if {[$lState OK] == 1} {

    puts "delete $lpackagename successfully."


    }
    set pPackage [$lPackageIter NextPackage $lStatus]
    }

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • andakConsultingLtd
    0 andakConsultingLtd 3 months ago in reply to CadAP

    Hi CadAP ,

    This is no different than my code, except your code operates on a loaded olb. Both scripts delete the package indeed, but when I try to recreate one of the packages that was deleted, Capture throws an error.

    This was exactly the problem I was trying to solve since the begining.
    If it matters, this happens in 23.1 - S008

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP 3 months ago in reply to andakConsultingLtd

    andakConsultingLtd ,

    Can you please let me know your exact steps your doing through tcl code?

    I want to try the exact same steps.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information