Script for component table i made is not taking component names with space. it is throwing an error. similarly i want to make it editable.

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

@tinh @Pandurang The Script for component table, i made is not taking component names with space. it is throwing an error. similarly i want to make it editable.

 

::hwtk::dialog .d -title 'Abaqus Component Table' 
set table [::hwtk::table [.d recess].table]
pack $table -fill both -expand true

$table columncreate cid -type int -text 'Comp ID'
$table columncreate cname -text 'Comp Name' 
$table columncreate cthk -type int -text 'Thickness' 
$table columncreate Mname -text 'Material Name' 
*createmark comps 1 displayed
set cmp [hm_getmark comps 1]
set lnd [hm_marklength comps 1]


for {set j 1} {$j <= $lnd} {incr j} {


foreach CMP $cmp {
set lm [hm_getcollectorname comps $CMP]
set thk [hm_getthickness comps $CMP]
set Pt [hm_getvalue comps id=$CMP dataname=propertyid]

if {$Pt==0} {

set values 'cid $CMP cthk {Not Assigned} cname $lm Mname {Not Assigned}';
    $table rowinsert end row$j -values $values
incr j
} elseif {$Pt!=0} {

set MaT [hm_getvalue props id=$Pt dataname=material.name]
*createmark materials 1 'by name' $MaT
set Mnd [hm_marklength mats 1]


if {$Mnd==0} {

set values 'cid $CMP cthk $thk cname $lm Mname {Not Assigned}';

    $table rowinsert end row$j -values $values
incr j
} elseif {$Mnd!=0} {
set values 'cid $CMP cthk $thk cname $lm Mname $MaT';

    $table rowinsert end row$j -values $values
incr j

}
}
}
}

