Jump to content
  • Announcements

    • Rahul Ponginan

      Please click here for a short but important announcement   03/26/17

      Dear Users Our Commercial and Academic users around the world can use these same forums here as before i.e. the Altair Support Forum , Commercial users from India with solver queries can go to the Solver Forum for India Commercial Users , Academic Users from India and AOC India Participants are requested to go to the Forum for India Academic Users and AOC India Participants , We will be tending to all queries in all the forums promptly as before, thank you for your understanding. 
Novak

TCL script

Recommended Posts

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

 

Share this post


Link to post
Share on other sites

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

5a8c14222ba93_2018-02-2013_25_36-Untitled-HyperWorks2017.2.thumb.jpg.c4cff5c9e76775c15306b72d84976010.jpg

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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. 
 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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? 

Share this post


Link to post
Share on other sites

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]

 

Share this post


Link to post
Share on other sites

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
 

Share this post


Link to post
Share on other sites

Hi

 

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

 

Thanks a lot

Share this post


Link to post
Share on other sites

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
}

...

}

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

 

Rahul R likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×