search a componet using loop
Hi All,
I have changed Id of a component in hypermesh and i have a .csv file which contains component's Ids and their thicknesses. Now i want to search component,s id in .csv file and corrosponding thickness value from csv.
Can anyone tell me how to do this using tcl?
Thanks,
Sanket
Answers
-
If I understand correctly you want to search within CSV file from Hyperworks?
0 -
yes
0 -
Tcl can read/write/search within CSV file. And you can run Tcl script from Hyperworks.
So I think it's possible.
0 -
0
-
Hi
Example csv file:
CompId,Thickness
1001,1.0
1002,1.2
2001,2.0
2002,2.2
2004,2.5
This is a sample code
set myfile c:/afile.csv
set fpt [open $myfile]
set cont [string map {, ' ' \n ' '} [read $fpt]]
close $fpt
set MyCompId 2002
set Thickness [dict get $cont $MyCompId]
0 -
I am using nastran profile.
0 -
Tinh is already gave you the good example:-)
-Here is my example-
# Auto property creation #
*evaltclscript 'AutoPropertyCreate.tcl' 0;
*evaltclstring '::autoproperty::Main' 0;# Thickness update from CSV #
set ft {{'CSV Files' .csv} {'All Files' *}};
set fn [tk_getOpenFile -filetypes $ft];
set fh [open $fn r];
while {![eof $fh]} {
gets $fh line;
lassign [split $line ,] cid T;
if {[hm_entityinfo exist comps $cid -byid] == '1'} {
set pid [hm_getvalue comps id=$cid dataname=propertyid];
*setvalue props id=$pid PSHELL_T=$T;
}
}
close $fh;If you are not using PSHELL card, you have to change the attribute name.
0 -
0