How to understand *createmark command with a tcl variable list?

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hello all,

From the help of *createmark command, it statements as follow:

 

*createmark entity_type mark_id '?option?' list

 

When specifying entity names that contain spaces, group the name using brackets, {Comp name with spaces}, or use a Tcl list.

 

When specifying the list using a Tcl variable, the eval Tcl command must precede the *createmark command (see example below). This expands (substitutes) the Tcl list before executing the command. It is also important to use brackets around any options that contain spaces when using eval (eval *createmark solids 1 {'by comp name'} $comp_names). Otherwise, the quotes will be expanded before the option reaches the *createmark command and it will not function as expected.

 

Why should we use eval command if we use a tcl list? That is to say what's the difference between with eval and without eval command?

 

set names

eval *createmark comps 1 $names  ; # with eval

*createmark comps 1 $names  ; # without eval

 

How to explain above two commands? Thank you

 

Roy

 

Answers

  • tinh
    tinh Altair Community Member
    edited November 2018

    Example names = 'comp1 comp2'

    With eval => *createmark comps 1 comp1 comp2

     

    Without eval => *createmark comps 1 'comp1 comp2'

    => cannot select comp1 and comp2

     

  • Vikas Kumar_22189
    Vikas Kumar_22189 Altair Community Member
    edited November 2018

    Hello Roy

    As tinh said without using eval command list variable value wont be expanded.

    You can understand this from below example:

     

    set cmd {puts 'Evaluating a puts'}
    puts 'CMD IS: $cmd' ; # O/P - CMD IS: puts 'Evaluating a puts'
    eval $cmd ; # O/P - Evaluating a puts

     

    Thanks, 

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited November 2018

    Example names = 'comp1 comp2'

    With eval => *createmark comps 1 comp1 comp2

     

    Without eval => *createmark comps 1 'comp1 comp2'

    => cannot select comp1 and comp2

     

    Hi @tinh and @Vikas Kumar

    set names 'comp1 comp2'

    *createmark comps 1 $names

    with eval command, I can understand the statement is: *createmark comps 1 comp1 comp2

    However, without eval command, why the statement is: *createmark comps 1 'comp1 comp2'    why there exist quotes? I think the value of names is comp1 comp2. How to understand?

     

    Roy

  • tinh
    tinh Altair Community Member
    edited November 2018

    Without eval, tcl just subtitutes $names by 'comp1 comp2' so that is reason

    With eval, 'eval' command will subtitute once more.

    You should learn basic Tcl language first. It is explained in tcl docs

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited November 2018

    Without eval, tcl just substitutes $names by 'comp1 comp2' so that is reason

    With eval, 'eval' command will subtitute once more.

    You should learn basic Tcl language first. It is explained in tcl docs

    Hi @tinh,

    As I know, with eval command, the order of execution is: First, substitute the variable value, and then if it is a valid tcl command, execute it. 

    So I think the execution order for the statement: eval *createmark comps 1 $names 

    First: eval *createmark comps 1 comp1 comp2

    Then: *createmark comps 1 comp1 comp2

     

    I haven't understood your saying ''eval' command will subtitute once more'.

     

    Thank you 

    Roy

  • tinh
    tinh Altair Community Member
    edited November 2018

    First: eval *createmark comps 1 'comp1 comp2'

    Then: *createmark comps comp1 comp2