Define Load via TCL Script by external file

Rahul_P1
Rahul_P1
Altair Employee
edited October 2020 in Community Q&A

Dear all,
i want to create forces on nodes via tcl script. Force components are defined by external file (load.csv).
The script does not work. Can anyone see the error in the script?

autoloadgen.tcl

set fp [open 'load.csv' r];
    
    while {![eof $fp]} {
    
        set x [gets $fp line]
            if {$x > 0} {
            set line [split $line ';'];
            set nodeid [lindex $line 0]
            set fx [lindex $line 1]
            set fy [lindex $line 2]
            set fz [lindex $line 3]
            set magn [lindex $line 4]
            }

*createmark nodes 1 $nodeid
*loadcreateonentity_curve nodes 1 1 1 $fx $fy $fz 0 0 $magn 0 0 0 0 0
    }
close $fp

load.csv

nodeid;fx;fy;fz;magn;
1553476;1000;1000;1000;1732.050808;

Best regards
kned

Tagged:

Answers

  • Rahul_P1
    Rahul_P1
    Altair Employee
    edited May 2015

    Hello,

    I think there might be two adaptions needed:
    1) The ',' delimiter needs to be used in the CSV file
    2) The *loadcreateonentity_curve nodes 1 1 1 0 1 $listx1 $listy1 $listz1 $listmagn 0 0 0 0 0 should be
    *loadcreateonentity_curve nodes 1 1 1 $listx1 $listy1 $listz1 $listmagn 0 0 0 0 0

    Then it will work correctly.
     

    By the way: the error in the original script comes from the Header in the CSV file. If you remove the Header nodeid;fx;fy;fz;magn, your original script will work as well.
    Jan

  • Rahul_P1
    Rahul_P1
    Altair Employee
    edited May 2015

    Many thanks!

    it works without header in the load file.