search a componet using loop

sanket_patil
sanket_patil Altair Community Member
edited October 2020 in Community Q&A

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

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited February 2019

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

     

  • sanket_patil
    sanket_patil Altair Community Member
    edited February 2019

    @Nguyen-Dai

     yes

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited February 2019

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

    So I think it's possible.

  • imoto
    imoto
    Altair Employee
    edited February 2019

    @sanket_patil

     

    Yes it is possible with Tcl.

    Which solver(User profile) are you using?

     

    Thanks,

    Imoto

  • tinh
    tinh Altair Community Member
    edited February 2019

    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]

  • sanket_patil
    sanket_patil Altair Community Member
    edited February 2019

    @imoto

    I am using nastran profile.

  • imoto
    imoto
    Altair Employee
    edited February 2019

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

  • sanket_patil
    sanket_patil Altair Community Member
    edited February 2019

    @imoto @tinh @Nguyen-Dai

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

     

    Regards,

    Sanket