TCL script : need help

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Dear Sir,

I am Begineer to TCL scripting. need small help

actually i am developing a small script i.e 

lets say i have few components with naming like COMPNAME_MATNAME_Txx.  this script will read COMPNAME & and it will create a PSHELL property with thickness (xx) with same name. and also it will read MATNAME and it will create material with same name.

 

Q) i want split the original compname & matname and assign to some variable like this :    set thickness [string trimleft [lindex [split $comp_name _] end] t]

how to do this one?

I have done with simple commands like (string range).please refer below picture

 

 

Thank you,

Regards,

Gopi

<?xml version="1.0" encoding="UTF-8"?>ref macro.JPG

Answers

  • tinh
    tinh Altair Community Member
    edited December 2018

    Hi

    Suppose there are only 3 '_' in the name.

    regexp -nocase {^([^_]+)_([^_]+)_t(.+)$} $comp_name = CompName MatName Thickness

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited December 2018

    Hi

    Suppose there are only 3 '_' in the name.

    regexp -nocase {^([^_]+)_([^_]+)_t(.+)$} $comp_name = CompName MatName Thickness

    Thanks for your quick reply.

    yeah i want to split according  '_ . (underscore)

    but how to assign to different variable using above logic?

    i want to do like this:  set compname xxxxxxx(logic) 

                                          set matname xxxxxxxx(logic)

                                         set thickness [string trimleft [lindex [split $comp_name _] end] t]

    getting some error please check below pic

    <?xml version="1.0" encoding="UTF-8"?>command.JPG

  • tinh
    tinh Altair Community Member
    edited December 2018

    Do you copy and paste my command?

    :rolleyes:/emoticons/default_rolleyes.gif' title=':rolleyes:' />

  • tinh
    tinh Altair Community Member
    edited December 2018

    Please type it as it is, from regexp to the end, don't miss any character, you will get CompName MatName and Thickness

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2019

    Please type it as it is, from regexp to the end, don't miss any character, you will get CompName MatName and Thickness

    Hi ,

    I tried with below command but did not get comp mat and thickness names.

    regexp -nocase {^([^_]+)_([^_]+)_t(.+)$} $comp_name

    can suggest me another method to split this (ex:comp1_mat1_txx). I want to split this onto three different parts i.e comp1, mat1, & xx (thickness value)

     

    thanks in advance 

  • tinh
    tinh Altair Community Member
    edited January 2019

    You can use split, lassing, string range commands to do it.

    Regexp will do it in 1 invocation.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2019

    You can use split, lassing, string range commands to do it.

    Regexp will do it in 1 invocation.

    Yeah it is very useful command. Successfully done.

    Thanks @tinh