• 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. Function iterator optimization

Stats

  • State Verified Answer
  • Replies 6
  • Subscribers 12
  • Views 1712
  • Members are here 0
More Content

Function iterator optimization

ZH202409115233
ZH202409115233 2 months ago

I have implemented a function designed to assign properties to specific components according to predefined rules. However, during execution, the memory usage continuously increases, eventually leading to a software crash. Could you please advise on potential optimization strategies?

code ;

proc parts_NCHandle_event_handle_dsn {} {
    set lStatus [DboState]
    set lSession $::DboSession_s_pDboSession
    DboSession -this $lSession
   
    set lDesign [$lSession GetActiveDesign]
    set NULL_OBJ "NULL"
   
    
    set lSchematicIter [$lDesign NewViewsIter $lStatus $::IterDefs_SCHEMATICS]
    while {[set lView [$lSchematicIter NextView $lStatus]] != $NULL_OBJ} {
        set lSchematic [DboViewToDboSchematic $lView]
        puts $lSchematic
        # 
        set lPagesIter [$lSchematic NewPagesIter $lStatus]
        while {[set lPage [$lPagesIter NextPage $lStatus]] != $NULL_OBJ} {
            # 
            puts $lPage
            set lPartInstsIter [$lPage NewPartInstsIter $lStatus]
            while {[set lInst [$lPartInstsIter NextPartInst $lStatus]] != $NULL_OBJ} {
                set lPlacedInst [DboPartInstToDboPlacedInst $lInst]
                if {$lPlacedInst != $NULL_OBJ} {
                    if {[catch {
                        setNC $lPlacedInst
                    } err]} {
                        puts " $lPlacedInst : $err"
                    }
                }
            }
            delete_DboPagePartInstsIter $lPartInstsIter
            DboTclHelper_sEvalPage $lPage
        }
        delete_DboSchematicPagesIter $lPagesIter
    }
    puts "执行完成"
    delete_DboLibViewsIter $lSchematicIter
    $lStatus -delete
}
proc setNC {lPlacedInst} {
set lStatus [DboState]
set lNullObj NULL
# puts $lcolor
set lPropNameCStr [DboTclHelper_sMakeCString "Value"]
#DboDisplayProp
set pDispProp [$lPlacedInst GetDisplayProp $lPropNameCStr $lStatus]
# puts $pDispProp
if {$pDispProp != $lNullObj} {
set lvalue [DboTclHelper_sMakeCString]
set lStatus [$pDispProp GetValueString $lvalue]
set lvStr [DboTclHelper_sGetConstCharPtr $lvalue]
DboTclHelper_sDeleteCString $lvalue
# puts $lvStr
set str ""
if {![string match "NC/*" $lvStr ] } {
# puts ookk11
set lcolor [$lPlacedInst GetColor $lStatus]
if {$lcolor == 45} {
set str "NC/"

} elseif {$lcolor == 43} {
set str "NC/NC/"
}
}
if {$str != ""} {
# puts $str$lvStr
set lPropValueCStr [DboTclHelper_sMakeCString $str$lvStr]
set lStatus [$lPlacedInst SetEffectivePropStringValue $lPropNameCStr $lPropValueCStr 0]
}
}

set lPropsIter [$lPlacedInst NewDisplayPropsIter $lStatus]
#set lNullObj NULL
set lvalue [DboTclHelper_sMakeCString]
#puts 1
set lPropNameCStr [DboTclHelper_sMakeCString "Value"]
#DboDisplayProp
set pDispProp [$lPlacedInst GetDisplayProp $lPropNameCStr $lStatus]
DboTclHelper_sDeleteCString $lPropNameCStr
if {$pDispProp != $lNullObj } {
set lStatus [$pDispProp GetValueString $lvalue]
set lvStr [DboTclHelper_sGetConstCharPtr $lvalue]
if {![regexp {^NC/[^N]} $lvStr]} {

return
}
if {![string match "NC/NC/*" $lvStr ]} {

return
}

#puts $lvalue
#get the first display property on the object
set lDProp [$lPropsIter NextProp $lStatus]
while {$lDProp !=$lNullObj } {

#
set lPropNameCStr [DboTclHelper_sMakeCString "Color"]
if {[regexp {^NC/[^N]} $lvStr]} {
set lPropValueCStr [DboTclHelper_sMakeCString "RGB(192,192,192)"]
set lStatus1 [$lPlacedInst SetEffectivePropStringValue $lPropNameCStr $lPropValueCStr]
$lDProp SetColor 45
}
if {[string match "NC/NC/*" $lvStr ]} {
set lPropValueCStr [DboTclHelper_sMakeCString "RGB(128,128,128)"]
set lStatus1 [$lPlacedInst SetEffectivePropStringValue $lPropNameCStr $lPropValueCStr]
$lDProp SetColor 43
}
DboTclHelper_sDeleteCString $lPropNameCStr
#get the next display property on the object
set lDProp [$lPropsIter NextProp $lStatus]
}
delete_DboDisplayPropsIter $lPropsIter
}
DboTclHelper_sDeleteCString $lvalue
$lStatus -delete
puts "done"
}
  • Cancel
  • Sign in to reply
  • TechnoBobby
    +1 TechnoBobby 2 months ago

    Hi ZH202409115233 ,

    Are you monitoring memory usage in Task Manager and noticing it gradually rise to 100%, after which the tool crashes?

    Also, does the same script run fine on a smaller design?

    If yes, one thing you could try is disabling online DRC while running the script. You can do this by going to:
    PCB > Design Rules Check > Options, and turning off online DRC.

    Hope this helps!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • ZH202409115233
    0 ZH202409115233 2 months ago in reply to TechnoBobby

    Thank you, your suggestion is effective. Sorry I didn't provide complete information earlier. The smaller design is runnable. I intentionally used a very large design (33 pages) to test it, and I observed in Task Manager the process of memory gradually increasing, until it reached 100%, after which the application crashed.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • PatEscher
    0 PatEscher 2 months ago in reply to TechnoBobby

    TechnoBobby CadAP 

    is there a possibility to turn off the online DRC through a tcl command
    We also do quite some operations on the design and would like to turn it off before and then afterwards turn it on again

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • TechnoBobby
    0 TechnoBobby 2 months ago in reply to PatEscher

    Hi PatEscher ,

    Yes, there is a TCL command to turn online DRC on or off.
    Below link will take you to an article on ASK:

    Title: How can I enable or disable 'Online DRC' by using Tcl commands?
    URL: https://support.cadence.com/apex/ArticleAttachmentPortal?id=a1O3w000009mKF5EAM

    Hope this helps!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • PatEscher
    0 PatEscher 2 months ago in reply to TechnoBobby

    Hello TechnoBobby , 

    Thanks, that works fine but it requires that the global DRC setting is activated.
    Now, if this global DRC setting is not activated, how can i set/toggle the design specific settings?

    Alternatively, would it be possible to turn the global DRC settings on on demand and also turn it off?

    • 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