TCL: elements linked to a node

Stéphane Combet
Stéphane Combet Altair Community Member
edited December 2023 in Community Q&A

Hello,

I am new to tcl.

I try to get in a list the IDs of elements linked to given nodes.

I don't understand why following commands (see attached picture) does not put any element ID as results of last command. I expected 1876489 1875679 1876470 187 5660.

Thank you!

image

Tagged:

Best Answer

Answers

  • Marc Arnold
    Marc Arnold
    Altair Employee
    edited November 2023 Answer ✓

    Hi, 

    can you try double quotes instead of single? 
    image

    Check out the help for the syntax:
    https://help.altair.com/hwdesktop/hwd/topics/reference/hm/_createmark.htm?zoom_highlight=createmark
    There are also some examples on the bottom of the page. 


    A little tip:
    You see in the bottom-left corner a message how many elements are selected after the *createmark command. 
    image

    That helps me to check immediately if it's working correctly. 

    Have fun with scripting! 

  • Michael Herve_21439
    Michael Herve_21439
    Altair Employee
    edited November 2023
    Hello @Stéphane Combet,

    In addition of Marc's proposal, you may try to use *findmark , and to find nodes attached to elements.

    Below is a video (the corresponding script can be retrieved from the comments) showing how to use it:

    https://youtu.be/t8NkIQC82Ks?si=Ye3RL0wWbk8TqRgJ

    Hope this helps,

    Michael

  • Stéphane Combet
    Stéphane Combet Altair Community Member
    edited November 2023

    Hi, 

    can you try double quotes instead of single? 
    image

    Check out the help for the syntax:
    https://help.altair.com/hwdesktop/hwd/topics/reference/hm/_createmark.htm?zoom_highlight=createmark
    There are also some examples on the bottom of the page. 


    A little tip:
    You see in the bottom-left corner a message how many elements are selected after the *createmark command. 
    image

    That helps me to check immediately if it's working correctly. 

    Have fun with scripting! 

    Thank you very much Marc, this was the point! double quote, not single.

    About syntax, I am sometimes in trouble with what is in the help.  For exemple on https://2021.help.altair.com/2021/hwdesktop/hwd/topics/reference/hm/_nodemarkaddtempmark.htm in the exemples there are parameters in parenthesis:

     *createmark(nodes,1) 100 101 102 103 This does not work in my case. I have to change this line coming from the online help to this:

     *createmark nodes 1 100 101 102 103 to make it works.

    Thanks for the tip by the way, really helpfull!

  • Stéphane Combet
    Stéphane Combet Altair Community Member
    edited November 2023

    Hello @Stéphane Combet,

    In addition of Marc's proposal, you may try to use *findmark , and to find nodes attached to elements.

    Below is a video (the corresponding script can be retrieved from the comments) showing how to use it:

    https://youtu.be/t8NkIQC82Ks?si=Ye3RL0wWbk8TqRgJ

    Hope this helps,

    Michael

    Thank you Michael. Good point with this function findmark, but I can't get what would be the benefit in my case? Anyway it's always good to have some short code tutorial like this one, thanks again.

  • Michael Herve_21439
    Michael Herve_21439
    Altair Employee
    edited November 2023

    Thank you Michael. Good point with this function findmark, but I can't get what would be the benefit in my case? Anyway it's always good to have some short code tutorial like this one, thanks again.

    Hello @Stéphane Combet

     

    you're right, there should be no added value in your case, maybe it will be more useful next time ;)

     

    Best Regards,

    Michael

  • Marc Arnold
    Marc Arnold
    Altair Employee
    edited November 2023

    Thank you very much Marc, this was the point! double quote, not single.

    About syntax, I am sometimes in trouble with what is in the help.  For exemple on https://2021.help.altair.com/2021/hwdesktop/hwd/topics/reference/hm/_nodemarkaddtempmark.htm in the exemples there are parameters in parenthesis:

     *createmark(nodes,1) 100 101 102 103 This does not work in my case. I have to change this line coming from the online help to this:

     *createmark nodes 1 100 101 102 103 to make it works.

    Thanks for the tip by the way, really helpfull!

    To be honest, I have never used parentheses in tcl, only square brackets or curly brackets. 

    If you notice strange behavior, you can check the newest documentation. Just replace the version in the link:

    https://2023.help.altair.com/2023/hwdesktop/hwd/topics/reference/hm/_nodemarkaddtempmark.htm 

    There is only the correct version:

    image

  • Stéphane Combet
    Stéphane Combet Altair Community Member
    edited November 2023

    Sorry to be so stupid, but I can't use the lists in a nice way... Syntax issues :(

    Why this leads to 9 elements selected:

    *createmark elems 1 "by node id" 20072267 20072268 20072271 20072273

    Whereas this leads to only 4 elements (those around the first node of the list $selectedNodes):

     *createmark elems 1 "by node id" $selectedNodes

    Thank you!

    image

  • Michael Herve_21439
    Michael Herve_21439
    Altair Employee
    edited November 2023

    Sorry to be so stupid, but I can't use the lists in a nice way... Syntax issues :(

    Why this leads to 9 elements selected:

    *createmark elems 1 "by node id" 20072267 20072268 20072271 20072273

    Whereas this leads to only 4 elements (those around the first node of the list $selectedNodes):

     *createmark elems 1 "by node id" $selectedNodes

    Thank you!

    image

    Hello again @Stéphane Combet ,

     

    you just experienced one tricky concept of *createmark ;)

    In its implementation, the command considers the output of $selectedNodes as separate arguments, and it takes only the first id of the node list

     

    To avoid it, every time you refer to a list in *createmark, you need to preceed it by the tcl command eval:

     

    eval *createmark elems 1 "by node id" $selectedNodes

     

    Hope this helps,

    Michael

  • Marc Arnold
    Marc Arnold
    Altair Employee
    edited November 2023

    Alternatively, you can write {*} in front of the variable you want to "write out":

    *createmark elems 1 "by node id" {*}$selectedNodes

    You have to check if the API expects a list or separate arguments. If you need seperate arguments and have a list variable, use {*} or the command from Michael. I guess Michael's answer is the safer choice :)

  • Stéphane Combet
    Stéphane Combet Altair Community Member
    edited November 2023

    @Michael Herve @Marc Arnold 

    Thanks!

    eval does not work in my case, {*} does.

  • Bhavik Sheth_21143
    Bhavik Sheth_21143 Altair Community Member
    edited December 2023

    Hi,

    Check below code to get element ID list.

    #Get attached ElementIDs of node 
     #TempNodesList (Node ID list)

    hm_markclear elements 2
    hm_markclear nodes 1
     hm_createmark nodes 1 $TempNodesList
    *findmark nodes 1 1 1 elements 0 2
    set elemIDList [hm_getmark elements 2]
    hm_markclear nodes 1
    hm_markclear elements 2