search a componet using loop

User: "sanket_patil"
Altair Community Member
Updated by sanket_patil

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

Find more posts tagged with

Sort by:
1 - 8 of 81
    User: "QuyNguyenDai"
    Altair Community Member
    Updated by QuyNguyenDai

    If I understand correctly you want to search within CSV file from Hyperworks?

     

    User: "sanket_patil"
    Altair Community Member
    OP
    Updated by sanket_patil

    @Nguyen-Dai

     yes

    User: "QuyNguyenDai"
    Altair Community Member
    Updated by QuyNguyenDai

    Tcl can read/write/search within CSV file. And you can run Tcl script from Hyperworks.

    So I think it's possible.

    User: "Imoto"
    Altair Employee
    Updated by Imoto

    @sanket_patil

     

    Yes it is possible with Tcl.

    Which solver(User profile) are you using?

     

    Thanks,

    Imoto

    User: "tinh"
    Altair Community Member
    Updated by tinh

    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]

    User: "sanket_patil"
    Altair Community Member
    OP
    Updated by sanket_patil

    @imoto

    I am using nastran profile.

    User: "Imoto"
    Altair Employee
    Updated by Imoto

    @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.

    User: "sanket_patil"
    Altair Community Member
    OP
    Updated by sanket_patil

    @imoto @tinh @Nguyen-Dai

     Thank you so much for help. It is working good.

     

    Regards,

    Sanket