How to understand *createmark command with a tcl variable list?
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
-
Example names = 'comp1 comp2'
With eval => *createmark comps 1 comp1 comp2
Without eval => *createmark comps 1 'comp1 comp2'
=> cannot select comp1 and comp2
0 -
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 putsThanks,
0 -
Altair Forum User said:
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
0 -
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
0 -
Altair Forum User said:
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
0 -
First: eval *createmark comps 1 'comp1 comp2'
Then: *createmark comps 1 comp1 comp2
0