• 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 System Capture (EE Cockpit)
  3. TCL/script to get the Custom variables variant specific...

Stats

  • State Verified Answer
  • Replies 10
  • Subscribers 29
  • Views 3101
  • Members are here 0
More Content

TCL/script to get the Custom variables variant specific Values and transfer to a customer variable?

MZ20250602835
MZ20250602835 3 months ago

Dear all,

may i ask how could i make a TCL/script in order to get the Custom variables variant specific Values for specific row(For example row3 DOC_PART_PCBA) and then give/transfer this value to a customer variables?

    

Many thanks

Moyan

  • Cancel
  • Sign in to reply
Parents
  • CadAP
    +1 CadAP 2 months ago

    MZ20250602835 

    Please try the script below, as it will update the custom variable value by reading from the variant.

    For the purpose of this example, I've taken the first value of the variable from Variant in case of multiple variants.

    proc checkFuncVar {} {

    # puts "entering check mode"
    set toolVar [lindex [cps::getAppVersion] 0]

    set lDesigName [sch::dbGetRootDesignName]
    cpb::extractFile "worklib/$lDesigName/variant/variant.dat" {variant.dat}
    set filename "variant.dat"
    set pattern "CV_"
    set fp [open $filename r]
    set functiontest {}
    while {[gets $fp line] >= 0} {
    if {[string match -nocase "*$pattern*" $line]} {
    # puts $line
    lappend functiontest $line
    }
    }
    close $fp
    return $functiontest
    if {[file exists $filename ] == 1} {

    file delete $filename

    }


    }

    set data [checkFuncVar]

    set lCustVar {}
    set regex {\{\s*(CV_\w+)\s*=\s*'([^']+)'\s*;?\s*\}}

    set valuesOnlyList {}
    foreach {full _ rawValue} [regexp -all -inline $regex $data] {
    set innerDict {}
    foreach pair [split $rawValue |] {
    lassign [split $pair =] k v
    dict set innerDict $k $v
    }
    lappend valuesOnlyList $innerDict
    }

    # Example: print each values-only dict
    foreach d $valuesOnlyList {
    # # puts "prop : [llength $d ]"
    # puts "prop : [lindex $d 0]"
    set lLength [llength $d]
    for {set i 0} {$i < $lLength} {incr i} {


    set lPropName [lindex $d $i]
    incr i
    set lPropVal [lindex $d $i]
    # puts $lPropName
    # puts $lPropVal
    if {$lPropName == "DOC_PART_PCBA"} {
    lappend lCustVar $lPropVal
    }

    }
    }

    # puts $lCustVar
    set lVarVal [lindex $lCustVar 0]
    # puts $lVarVal

    set lCustomVar [cps::setDirectiveValue CUSTOMVAR TEST_V1 $lVarVal STRING]

    saveAll
    cps::reopenProject

    Try and let me know your feedbcak.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Reply
  • CadAP
    +1 CadAP 2 months ago

    MZ20250602835 

    Please try the script below, as it will update the custom variable value by reading from the variant.

    For the purpose of this example, I've taken the first value of the variable from Variant in case of multiple variants.

    proc checkFuncVar {} {

    # puts "entering check mode"
    set toolVar [lindex [cps::getAppVersion] 0]

    set lDesigName [sch::dbGetRootDesignName]
    cpb::extractFile "worklib/$lDesigName/variant/variant.dat" {variant.dat}
    set filename "variant.dat"
    set pattern "CV_"
    set fp [open $filename r]
    set functiontest {}
    while {[gets $fp line] >= 0} {
    if {[string match -nocase "*$pattern*" $line]} {
    # puts $line
    lappend functiontest $line
    }
    }
    close $fp
    return $functiontest
    if {[file exists $filename ] == 1} {

    file delete $filename

    }


    }

    set data [checkFuncVar]

    set lCustVar {}
    set regex {\{\s*(CV_\w+)\s*=\s*'([^']+)'\s*;?\s*\}}

    set valuesOnlyList {}
    foreach {full _ rawValue} [regexp -all -inline $regex $data] {
    set innerDict {}
    foreach pair [split $rawValue |] {
    lassign [split $pair =] k v
    dict set innerDict $k $v
    }
    lappend valuesOnlyList $innerDict
    }

    # Example: print each values-only dict
    foreach d $valuesOnlyList {
    # # puts "prop : [llength $d ]"
    # puts "prop : [lindex $d 0]"
    set lLength [llength $d]
    for {set i 0} {$i < $lLength} {incr i} {


    set lPropName [lindex $d $i]
    incr i
    set lPropVal [lindex $d $i]
    # puts $lPropName
    # puts $lPropVal
    if {$lPropName == "DOC_PART_PCBA"} {
    lappend lCustVar $lPropVal
    }

    }
    }

    # puts $lCustVar
    set lVarVal [lindex $lCustVar 0]
    # puts $lVarVal

    set lCustomVar [cps::setDirectiveValue CUSTOMVAR TEST_V1 $lVarVal STRING]

    saveAll
    cps::reopenProject

    Try and let me know your feedbcak.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Children
  • MZ20250602835
    0 MZ20250602835 2 months ago in reply to CadAP

    Dear CadAP,

    many thanks for your reply. I get the result and it works with your codes.

    Thanks a million again.

    Moyan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • MZ20250602835
    0 MZ20250602835 2 months ago in reply to CadAP

    Dear CadAP,

    i realised that the values will be updated after reopen the design.

    But after reopen i get the warning because of the Pulse.

    May i ask if is it possible to avoid this warning after reopen? or update the custom variables value without reopening the design?

    Many thanks

    MOyan

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP 2 months ago in reply to MZ20250602835

    MZ20250602835 

    we need to repone the design to read the cpm diretive, which is written by script.

    For suppressing the message, you can use belwo command:

    cps::setSuppressDialog <bool> tcl API can be used to suppress pop up messages.
    e.g.
    cps::setSuppressDialog 1
    This will suppress all the pop up messages for current session. Executing same command with value 0 will re-enable pop up messages:
    cps::setSuppressDialog 0

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • MZ20250602835
    0 MZ20250602835 2 months ago in reply to CadAP

    Dear CadAP,

    many thanks for your support. After test i got one issue and i could not figure out the reason yet. It seemed the value impact the sequence.

    Sometime i got the wrong order of variant within variant.dat file and then i got the wrong value.

    May i ask how could i guarantee to get the right order of the variant?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP 2 months ago in reply to MZ20250602835

    MZ20250602835 

    Retrieve the list of variants from the design using the function cps::getVariantNames, which returns the variant names in order, and store this list in a variable.

    Iterate to the foreach loop defined in the above code and retrieve the variable value 'data'.  Parse the variable by removing the prefix "CV_" and then match the resulting variant name against the list from above in order to obtain the corresponding property value.

    This will help you to achieve you requirement.

    • 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.

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

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