.d post

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    Hi jouher,

     

    Try

     set values [list cid $CMP cthk {Not Assigned} cname $lm Mname {Not Assigned}];

    so as to suppress variable expansion, instead of

     set values 'cid $CMP cthk {Not Assigned} cname $lm Mname {Not Assigned}';

     

    Regards,

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    Thanks @akitoguc. But, it is displaying component name in table by removing space. But, I want the name to be as it is.

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    And please suggest me how to make it editable.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    You can remove spaces from component name by:

     set lm [string map {' ' ''} $lm]

    I think you can edit string in your hwtk::table widget by default. If you want to update the component name by editting its name in the table, you can do that by setting a callback procedure to a specific column as '-valueaccept' option:

     $w columncreate cname -text 'Comp Name' -valueaccept '::SetCompName %V %P'

    The callback procedure can be something like below:

     proc ::SetCompName { table value prev } {     # FIXME: add error handling code     *renamecollector comps $prev $value     return 1; }

    Hope  it helps.

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    Thanks @akitoguc. But still when i rename , it is throwing error.

     

    My code is:

     

    ::hwtk::dialog .d -title 'Abaqus Component Table' 
    set table [::hwtk::table [.d recess].table]
    pack $table -fill both -expand true

    $table columncreate cid -type int -text 'Comp ID'
    $table columncreate cname -text 'Comp Name' -valueaccept '::SetCompName %V %P'
    $table columncreate cthk -type int -text 'Thickness' 
    $table columncreate Mname -text 'Material Name' 
    *createmark comps 1 displayed
    set cmp [hm_getmark comps 1]
    set lnd [hm_marklength comps 1]


    proc ::SetCompName {table value prev } {
        # FIXME: add error handling code
        *renamecollector comps $prev $value
        return 1;
    }


    for {set j 1} {$j <= $lnd} {incr j} {


    foreach CMP $cmp {
    set lm [hm_getcollectorname comps $CMP]
    regsub -all {\s} $lm {} lm
    set thk [hm_getthickness comps $CMP]
    set Pt [hm_getvalue comps id=$CMP dataname=propertyid]

    if {$Pt==0} {

    set values 'cid $CMP cthk {Not Assigned} cname $lm Mname {Not Assigned}';
        $table rowinsert end row$j -values $values
    incr j
    } elseif {$Pt!=0} {

    set MaT [hm_getvalue props id=$Pt dataname=material.name]
    *createmark materials 1 'by name' $MaT
    set Mnd [hm_marklength mats 1]


    if {$Mnd==0} {

    set values 'cid $CMP cthk $thk cname $lm Mname {Not Assigned}';

        $table rowinsert end row$j -values $values
    incr j
    } elseif {$Mnd!=0} {
    set values 'cid $CMP cthk $thk cname $lm Mname $MaT';

        $table rowinsert end row$j -values $values
    incr j

    }
    }
    }
    }

    .d post

    <?xml version="1.0" encoding="UTF-8"?>image.png

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    That's because of mismatch of component names; names in the table has spaces taken away, but components actually has names with spaces. Sorry I'm not clear on what you wnat to do.

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    @akitoguc I just want to rename component name

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    That's because of mismatch of component names; names in the table has spaces taken away, but components actually has names with spaces. Sorry I'm not clear on what you wnat to do.

    I just gave names without space and ran the script. Even then I cannot edit.

  • tinh
    tinh Altair Community Member
    edited May 2018

    why don't you use component table in Utility tab?

  • Pandurang
    Pandurang Altair Community Member
    edited May 2018

    @Jouher

     

    Please try this script ......I am able to change the name of comp through table

     

    ##########
    variable table;
    proc SetValueCallback {row col value } {
        variable table
        set id [$table cellget $row,cid]
        *setvalue comps id=$id name=$value
        return true
    }
    proc main {} {
            ::hwtk::dialog .d -title 'Abaqus Component Table' 
            set table [::hwtk::table [.d recess].table]
            pack $table -fill both -expand true
            $table columncreate cid -type int -text 'Comp ID'
            $table columncreate cname -text 'Comp Name' -validatecommand 'SetValueCallback %I %C %V'
            $table columncreate cthk -type int -text 'Thickness' 
            $table columncreate Mname -text 'Material Name' 


            *createmark comps 1 displayed
            set cmp [hm_getmark comps 1]
            set lnd [hm_marklength comps 1]

            for {set j 1} {$j <= $lnd} {incr j} {

            foreach CMP $cmp {
            set lm [hm_getcollectorname comps $CMP]
            set thk [hm_getthickness comps $CMP]
            set Pt [hm_getvalue comps id=$CMP dataname=propertyid]
            if {$Pt==0} {
            set values 'cid $CMP cthk {Not Assigned} cname $lm Mname {Not Assigned}';
                $table rowinsert end row$j -values $values
            incr j
            } elseif {$Pt!=0} {
            set MaT [hm_getvalue props id=$Pt dataname=material.name]
            *createmark materials 1 'by name' $MaT
            set Mnd [hm_marklength mats 1]

            if {$Mnd==0} {
            set values 'cid $CMP cthk $thk cname $lm Mname {Not Assigned}';
                $table rowinsert end row$j -values $values
            incr j
            } elseif {$Mnd!=0} {
            set values 'cid $CMP cthk $thk cname $lm Mname $MaT';
                $table rowinsert end row$j -values $values
            incr j
            }
            }
            }
            }
            .d post
    }
    main

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    why don't you use component table in Utility tab?

    @tinh Component table is not there in Abaqus profile.

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    @Jouher

     

    Please try this script ......I am able to change the name of comp through table

     

    ##########
    variable table;
    proc SetValueCallback {row col value } {
        variable table
        set id [$table cellget $row,cid]
        *setvalue comps id=$id name=$value
        return true
    }
    proc main {} {
            ::hwtk::dialog .d -title 'Abaqus Component Table' 
            set table [::hwtk::table [.d recess].table]
            pack $table -fill both -expand true
            $table columncreate cid -type int -text 'Comp ID'
            $table columncreate cname -text 'Comp Name' -validatecommand 'SetValueCallback %I %C %V'
            $table columncreate cthk -type int -text 'Thickness' 
            $table columncreate Mname -text 'Material Name' 


            *createmark comps 1 displayed
            set cmp [hm_getmark comps 1]
            set lnd [hm_marklength comps 1]

            for {set j 1} {$j <= $lnd} {incr j} {

            foreach CMP $cmp {
            set lm [hm_getcollectorname comps $CMP]
            set thk [hm_getthickness comps $CMP]
            set Pt [hm_getvalue comps id=$CMP dataname=propertyid]
            if {$Pt==0} {
            set values 'cid $CMP cthk {Not Assigned} cname $lm Mname {Not Assigned}';
                $table rowinsert end row$j -values $values
            incr j
            } elseif {$Pt!=0} {
            set MaT [hm_getvalue props id=$Pt dataname=material.name]
            *createmark materials 1 'by name' $MaT
            set Mnd [hm_marklength mats 1]

            if {$Mnd==0} {
            set values 'cid $CMP cthk $thk cname $lm Mname {Not Assigned}';
                $table rowinsert end row$j -values $values
            incr j
            } elseif {$Mnd!=0} {
            set values 'cid $CMP cthk $thk cname $lm Mname $MaT';
                $table rowinsert end row$j -values $values
            incr j
            }
            }
            }
            }
            .d post
    }
    main

    @Pandurang its throwing error. 

     

    <?xml version="1.0" encoding="UTF-8"?>image.png

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    @Pandurang its throwing error. 

     

    <?xml version="1.0" encoding="UTF-8"?>image.png

    Thanks @Pandurang I have solved the issue.

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    @tinh Currently as I am using regsub, component name is displayed omitting spaces. Please see the code.  I want to display name as it is .

    That is, cuurently, if i remove reg sub, it shows error whilte taking comp names with spaces.

  • tinh
    tinh Altair Community Member
    edited May 2018

    Hi Jouher

    it's due to these lines:

    set values 'cid $CMP cthk $thk cname $lm Mname {Not Assigned}';

     

    you should write:

    set values [list cid $CMP cthk $thk cname $lm Mname {Not Assigned}];

     

    so $lm with spaces will be preserved

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    @tinh Thanks Tinh, It works smoothly. Now, in the above codes what should be modified to add maximize, minimize and refresh button?

  • tinh
    tinh Altair Community Member
    edited May 2018

    Hi Jouher

    maybe hwtk:dialog will create a transient toplevel '.d'

    try using:

    wm transient .d {}

     

    or create window .d by

    toplevel .d

  • tinh
    tinh Altair Community Member
    edited May 2018

    to create a button:

    ::ttk:button .d.refresh -text Refresh -command p_RefreshTable

     

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    to create a button:

    ::ttk:button .d.refresh -text Refresh -command p_RefreshTable

     

    @tinh I have tried using

     

    set f [.d recess]
     hwtk::button $f.b1 -text 'Refresh' -command {MV}
    pack $f.b1 

     

    And it came. Now  I have doubt that what change or command should i add so that when i click refresh button, the table should get refreshed?

  • tinh
    tinh Altair Community Member
    edited May 2018

    maybe simply... delete your table and then recreate it!, if you don't know how to access its content :rolleyes:/emoticons/default_rolleyes.gif' title=':rolleyes:' />

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    maybe simply... delete your table and then recreate it!, if you don't know how to access its content :rolleyes:/emoticons/default_rolleyes.gif' title=':rolleyes:' />

    @tinhPlease tell me how to convert my material name and property name columns to combo box from above code.

  • tinh
    tinh Altair Community Member
    edited May 2018

    Hi Jouher

    maybe set -type combo 

    when creating table column

    $table columncreate Mname -text 'Material Name -type combo

     

    if it raises error, it will tell you which types are available

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    Hi Jouher

    maybe set -type combo 

    when creating table column

    $table columncreate Mname -text 'Material Name -type combo

     

    if it raises error, it will tell you which types are available

    Thanks @tinh. Drop down came for each row value by giving : '-type combobox'

     

    But, how to give values in that as per my code. Currently its blank. 

  • tinh
    tinh Altair Community Member
    edited May 2018

    Hi Jouher

    create that column with option 

    -valuelistcommand ::p_GetMaterialList

     

    and define the command to return list of mats

    ex:

    proc ::p_GetMaterialList args {

         hm_entitylist mats name

    }

  • Saumya4Mishra
    Saumya4Mishra Altair Community Member
    edited January 2019

    Hi,

     

    Can we have menu options in tk table? What i mean is can we right click on a cell and create menu buttons for it like modify, delete.

     

    Regards

    Saumya Mishra

  • tinh
    tinh Altair Community Member
    edited January 2019

    Sure, it can.

    Refer to TkTable page in Tcl/Tk docs

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited January 2019

    Hi @tinh, @Pandurang, @akitoguc & all,

     

    How to give right click edit option to each row. I checked the commands but didnt get or understand. Can you help by seeing the above code to explain how to add rightclick option.