Jump to content
Jouher

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.

Recommended Posts

@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

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

image.png

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
3 minutes ago, akitoguc said:

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.

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites
8 hours ago, Pandurang said:

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

 

image.png

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
19 hours ago, tinh said:

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?

Share this post


Link to post
Share on other sites
16 hours ago, tinh said:

maybe simply... delete your table and then recreate it!, if you don't know how to access its content :rolleyes:

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
On 5/16/2018 at 5:16 PM, tinh said:

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. 

Share this post


Link to post
Share on other sites

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

}

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