How to automatically create a set of Plotel

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

Hello,

hope somoen can help with this topic which looks like simple but is making me crazy...

 

I'm trying to write a TCL script to create, from a set of three nodes (which should be selected by the user, let's call them Node_1, Node_2, Node_3):

- 1 PLOTEL from Node_1 to Node_2

- 1 PLOTEL from Node_1 to Node_3

- 1 PLOTEL from Node_1 to a new one (Node_4) which should be created by the macro itself, on a (ideal) line passing through Node_1 and orthogonal to the plane defined by Node_1 + Node_2 + Node_3

 

I'm quite new to tcl, so I started from having a look around on the web and some trial and error by looking at the command.cmf file.

 

Here is what I am at:

#set nodeList [hm_getmark nodes 1]
*createlistpanel nodes 1 'Select the ordered nodes'
set nodeList [hm_getlist nodes 1]

set Node_1 [lindex $nodeList 0]
set
Node_2 [lindex $nodeList 1]
set
Node_3 [lindex $nodeList 2]

*createspotweld $
Node_1 $Node_2 0 0 0 0 0 2 '';
*createspotweld $
Node_1 $Node_3 0 0 0 0 0 2 '';

 

So far I've created the first two PLOTEL belonging to the Node_1 + Node_2 + Node_3 plane.

 

Now I should try to understand which is the normal direction. I tried to look at the command.cmf script for similar functions (i.e., when translating nodes and selecting three nodes to define the direction) but to my surprise I discovered that Hypermesh someway computes the components of the normal and uses them.

It is not such a big effort, it is a matter of computing a vectorial product and its components.

 

Let a1, a2, a3 be the components of the first vector (From Node_1 to Node_2) and b1, b2, b3 the components of the second one (from Node_2 to Node_3)

The components of the normal vector will be:

   x_n=a2b3-a3b2

   y_n=a1b3-a3b1

   z_n=a1b2-a2b1

 

Once I have the components above I should create the new Node_4 by translating Node_1 along the normal vector.

Could you please help me with the rest of the program?

 

Thanks in advance

 

Alex

Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited March 2013

    Hi Alex

    you're right. Because command.cmf just includes modified commands (* command) , not query commands. Let's continue your script

     

    foreach Node {Node1 Node2 Node3} {

    #get node coordinates

       set ${Node}_xyz [expr [hm_nodevalue [set $Node]]]

    }

    #calculate vectors

      set vector12 [list [expr [lindex $Node2_xyz 0] - [lindex $Node1_xyz 0]] \

                         [expr [lindex $Node2_xyz 1] - [lindex $Node1_xyz 1]] \

                         [expr [lindex $Node2_xyz 2] - [lindex $Node1_xyz 2]]]

     

      set vector13 [list [expr [lindex $Node3_xyz 0] - [lindex $Node1_xyz 0]] \

                         [expr [lindex $Node3_xyz 1] - [lindex $Node1_xyz 1]] \

                         [expr [lindex $Node3_xyz 2] - [lindex $Node1_xyz 2]]]

     foreach {a1 a2 a3} $vector12 {break}

     foreach {b1 b2 b3} $vector13 {break}

     

       set x_n [expr $a2*$b3-$a3*$b2]

       set y_n [expr $a1*$b3-$a3*$b1]

       set z_n [expr $a1*$b2-$a2*$b1]

    #now you can create vector and translate node

    *createmark nodes 1 $Node1

    *duplicatemark nodes 1 25

    set Node4 [hm_entitymaxid nodes]

    *createvector 1 $x_n $y_n $z_n

    *translatemark nodes 1 1 10

    *createspotweld $Node1 $Node4 0 0 0 0 0 2 ''

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2013

    Great!

    Thanks a lot tinh!

    In the meanwhile I had found a less efficient and elegant way than yours.

    Here it is:

    *createlistpanel nodes 1 'Select the ordered nodes'
    set nodeList [hm_getlist nodes 1]

    set n1 [lindex $nodeList 0]
    set n2 [lindex $nodeList 1]
    set n3 [lindex $nodeList 2]

    set n1x [ hm_getentityvalue NODES $n1 'x' 0 ]
    set n1y [ hm_getentityvalue NODES $n1 'y' 0 ]
    set n1z [ hm_getentityvalue NODES $n1 'z' 0 ]
    set n2x [ hm_getentityvalue NODES $n2 'x' 0 ]
    set n2y [ hm_getentityvalue NODES $n2 'y' 0 ]
    set n2z [ hm_getentityvalue NODES $n2 'z' 0 ]
    set n3x [ hm_getentityvalue NODES $n3 'x' 0 ]
    set n3y [ hm_getentityvalue NODES $n3 'y' 0 ]
    set n3z [ hm_getentityvalue NODES $n3 'z' 0 ]

    set vec1x [expr $n2x - $n1x]
    set vec1y [expr $n2y - $n1y]
    set vec1z [expr $n2z - $n1z]
    set vec2x [expr $n3x - $n2x]                 
    set vec2y [expr $n3y - $n2y]                 
    set vec2z [expr $n3z - $n2z]                 
                                                 
    set vecx [expr $vec1y*$vec2z - $vec1z*$vec2y]
    set vecy [expr $vec1z*$vec2x - $vec1x*$vec2z]
    set vecz [expr $vec1x*$vec2y - $vec1y*$vec2x]

    *createvector 1 $vecx $vecy $vecz

    set nodes1 '';
    set nodes2 '';
    set maxid1 '';
    set maxid2 '';

    *createmark nodes 1 $n1
    *duplicatemark nodes 1 25
    set n4 [hm_entitymaxid nodes]
    *createmark nodes 1 $n4
    *translatemark nodes 1 1 5

    *createspotweld $n1 $n2 0 0 0 0 0 2 '';
    *createspotweld $n1 $n3 0 0 0 0 0 2 '';
    *createspotweld $n1 $n4 0 0 0 0 0 2 '';

    *nodecleartempmark

     

    Now I will test yours and will come back to you!

    Thanks again!

    Alex

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.