Jump to content
sanket_patil

search a componet using loop

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...