TCL script to load points and forces
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
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
}
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?
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.
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!
Before talking about your code, my question: how do you do with your loaded nodes? How to link to your mesh? your structure?