I have a TCL script written here. I want to call a certain set created as Set1 and write it on the output.txt file. Can someone help how to write it in TCL? If there is an error in elem_set can it be rectified as well?

Adeline War_20893
Adeline War_20893 Altair Community Member
edited May 2023 in Community Q&A

cd E:/New_Folder
set outPath "E:/New_folder/output.txt"
set import_file_path "E:/New_folder/ads.h3d"
hwi OpenStack
hwi GetSessionHandle session
session GetProjectHandle project
project GetPageHandle page 1
page GetWindowHandle win 1
win SetClientType animation
win GetClientHandle anim
anim AddModel $import_file_path
set id [anim AddModel $import_file_path]
anim GetModelHandle myModel $id
myModel SetResult $import_file_path
anim Draw
myModel GetResultCtrlHandle myResult
set current [myResult GetCurrentSubcase]
myResult SetCurrentSimulation [expr [myResult GetNumberOfSimulations $current]-1]
set data_types [myResult GetDataTypeList $current]
myResult GetContourCtrlHandle myContour
myContour SetDataType [lindex $data_types 6]
myContour SetDataComponent == vonMises
myContour SetEnableState true
anim Draw
myModel GetQueryCtrlHandle myQuery
set set_id [myModel AddSelectionSet element]
myModel GetSelectionSetHandle mySet [myModel
AddSelectionSet element]
elem_set SetSelectMode 'displayed'
elem_set Add "component_name == PSOLID_3"
myModel GetQueryCtrlHandle myQuery
myQuery SetSelectionSet [Set1 GetID]
myQuery SetQuery "element.id contour.value"
myQuery WriteData $outPath
session ReleaseHandle
project ReleaseHandle
page ReleaseHandle
win ReleaseHandle
myModel ReleaseHandle
myResult ReleaseHandle
hwi CloseStack
exit

 

Answers

  • Adriano A. Koga
    Adriano A. Koga
    Altair Employee
    edited May 2023

    Try this mod version:

     

    cd "C:/_RUNNING/COMMUNITY"

    set outPath "C:/_RUNNING/COMMUNITY/output.txt"
    set import_file_path "C:/_RUNNING/COMMUNITY/Model.h3d"
    set set_name "Set1"


    hwi OpenStack
    hwi GetSessionHandle session
    session GetProjectHandle project
    project GetPageHandle page 1
    page GetWindowHandle win 1
    win SetClientType animation
    win GetClientHandle anim
    #anim AddModel $import_file_path
    set id [anim AddModel $import_file_path]
    anim GetModelHandle myModel $id
    myModel SetResult $import_file_path
    anim Draw
    myModel GetResultCtrlHandle myResult
    set current [myResult GetCurrentSubcase]
    myResult SetCurrentSimulation [expr [myResult GetNumberOfSimulations $current]-1]
    set data_types [myResult GetDataTypeList $current]
    myResult GetContourCtrlHandle myContour
    myContour SetDataType [lindex $data_types 6]
    myContour SetDataComponent == vonMises
    myContour SetEnableState true
    anim Draw


    set sets_list [myModel GetSelectionSetList "User_Set"]

    hwi OpenStack
    foreach seto $sets_list {
        myModel GetSelectionSetHandle mySet${seto} $seto
        set label [mySet${seto} GetLabel]
        if {$label == $set_name} {
            set set_id $seto
        }
    }
    hwi CloseStack

    myModel GetQueryCtrlHandle myQuery
    myQuery SetSelectionSet $set_id
    myQuery SetQuery "element.id contour.value"
    myQuery WriteData $outPath

    hwi CloseStack
    exit

  • Adeline War_20893
    Adeline War_20893 Altair Community Member
    edited May 2023

    Try this mod version:

     

    cd "C:/_RUNNING/COMMUNITY"

    set outPath "C:/_RUNNING/COMMUNITY/output.txt"
    set import_file_path "C:/_RUNNING/COMMUNITY/Model.h3d"
    set set_name "Set1"


    hwi OpenStack
    hwi GetSessionHandle session
    session GetProjectHandle project
    project GetPageHandle page 1
    page GetWindowHandle win 1
    win SetClientType animation
    win GetClientHandle anim
    #anim AddModel $import_file_path
    set id [anim AddModel $import_file_path]
    anim GetModelHandle myModel $id
    myModel SetResult $import_file_path
    anim Draw
    myModel GetResultCtrlHandle myResult
    set current [myResult GetCurrentSubcase]
    myResult SetCurrentSimulation [expr [myResult GetNumberOfSimulations $current]-1]
    set data_types [myResult GetDataTypeList $current]
    myResult GetContourCtrlHandle myContour
    myContour SetDataType [lindex $data_types 6]
    myContour SetDataComponent == vonMises
    myContour SetEnableState true
    anim Draw


    set sets_list [myModel GetSelectionSetList "User_Set"]

    hwi OpenStack
    foreach seto $sets_list {
        myModel GetSelectionSetHandle mySet${seto} $seto
        set label [mySet${seto} GetLabel]
        if {$label == $set_name} {
            set set_id $seto
        }
    }
    hwi CloseStack

    myModel GetQueryCtrlHandle myQuery
    myQuery SetSelectionSet $set_id
    myQuery SetQuery "element.id contour.value"
    myQuery WriteData $outPath

    hwi CloseStack
    exit

    @Adriano A. Koga Thank you for the help but an error is generated specifying 'can't read "set_id": no such variable".

    Could you help me with this?

     

    Thank you

  • Adriano A. Koga
    Adriano A. Koga
    Altair Employee
    edited May 2023

    @Adriano A. Koga Thank you for the help but an error is generated specifying 'can't read "set_id": no such variable".

    Could you help me with this?

     

    Thank you

    have you adjusted the header of the script with your actual data?

    Also, maybe there might be an issue with the  User_Set, then maybe you could replace this line:

    set sets_list [myModel GetSelectionSetList "User_Set"]

    by

    set sets_list [myModel GetSelectionSetList]