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

    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
  • MZ20250602835
    0 MZ20250602835 2 months ago in reply to CadAP

    Dear CadAP,

    many many thanks again, i modified the script within checkFuncVar in order to get CV_VAR_X at one time so it works independent of the order of the variants.

    happy Easter
    Many thanks
    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,

    during test i have one issue, if the data content ~ and changed the row in this case i can`t get the value later for custom variable.

    CV_VAR_1='DOC_COMPPLAN_DESC=test|DOC_COMPPLAN_NO=2100-1000|DOC_COMPPLAN_VER=00|~
    DOC_PART_PCBA=5100-1000|DOC_PART_PCB_NUMBER=5100|DOC_PCBAPLAN_MOD_DATE=test_MOD_~
    DATE|DOC_PCBAPLAN_MOD_ENG=test MOD_ENG|DOC_PCBAPLAN_PROD_DATE=test_DATE|DOC_PCBA~
    PLAN_PROD_ENG=test_ENG';

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

    MZ20250602835 

    Please try to remove the "~" from the list "valuesOnlyList" where we are storing the dict  key and value. 

     

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

    Many thanks again,

    the problem is solved.

    Best Regards

    Moyan

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

    Many thanks again,

    the problem is solved.

    Best Regards

    Moyan

    • Cancel
    • Vote Up 0 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.

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

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