• 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 select a project and save it with Tcl Command

Stats

  • State Suggested Answer
  • Replies 15
  • Answers 1
  • Subscribers 12
  • Views 2624
  • Members are here 0
More Content

How to select a project and save it with Tcl Command

Morgan
Morgan 5 months ago

Hi friends of the community,

I want to use Tcl Command to select the last opened project name(or library) in capture cis, such as .dsn(.olb), and then, save and close it, but I encounter some troubles:

1.When I iter all open designs in the session with 3.2.5, it get the design name, but not listed in the order in which they were opened, so I can't find the last opened project; and sometimes, it listed the project name I have closed;

2.When I try to select the .dsn or .olb name use <ui::PMActivate "d:/cadence/work/test/mytest.opj"> and <SelectPMItem "./mytest.dsn">, and catch the error, it report errors with "RuntimeError Item Not Found" frequently. Is there any Tcl Command that implements this function?

3.When I save the project or library after modify with the code blow, It will pop up a window that needs to be confirmed, but I don't need the step, I want just save it directly.

#

#

# the code use this:


DboSession_MarkAllLibForSave $lLibSession $lDboLibrary
DboSession_SaveLib $lLibSession $lDboLibrary

#

#

# the confirm window like this:

  • Sign in to reply
  • Cancel
