TCL script

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

 

 

 

Tagged:

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hello

     

    I have a question regarding the TCl script. I want user to pick a node from the .h3d file in hyperview and then the script should give out the principal stresses of that particular node.  

    I am not sure which command to use which tells user to pick a node and then select that node to give out the principal stresses

     

    Thanks  in advance

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hello

     

    Could  someone please have a look. it is bit urgent

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hi,

     

    Please try this script: https://connect.altair.com/CP/kb-view.html?kb=40826 which is available on Altair connect

     if necessary modify if you want the output in a different way

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Thanks a lot Prakash. Will have a look at it.

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    I don't really understand how do I use this code.

    I copied the whole code in hyperview and got something like this( image attached)

     

    Under the usage section, it says ' Using the Node selector, select nodes the order you intend to write out'. How do I do that? I tried to use the query result panel, but that thing only exports the data which I select in the panel.

     

    Please let me know what does that step mean

     

    Thanks

    <?xml version="1.0" encoding="UTF-8"?>5a8c14222ba93_2018-02-2013_25_36-Untitled-HyperWorks2017.2.thumb.jpg.c4cff5c9e76775c15306b72d84976010.jpg

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    I figured it out

    Never mind

     

    Thanks

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hello Everyone,

     

    The last file works great. Thanks a ton for the help.

    I had another question. In this TCl script, I am trying to get a user input for the nodeID and then the script should give out the contour value. It should be pretty straightforward, but I am not able to resolve it. I have attached my script. I think there is just a small error somehwere. If someone could have a look, then it would be great. Thanks in advance.

     

    proc ShowCurves {fine amount}

    hwi OpenStack
    hwi GetSessionHandle session1
    session1 GetProjectHandle project1
    project1 GetPageHandle page1 1
    page1 GetWindowHandle win1 1
    win1 SetClientType animation
    win1 GetClientHandle anim1
    set mod_name 'D:/schnapphaken/Schnapphaken_rev00.h3d'
    set id1 [anim1 AddModel $mod_name]
    anim1 GetModelHandle my_model1 $id1
    my_model1 SetResult $mod_name

    my_model1 GetResultCtrlHandle my_res
    my_res GetContourCtrlHandle my_cont
    my_cont SetDataType Stress
    my_cont SetDataComponent vonMises
    my_cont SetLayer Max
    my_cont SetAverageMode simple
    set num_sims [my_res GetNumberOfSimulations 1]
    set num_ind [expr $num_sims-1]
    my_res SetCurrentSimulation $num_ind

     

    my_cont SetEnableState true
    anim1 SetDisplayOptions contour true
    anim1 Draw


    set entity_type [my_cont GetBinding]
    set set_id [my_model1 AddSelectionSet $entity_type]
    my_model1 GetSelectionSetHandle entity_list $set_id


    puts 'What is node you want to query'
    gets stdin enteranode
    entity_list Add '$enteranode'
    set id_list [entity_list GetList]
    my_model1 GetQueryCtrlHandle my_query
    my_query SetSelectionSet $set_id
    my_query SetQuery 'contour.value';
    my_query WriteData output.txt

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited February 2018

    Hi Novak , 

    Please make below modifications in code and try:

    set mod_name {D:/schnapphaken/Schnapphaken_rev00.h3d}

     

    entity_list Add 'id == $enteranode'

     

    Please note if you have to add multiple nodes, try to loop and add each node. 
     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hi Livil

     

    Thanks for the reply. I did make those modifications but the output file still doesn't give the stress value of that particular node. The output file just has 'value' written in it.

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited February 2018

    Hi Novak , 

    Can you please confirm two things, 

    1. when you go line by line and execute anim1 Draw are you able to visualize the contour?

    2. Are you able to manually query the stress values in the nodes? 

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hi Livil

     

    Yes. I am able to do both the things

    Thanks

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hi Prakash

     

    Meanwhile, I had another question as well. The file which you sent me works perfect. I want to add some stuff, but it is very hard to understand what is exactly going on in the script. I want to use the stresses in 3 directions to then calculate the stress at which it breaks. For that, I have created a separate TCl file, in which 'sigma_1, sigma_2, sigma_3' are the 3 stresses which will be obtained from the first script. Basically, I just want to integrate the following script with the original one. The script should look like this:

    Thanks a lot in advance.

     

    proc ShowCurves {fine amount}

    gets stdin sigma_1
    gets stdin sigma_2
    gets stdin sigma_3

    if {$sigma_1 > 0} {
    set f_sigma 1
    } else {
    set f_sigma 1.3
    }
    if {$sigma_2 > 0} {
    set f_sigma 1
    } else {
    set f_sigma 1.3
    }
    if {$sigma_3 > 0} {
    set f_sigma 1
    } else {
    set f_sigma 1.3
    }

    set sigma_bar_1 [expr $sigma_1/$f_sigma]
    set sigma_bar_2 [expr $sigma_2/$f_sigma]
    set sigma_bar_3 [expr $sigma_3/$f_sigma]
    set vonmiseshypo [expr sqrt ($0.5*(($sigma_bar_1-$sigma_bar_2)^2+($sigma_bar_2-$sigma_bar_3)^2+($sigma_bar_3-$sigma_bar_1)^2))]
    set vonmiseshypo [expr sqrt (0.5*(($sigma_bar_1-$sigma_bar_2)^2+($sigma_bar_2-$sigma_bar_3)^2+($sigma_bar_3-$sigma_bar_1)^2))]
    set normalstresshypo [expr {max(sigma_bar_1, sigma_bar_2, sigma_bar_3)}]
    set normalstresshypo [expr {max($sigma_bar_1, $sigma_bar_2, $sigma_bar_3)}]
    puts 'What material is it 1.Duktile thermoplast 2.Semi duktile thermoplast 3. spröde thermoplast'
    gets stdin material
    if {material == 1} {
    puts 'your material is duktile thermoplast'
    set q 0
    } elseif {material ==2} {
    puts 'your material is semiduktile thermoplast'
    set q 0.26
    } elseif {material == 3} {
    puts 'your material is spröde thermoplast'
    set q 0.52
    } else{
    if {$material == 1} {
    puts 'your material is duktile thermoplast'
    set q 0
    } elseif {$material ==2} {
    puts 'your material is semiduktile thermoplast'
    set q 0.26
    } elseif {$material == 3} {
    puts 'your material is spröde thermoplast'
    set q 0.52
    } else {
    puts 'try again'
    }
    set sigma_versagen [expr $q*$normalstresshypo+(1-q)*$vonmiseshypo]
    set sigma_versagen [expr $q*$normalstresshypo+(1-$q)*$vonmiseshypo]

     

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited February 2018

    Hi Novak,

    I tried doing it via elements cause my model had results in elements and I was able to write to file. Please refer below and modify the program accordingly. 

     

        set t [clock clicks]
        hwi OpenStack
        hwi GetSessionHandle sessh$t
        sessh$t GetProjectHandle projh$t
        projh$t GetPageHandle pageh$t [projh$t GetActivePage]
        pageh$t GetWindowHandle winh$t [pageh$t GetActiveWindow]
        winh$t GetClientHandle animh$t
        animh$t GetModelHandle modelh$t [animh$t GetActiveModel]
        modelh$t GetResultCtrlHandle resh$t
        set subId [resh$t GetCurrentSubcase]

        set sid [modelh$t AddSelectionSet element]; //change to nodes or use your current logic
        modelh$t GetSelectionSetHandle s$t $sid

    //Get node from user. 
        s$t Add 'id == 1608'; //$enteranode should come instead of 1608

        modelh$t GetQueryCtrlHandle q$t;
        q$t SetSelectionSet $sid;
        q$t SetQuery 'element.id contour.value' //change to node.id
        q$t GetIteratorHandle i$t
        q$t WriteData {C:\temp\output.txt}
        # set data [i$t GetDataList]

       # puts $data
        hwi CloseStack
     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Thank you Livil. Will have a look.

     

    Thanks a lot

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2018

    Hi

     

    Can anyone please help me with the above question related to the integration of the two scripts.

     

    Thanks a lot

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited March 2018

    Hi Novak, 

     

    After you get the stresses form the first file, call your proc using:

     

    ShowCurves $sigma_1 $sigma_2 $sigma_3 #Stress values 


    and modify the proc you have written as: 

     

    proc ShowCurves {sigma_1 sigma_2 sigma_3}

    {

    if {$sigma_1 > 0} {
    set f_sigma 1

    } else {
    set f_sigma 1.3
    }

    ...

    }

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2018

    Hi Livil

     

    Thanks for replying Livil. How do I assign the values obtained from the script to sigma_1, sigma_2, sigma_3. The script just prints the values, doesn't give any name or something.

     

    Thanks again

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited March 2018

    Hi Novak, 

    Are you referring to the script shared by Prakash or something else?  Does it print to the screen or to the file?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2018

    Hi Livil

    Exactly, that's one I meant. It prints to the file.

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited March 2018

    Hi Novak, 

    Are you able to get the desired result from the file? 

     

    If you're getting what you want you will have to return lst_dispInfo from GetNodalContourValue  and set sigma values directly in the below loop like this:

        foreach n_id $::curSel {
            set sigma_1  [::hw::post::custom::GetNodalContourValue $n_id 'YourResultType' 'YourResul/direction']; #should be matching the file. 
            set sigma_2 [::hw::post::custom::GetNodalContourValue $n_id 'Displacement' 'Y']; #should be matching the file. 
            set sigma_2 [::hw::post::custom::GetNodalContourValue $n_id 'Displacement' 'Z']; #should be matching the file. 
            ShowCurves $sigma_1 $sigma_2 $sigma_3 #Stress values 

        }

     

    If you're authorized to share files, please share result and developed code in the below link. I will give it a try. 

    https://ftin.india.altair.com:8443/filedrop/~QUK1Ji

     

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited November 2020

    Hello Everyone

     

    Firstly thanks a lot Livil for all the help. Really grateful for it.

    Secondly, here is the file which Livil wrote, in case any one needs it in future.

     

    Unable to find an attachment - read this blog

  • Mrunmaya M
    Mrunmaya M Altair Community Member
    edited March 2019

    Hello,

     

    I have a question regarding  developing a TCL script in Hyperview for post processing.

     

    I want to pass the particular node id  where the dynamic max value  is displayed as a measure (after execution of contour plot) needed to create a note .  

     

    I am not sure which command to use for getting the node id and then pass that node id to create a note (with passing that node id as an Entity ID).

    (Details enclosed as an attachment)

     

    Thanks  in advance.

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

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited March 2019

    Hi Mrunmaya,

     

    How familiar are you with HyperView Scripting? You can do this by getting measure handle and using AddNode.

     

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

  • Mrunmaya M
    Mrunmaya M Altair Community Member
    edited March 2019

    Hi Livil,

     

    Thanks for the help. I implemented it and it worked out for me. 

     

    I have another query regarding masking  the elements in the model.

     

    I want to mask the nearby elements around a Node ID.

     

    Any help in this regard will be helpful.

     

    Thanks in Advance.

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited March 2019

    Hi Mrunmaya,

     

    Please refer to poISelectionSet Add in help document, it has a lot of examples similar to your requirement. 

  • Mrunmaya M
    Mrunmaya M Altair Community Member
    edited March 2019

    HI Livil,

     

    Thanks Will Check the help document and revert back to you for any queries.