Jump to content

Recommended Posts

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

Share this post


Link to post
Share on other sites

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]

vipin likes this

Share this post


Link to post
Share on other sites

@sanket_patil

 

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.

vipin likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×