Parents
  • CadAP
    0 CadAP 5 months ago

    Morgan 

    Please find below sample code. It will get the last opened project based on the .dsn file time. Tcl code will save and close the project also.

    Try and let me know your feedback.

    set lDesignNameCs [DboTclHelper_sMakeCString]
    set lSession $::DboSession_s_pDboSession
    DboSession -this $lSession
    set lStatus [DboState]
    set sep ","
    set lDesignTime {}
    set lDesignloc {}
    set lDesignsIter [$lSession NewDesignsIter $lStatus]
    #get the first design
    set lDesign [$lDesignsIter NextDesign $lStatus]
    set lNullObj NULL
    while { $lDesign!= $lNullObj} {
    #placeholder: do your processing on $lDesign
    # puts $lDesign
    $lDesign GetName $lDesignNameCs
    set lDesignName [DboTclHelper_sGetConstCharPtr $lDesignNameCs]
    set lFileTime [file atime $lDesignName]
    set ldesignFileTime "[clock format $lFileTime -format %H:%M:%S]"

    lappend lDesignloc $lDesignName
    lappend lDesignTime $ldesignFileTime

    set lDesign [$lDesignsIter NextDesign $lStatus]

    }
    delete_DboSessionDesignsIter $lDesignsIter


    # foreach lDesgTime $

    # puts [llength $designlocAndTime]

    set lcount 0
    foreach lData $lDesignTime {

    if {$lcount == 0} {
    set lLastTime [split $lData ":"]
    incr lcount
    }
    # puts $lData
    if {$lcount > 0} {
    set lLastHr [lindex $lLastTime 0]
    set lLastMins [lindex $lLastTime 1]
    set lLastSec [lindex $lLastTime 2]
    set lDesignTm [split $lData ":"]
    set lDesignHr [lindex $lDesignTm 0]
    set lDesignMins [lindex $lDesignTm 1]
    set lDesignSec [lindex $lDesignTm 2]
    }

    if {$lLastHr > $lDesignHr} {

    # puts $lData
    set lLastTime [split $lData ":"]

    }
    if {$lLastHr == $lDesignHr} {

    # puts $lData
    if {$lLastMins > $lDesignMins} {
    set lLastTime [split $lData ":"]
    }

    if {$lLastMins == $lDesignMins} {
    if {$lLastSec > $lDesignSec} {
    set lLastTime [split $lData ":"]
    }
    }
    }
    }

    set lLastDesignTime [join $lLastTime ":"]
    # puts $lLastDesignTime
    # puts $lDesignTime
    set lTimeIndex [lsearch $lDesignTime $lLastDesignTime]
    # puts $lTimeIndex
    set lDesignfromIndex [lindex $lDesignloc $lTimeIndex]
    # ui::PMActivate "$lDesignloc"
    set lDesgnLoc [split $lDesignfromIndex "\\"]

    set lDesignName [lindex $lDesgnLoc [expr { [llength $lDesgnLoc] - 1}]]
    ui::PMActivate "$lDesignfromIndex"
    puts "/$lDesignName"
    Menu "File::Save"
    Menu "File::Close"

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Morgan
    0 Morgan 5 months ago in reply to CadAP

    Hi CadAP, thank you for the code, I run it on my computer.

    1. When I close one project, then run the program, the dsn name still appears in the list lDesignloc.

    2. <ui::PMActivate "$lDesignfromIndex"> can't active and select any dsn file, it print message: [    1]No View Present, Is there any Datbase Tcl Command that implements this function(select dsn file), such as SelectPMItem or GetSelectedPMItems?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP 5 months ago in reply to Morgan

    Morgan 

    I have tried multiple times but not able to see the issue as mentioned above.

    Can you please check that you have "ON "the journaling option present in the "Extended Preference".

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Morgan
    0 Morgan 5 months ago in reply to CadAP

    Hi CadAP, 

    Yes, I have "ON "the journaling option, but after I have close it, the 2 issue not disappeared, and test in cadence version 16.6, 24.1

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP 5 months ago in reply to Morgan

    Morgan 

    I tried in SPB24.1 and it is working as expected.

    I have modified the code a little bit let check if it works for you or not?

    # Get last design open and close it
    set lDesignNameCs [DboTclHelper_sMakeCString]
    set lSession $::DboSession_s_pDboSession
    DboSession -this $lSession
    set lStatus [DboState]
    set sep ","
    set lDesignTime {}
    set lDesignloc {}
    set lDesignsIter [$lSession NewDesignsIter $lStatus]
    #get the first design
    set lDesign [$lDesignsIter NextDesign $lStatus]
    set lNullObj NULL
    while { $lDesign!= $lNullObj} {
    #placeholder: do your processing on $lDesign
    # puts $lDesign
    $lDesign GetName $lDesignNameCs
    set lDesignName [DboTclHelper_sGetConstCharPtr $lDesignNameCs]
    set lFileTime [file atime $lDesignName]
    set ldesignFileTime "[clock format $lFileTime -format %H:%M:%S]"

    lappend lDesignloc $lDesignName
    lappend lDesignTime $ldesignFileTime

    set lDesign [$lDesignsIter NextDesign $lStatus]

    }
    delete_DboSessionDesignsIter $lDesignsIter


    # foreach lDesgTime $

    # puts [llength $designlocAndTime]


    # DboDesign_StartDBBatchUpdate
    set lcount 0
    foreach lData $lDesignTime {

    if {$lcount == 0} {
    set lLastTime [split $lData ":"]
    incr lcount
    }
    # puts $lData
    if {$lcount > 0} {
    set lLastHr [lindex $lLastTime 0]
    set lLastMins [lindex $lLastTime 1]
    set lLastSec [lindex $lLastTime 2]
    set lDesignTm [split $lData ":"]
    set lDesignHr [lindex $lDesignTm 0]
    set lDesignMins [lindex $lDesignTm 1]
    set lDesignSec [lindex $lDesignTm 2]
    }

    if {$lLastHr > $lDesignHr} {

    # puts $lData
    set lLastTime [split $lData ":"]

    }
    if {$lLastHr == $lDesignHr} {

    # puts $lData
    if {$lLastMins > $lDesignMins} {
    set lLastTime [split $lData ":"]
    }

    if {$lLastMins == $lDesignMins} {
    if {$lLastSec > $lDesignSec} {
    set lLastTime [split $lData ":"]
    }
    }
    }
    }

    set lLastDesignTime [join $lLastTime ":"]
    # puts $lLastDesignTime
    # puts $lDesignTime
    set lTimeIndex [lsearch $lDesignTime $lLastDesignTime]
    # puts $lTimeIndex
    set lDesignfromIndex [lindex $lDesignloc $lTimeIndex]
    # ui::PMActivate "$lDesignloc"
    set lDesgnLoc [split $lDesignfromIndex "\\"]

    set lDesignName [lindex $lDesgnLoc [expr { [llength $lDesgnLoc] - 1}]]

    if {$lDesignfromIndex != ""} {
    ui::PMActivate "$lDesignfromIndex"
    puts "/$lDesignName"
    Menu "File::Save"
    Menu "File::Close"
    }

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

    Morgan 

    I tried in SPB24.1 and it is working as expected.

    I have modified the code a little bit let check if it works for you or not?

    # Get last design open and close it
    set lDesignNameCs [DboTclHelper_sMakeCString]
    set lSession $::DboSession_s_pDboSession
    DboSession -this $lSession
    set lStatus [DboState]
    set sep ","
    set lDesignTime {}
    set lDesignloc {}
    set lDesignsIter [$lSession NewDesignsIter $lStatus]
    #get the first design
    set lDesign [$lDesignsIter NextDesign $lStatus]
    set lNullObj NULL
    while { $lDesign!= $lNullObj} {
    #placeholder: do your processing on $lDesign
    # puts $lDesign
    $lDesign GetName $lDesignNameCs
    set lDesignName [DboTclHelper_sGetConstCharPtr $lDesignNameCs]
    set lFileTime [file atime $lDesignName]
    set ldesignFileTime "[clock format $lFileTime -format %H:%M:%S]"

    lappend lDesignloc $lDesignName
    lappend lDesignTime $ldesignFileTime

    set lDesign [$lDesignsIter NextDesign $lStatus]

    }
    delete_DboSessionDesignsIter $lDesignsIter


    # foreach lDesgTime $

    # puts [llength $designlocAndTime]


    # DboDesign_StartDBBatchUpdate
    set lcount 0
    foreach lData $lDesignTime {

    if {$lcount == 0} {
    set lLastTime [split $lData ":"]
    incr lcount
    }
    # puts $lData
    if {$lcount > 0} {
    set lLastHr [lindex $lLastTime 0]
    set lLastMins [lindex $lLastTime 1]
    set lLastSec [lindex $lLastTime 2]
    set lDesignTm [split $lData ":"]
    set lDesignHr [lindex $lDesignTm 0]
    set lDesignMins [lindex $lDesignTm 1]
    set lDesignSec [lindex $lDesignTm 2]
    }

    if {$lLastHr > $lDesignHr} {

    # puts $lData
    set lLastTime [split $lData ":"]

    }
    if {$lLastHr == $lDesignHr} {

    # puts $lData
    if {$lLastMins > $lDesignMins} {
    set lLastTime [split $lData ":"]
    }

    if {$lLastMins == $lDesignMins} {
    if {$lLastSec > $lDesignSec} {
    set lLastTime [split $lData ":"]
    }
    }
    }
    }

    set lLastDesignTime [join $lLastTime ":"]
    # puts $lLastDesignTime
    # puts $lDesignTime
    set lTimeIndex [lsearch $lDesignTime $lLastDesignTime]
    # puts $lTimeIndex
    set lDesignfromIndex [lindex $lDesignloc $lTimeIndex]
    # ui::PMActivate "$lDesignloc"
    set lDesgnLoc [split $lDesignfromIndex "\\"]

    set lDesignName [lindex $lDesgnLoc [expr { [llength $lDesgnLoc] - 1}]]

    if {$lDesignfromIndex != ""} {
    ui::PMActivate "$lDesignfromIndex"
    puts "/$lDesignName"
    Menu "File::Save"
    Menu "File::Close"
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Morgan
    0 Morgan 5 months ago in reply to CadAP

    Hi CadAP, 

    I use V24.1, and open 5 dsn files.

    With your code, it just process the time minimum dsn file, if I modify variable lTimeIndex, such as "set lTimeIndex 3", the code always not work(can't switch to that dsn window), and if I add SelectPMItem "./$lDesignName" after ui::PMActivate, if always fail and print message:RuntimeError Item Not Found.

    The last few lines of code I modified were:

    #set lTimeIndex [lsearch $lDesignTime $lLastDesignTime]
    set lTimeIndex 3
    # puts $lTimeIndex
    set lDesignfromIndex [lindex $lDesignloc $lTimeIndex]
    # ui::PMActivate "$lDesignloc"
    set lDesgnLoc [split $lDesignfromIndex "\\"]
    set lDesignName [lindex $lDesgnLoc [expr { [llength $lDesgnLoc] - 1}]]

    if {$lDesignfromIndex != ""} {
    ui::PMActivate "$lDesignfromIndex"
    SelectPMItem "./$lDesignName"
    puts "/$lDesignName"

    catch the SelectPMItem message, print like this:

    So the issue is, can't process other dsn file name but the time minimum one, can you help me solve the problem?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • CadAP
    0 CadAP 5 months ago in reply to Morgan

    HI Morgan,

    Please dump list value "$lDesignloc", then check correct output is stored in the variable "lDesignfromIndex".

    Also check "lDesignName" variable is storing correct value.

    I think somewhere variable are messing up with the values.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Morgan
    0 Morgan 5 months ago in reply to CadAP

    Hi CadAP, 

    When I puts this 3 variable, see command log as follows, Looks like nothing is wrong.

    Now "set lTimeIndex 4", get the dsn name T5.DSN, but Actually PMActivate the dsn file T3, and SelectPMItem it failed.

    #this is command log

    Capture> source [file normalize {G:/Cadence/Work/GetLastOpenedProject.tcl}]
    lDesignloc: {G:\CADENCE\WORK\TEST\T1.DSN} {G:\CADENCE\WORK\TEST\T2.DSN} {G:\CADENCE\WORK\TEST\T3.DSN} {G:\CADENCE\WORK\TEST\T4.DSN} {G:\CADENCE\WORK\TEST\T5.DSN}
    lDesgnLoc: G: CADENCE WORK TEST T5.DSN
    lDesignfromIndex: G:\CADENCE\WORK\TEST\T5.DSN
    lDesignName: T5.DSN

    Capture> ui::PMActivate "G:/CADENCE/WORK/TEST/T3.opj"
    Capture> [ 1]RuntimeError Item Not Found

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Morgan
    0 Morgan 5 months ago in reply to CadAP

    Hi CadAP,

    I puts this 3 variable, all the values look like not wrong.

    Now "set lTimeIndex 4", get the lDesignName T5.DSN, but Actually PMActivate file T3, and SelectPMItem failed.

    #the command log as below:

    Capture> source [file normalize {G:/Cadence/Work/GetLastOpenedProject.tcl}]
    lDesignloc: {G:\CADENCE\WORK\TEST\T1.DSN} {G:\CADENCE\WORK\TEST\T2.DSN} {G:\CADENCE\WORK\TEST\T3.DSN} {G:\CADENCE\WORK\TEST\T4.DSN} {G:\CADENCE\WORK\TEST\T5.DSN}
    lDesgnLoc: G: CADENCE WORK TEST T5.DSN
    lDesignfromIndex: G:\CADENCE\WORK\TEST\T5.DSN
    lDesignName: T5.DSN

    Capture> ui::PMActivate "G:/CADENCE/WORK/TEST/T3.opj"
    Capture> [ 1]RuntimeError Item Not Found

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Morgan
    0 Morgan 5 months ago in reply to CadAP

    Hi CadAP,

    I puts this 3 variable, all the values look like not wrong.

    Now "set lTimeIndex 4", get the lDesignName T5.DSN, but Actually PMActivate file T3, and SelectPMItem failed.

    #the command log as below:

    Capture> source [file normalize {G:/Cadence/Work/GetLastOpenedProject.tcl}]
    lDesignloc: {G:\CADENCE\WORK\TEST\T1.DSN} {G:\CADENCE\WORK\TEST\T2.DSN} {G:\CADENCE\WORK\TEST\T3.DSN} {G:\CADENCE\WORK\TEST\T4.DSN} {G:\CADENCE\WORK\TEST\T5.DSN}
    lDesgnLoc: G: CADENCE WORK TEST T5.DSN
    lDesignfromIndex: G:\CADENCE\WORK\TEST\T5.DSN
    lDesignName: T5.DSN

    Capture> ui::PMActivate "G:/CADENCE/WORK/TEST/T3.opj"
    Capture> [ 1]RuntimeError Item Not Found

    • 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