• 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. TCl script to replace selected parts with a component from...

Stats

  • State Verified Answer
  • Replies 16
  • Subscribers 14
  • Views 5248
  • Members are here 0
More Content

TCl script to replace selected parts with a component from library

soliman1991
soliman1991 over 1 year ago

Hello, 

I need to replace components in a schematic page with parts from the library, I tried DboPage_ReplaceInst, but the documentation is very vague.

Here is my attempt for reference: 

set selected [GetSelectedObjects]
puts $selected
set newPackageStr {CAP CER 0.1UF 10V X8M 0201} #that is the package name in the library
set lStatus [DboState]
set lSession $::DboSession_s_pDboSession
DboSession -this $lSession


set pLibName [file normalize {d:\random\Library.olb}]
set lLibName [DboTclHelper_sMakeCString $pLibName]
set lLib [$lSession GetLib $lLibName $lStatus]

set LibraryName [DboTclHelper_sMakeCString]

$lLib GetName $LibraryName
set newPackageName [DboTclHelper_sMakeCString newPackageStr]
set newPackage [$lLib GetPackage $newPackageName $lStatus]

foreach obj $selected {
    set device [$obj GetDevice $lStatus]
    DboPage_ReplaceInst $obj $newPackageName $newPackage $device $lStatus 0 0 1 1
}
  • Sign in to reply
  • Cancel
Parents
  • CadAP
    0 CadAP over 1 year ago

    Hello Soliman1991,

    Please use the below code to replace the selected part with a part from another library.

    set selected [GetSelectedObjects]
    # puts $selected
    set lPackage "C" ;#make sure the package name in the library.
    set lStatus [DboState]
    set lSession $::DboSession_s_pDboSession
    DboSession -this $lSession


    set pLibName [file normalize {d:\random\Library.olb}]

    foreach obj $selected {
    # set device [$obj GetDevice $lStatus]
    # $lPage ReplaceInst $obj $newPackageStr $lPart $device $lStatus 0 0 1 1
    ReplacePart "$pLibName" "$lPackage" "$lPackage.NORMAL" ""

    }

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • PatEscher
    0 PatEscher over 1 year ago in reply to CadAP

    what would be the difference between ReplaceInst and ReplacePart then?
    Are we really replacing the instances by this command or are we replacing the complete Parts, so that it automatically replaces all instances using this part?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP over 1 year ago in reply to PatEscher

    Hi PatEscher,

    Yes, ReplacePart is completing replacing the Part with the new one taken from library. While in ReplaceInst we can preserve previous value.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • PatEscher
    0 PatEscher over 1 year ago in reply to CadAP

    mhh, ok still not 100% clear.

    So I replace a selected component in the schematic (this is the placed instance) with the full definition of the component coming from the library.
    Is is like a 'delete' and an 'add" then?
    So I will lose as mentioned in the other post the RefDes (ok we could store the value and set it afterwards) and also all user modification done, right?
    Is there any performance difference between ReplacePart and ReplaceInst ?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • soliman1991
    0 soliman1991 over 1 year ago in reply to PatEscher

    FYI, I tried storing the RefDes and swapped the part using ReplacePart. Capture crashes after trying to write the RefDes back. Did you get any luck with that? 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP over 1 year ago in reply to PatEscher

    HI,

    ReplaceInst(pOldInst, packageName, part, device, status, bUpdate,
    Class : DboPage(DboBaseObject):
    bNewVersion, bPreserverefDes, bDeleteOldInst = 1) : returns DboPlacedInst
    Class : DboPage(DboBaseObject):
    Parameters:
    pOldInst: DboPlacedInst *
    packageName: CString &
    part: DboLibPart *
    device: DboDevice *
    status: DboState &
    bUpdate: int
    bNewVersion: int
    bPreserverefDes: int

    ReplacePart(libName, pkgName, partName, device)
    Parameters:
    libName: char const *
    pkgName: char const *
    partName: char const *
    device: char const *

    See the arguments required for ReplaceInst and ReplacePart. ReplaceInst have argument to bPreserverefDes and bDeleteOldInst.

    Is is like a 'delete' and an 'add" then?

    Yes
    So I will lose as mentioned in the other post the RefDes (ok we could store the value and set it afterwards) and also all user modification done, right?

    with ReplacePart --Yes.

    Is there any performance difference between ReplacePart and ReplaceInst ?

    Performance affect when accessing library over network(if there any network slowness or low latency) .

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • CadAP
    0 CadAP over 1 year ago in reply to PatEscher

    HI,

    ReplaceInst(pOldInst, packageName, part, device, status, bUpdate,
    Class : DboPage(DboBaseObject):
    bNewVersion, bPreserverefDes, bDeleteOldInst = 1) : returns DboPlacedInst
    Class : DboPage(DboBaseObject):
    Parameters:
    pOldInst: DboPlacedInst *
    packageName: CString &
    part: DboLibPart *
    device: DboDevice *
    status: DboState &
    bUpdate: int
    bNewVersion: int
    bPreserverefDes: int

    ReplacePart(libName, pkgName, partName, device)
    Parameters:
    libName: char const *
    pkgName: char const *
    partName: char const *
    device: char const *

    See the arguments required for ReplaceInst and ReplacePart. ReplaceInst have argument to bPreserverefDes and bDeleteOldInst.

    Is is like a 'delete' and an 'add" then?

    Yes
    So I will lose as mentioned in the other post the RefDes (ok we could store the value and set it afterwards) and also all user modification done, right?

    with ReplacePart --Yes.

    Is there any performance difference between ReplacePart and ReplaceInst ?

    Performance affect when accessing library over network(if there any network slowness or low latency) .

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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