selecting nodes depending on their coordinates

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

Hello,

I'm a new user of tcl languaje and HyperMesh macros, and I have a problem selecting nodes in a tcl script.

I want to create a list with nodes depending on their coordinates. For example, I want to create a list with nodes that fulfills these conditions:

0< x < 5 && 3 < y < 6 && z == 0

(the nodes that the coordinate x have between 0 and 5, and the coordinate y between 3 and 6 and the coordinate z = 0).

Is it necessary to obtain a matrix with the coordinates x, y and z of all the nodes? How can I do that in a simple way? Is there any specific command for that?

Thanks in advance

Looking forward to for your help

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2012

    Hi,

    try the following command:

    SYNTAX

    *createmark entity_type mark_id '?option?' list

    entity_type = nodes

    mark_id = 1 or 2

    '?option?' =

    'by box' x0 y0 z0 x1 y1 z1 syst location contained all tol

    Place entities on mark_id if they are inside/outside/on the boundary of the box.

    x0 – lower bound x coordinate

    y0 – lower bound y coordinate

    z0 – lower bound z coordinate

    x1 – upper bound x coordinate

    y1 – upper bound y coordinate

    z1 – upper bound z coordinate

    syst – the ID of a local coordinate system to which the coordinate bounds are relative to. If 0, the global axes are used.

    location – The location of the entities to find, relative to the shape. Valid values are inside, outside and boundary.

    contained – A flag that indicates whether the entire entity should meet the location criteria (1) or just any part of the entity (0) to be selected.

    all – A flag that indicates whether all entities (1) or only displayed entities (0) are considered for selection.

    tol – The tolerance to use. In most cases, this should be set to 0.

    This is currently supported for nodes, elements, components (FE only), loads, equations, loadcols, systems, systcols, vectors, vectorcols and contactsurfs.

    Take a look at HW11 help file (Desktop User's Guide)

    Regards,

    Mario

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2012

    Hi Mario,

    Thanks for your answer. The command you recommend looks good, but it doesn't work in my tcl. This is the part where I want to do that (below), but Hypermesh displays an error message 'Nodes have not been selected'.

    Is it possible that this commad doesn't work with nodes in the same plane? I mean, it can be because z1bb = z2bb?? I don't think so, but it can be possible. It doen't work even with a tolerance of 0.2

    Is there any other possibilities for doing this??

    Thanks in advande,

    *createmarkpanel nodes 1 'Select one node';

    set node_list_1b [hm_getmark nodes 1];

    if { ! [ Null node_list_1b ] } {

    set nodeId1b [ lindex $node_list_1b 0 ]

    set x1b [ hm_getentityvalue NODES $nodeId1b 'x' 0 ]

    set y1b [ hm_getentityvalue NODES $nodeId1b 'y' 0 ]

    set z1b [ hm_getentityvalue NODES $nodeId1b 'z' 0 ]

    }

    *createmarkpanel nodes 2 'Select the second node';

    set node_list_2b [hm_getmark nodes 2];

    if { ! [ Null node_list_2b ] } {

    set nodeId2b [ lindex $node_list_2b 0 ]

    set x2b [ hm_getentityvalue NODES $nodeId2b 'x' 0 ]

    set y2b [ hm_getentityvalue NODES $nodeId2b 'y' 0 ]

    set z2b [ hm_getentityvalue NODES $nodeId2b 'z' 0 ]

    }

    *clearmark nodes 1;

    *clearmark nodes 2;

    if {$x1b < $x2b} {

    set x1bb $x1b

    set x2bb $x2b

    } else {

    set x1bb $x2b

    set x2bb $x1b

    }

    if {$y1b < $y2b} {

    set y1bb $y1b

    set y2bb $y2b

    } else {

    set y1bb $y2b

    set y2bb $y1b

    }

    if {$z1b < $z2b} {

    set z1bb $z1b

    set z2bb $z2b

    } else {

    set z1bb $z2b

    set z2bb $z1b

    }

    *createmark nodes 1 'by box' '$x1bb $y1bb $z1bb $x2bb $y2bb $z2bb 0 inside 0 1 0'

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2012

    Hi mgoiogana,

    sometimes there are still small bugs... ;-)

    try:

    *createmark nodes 1 'by box' $x1bb $y1bb $z1bb $x2bb $y2bb $z2bb 0 inside 0 1 0

    without the second ''

    Regards

    Mario

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2012

    Hi Mario,

    That was not the problem. I've tried with the second '' and without the second '', but the result is the same, the problem remains: 'Nodes have not been selected!'

    and the same happens with:

    hm_createmark nodes 1 'by box' $x1bb $y1bb $z1bb $x2bb $y2bb $z2bb 0 inside 0 1 0

    or:

    hm_createmark nodes 1 'by box' '$x1bb $y1bb $z1bb $x2bb $y2bb $z2bb 0 inside 0 1 0'

    I don't know what the reason is. I'll try to look for any other command, because I think that this new command doesn't work very well.

    Let's see what we can do...

    Anyway, thaks with your help.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2012

    Hi,

    i have tried it with exactly your code and it works without the quotes...

    You can't see the marked nodes of course, only the message:

    24 nodes added. Total selected 24

    My system: HW11, Patches 120, 230, 402

    Regards,

    Mario

    PS: Debug the selection (2 diagonal nodes for the Box of course), i take: tk_messageBox -message 'x1bb : $x1bb'

    I have used *createmark, not hm_createmark

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited July 2012

    Hi all,

    I found this topic, which almost explained my problem with a macro for applying pressures on ship shells.

    However, I cannot make the part with *createmark elems working.

    The part of the script I'm using is like this:

    *createmark elements 1 'by box' $minX $minY $minZ $maxX $maxY $diff 0 inside 0 1 0

    Where $minX, $maxX etc... are formerly received minimum and maximum coordinates of the component i want to apply pressure on, and $diff is the Z coord. corresponding to the water level.

    The problem is that the 'by box' option keeps selecting all of the elements in component, while it should select only those inside the bounding box.

    It also happens when I put the bounds manually (straight numbers) or if I use the macro above (by MGOIOGANA) with nodes selecting.

    Can anyone tell me what's causing this? There is no explanation of the 'by box' option in HW11 help...

    Thanks in advance.

    Regards,

    Peter

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited July 2015

    use eval command before *createmark and put 'by box' inside curly brackets { }

    the final code should look something like this:


    eval *createmark option mark_id {'by box'} x0 y0 z0 x1 y1 z1 syst location contained all tol

    Good luck,