🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

TCL script to load points and forces

User: "Altair Forum User"
Altair Employee
Updated by Altair Forum User

Hi,

 

I am making a TCL script to import a CSV file in Altair HyperMesh. The CSV file contains 7 columns (x-coordinate, y-coordinate, z-coordinate, x-force, y-force, z-force and resultant force). The idea is to run the script, the nodes are created on the coordinates given in the first 3 columns, the node is selected, a force is created on the selected note. (This should run through all the rows of the csv file.)

The code I have until now is the following:

 

lappend auto_path 'C:/Program Files/Altair/2017/hw/tcl/tcllib-1.19/modules'

package require csv
package require struct::matrix

set data [::struct::matrix]
$data add rows 16
$data add columns 7
set csvfile [open 'coordinates-forces.csv']
csv::read2matrix $csvfile data  , auto 
close $csvfile

set rows [data rows]

for {set i 0} {$i < $rows} {incr i} {
*createnode [data get cell 0 i] [data get cell 1 i] [data get cell 2 i]
*createmark nodes 1 i
*loadcreateonentity_curve nodes i 1 1 {data get cell 4 i} {data get cell 5 i} {data get cell 6 i} 0 0 {data get cell 7 i} 0 0 0 0 0
}

 

The error I currently get is 'invalid command name 'data''. Any help would be appeciated.

 

Thanks in advance!

Philip

Find more posts tagged with

Sort by:
1 - 13 of 131
    User: "QuyNguyenDai"
    Altair Community Member
    Updated by QuyNguyenDai

    Before talking about your code, my question: how do you do with your loaded nodes? How to link to your mesh? your structure?

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    The loaded nodes will be linked to the mesh with RBE2 or RBE3 elements (depending on the type of load). These will, for now, be implemented manually afterwards.

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Use $data instead of data

    Use [ ] instead of { }

     

    I think a simpler code can do , don't need structmatrix package, it just messes up your codes

     

    set fpt [open 'coordinates-forces.csv']

    set buf [read -nonewline $fpt]

    close $fpt

    foreach line [split $buf \n] {

       lassign [split $line ,] x y z fx fy fz f

       CreateNode

        CreateForce

    }

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Okay, so trying the simpler code you provided above, I still get an error.

     

    foreach line [split $buf \n] {
    lassign [split $line] x y z fx fy fz f
    *createnode $x $y $z
    *createmark nodes 1 1
    *loadcreateonentity_curve nodes 1 1 1 $fx $fy $fz 0 0 $f 0 0 0 0 0
    }

     

    The reason I put [split $line] is because it is actually separated with a semicolon, so a comma wouldn't work.

    The error I get is the following: extra characters after close-quote.

    I would assume that there might be a problem with the '{' after the foreach command, but I'm not sure.

     

    Any advice?

     

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Take a screenshot about the error please

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    You can find the error attached.

    <?xml version="1.0" encoding="UTF-8"?>Screenshot.PNG

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Did you copy code from webbrowser then paste to text editor?

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Yeah at first I did. Now, I typed it in myself and it actually gives me another error.

    Note that now, I created an extra variable $n to show on which node the force needs to be applied. I checked it in the command file and this should actually work. But, I don't really understand the error showing up now.

    <?xml version="1.0" encoding="UTF-8"?>Screenshot2.PNG

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Use *createmark nodes 1 -1

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    What the script does now is creating a node at 0 0 0 and a force on that node with components 0 0 0. My test csv file doesn't contain this node, nor a zero force.

    I'm not sure what's wrong here?

    User: "tinh"
    Altair Community Member
    Updated by tinh

    to debug, try running with a short csv file , maybe 5 lines

     

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    I have debugged it! There were some minor errors like \n instead of '\n' and the semicolon separator {;} in the split command. For those of you wondering what the final code looks like, you can find it beneath.

    Note: I've added a line to create a loadcollector for each created force.

     

    Thanks for the help tinh!

    <?xml version="1.0" encoding="UTF-8"?>Screenshot4.PNG

    User: "tinh"
    Altair Community Member
    Updated by tinh

    \n instead of '\n'

     

    I don't think so. Actually \n and '\n' are the same. Anyway, gòod job