condition id

Hi

I want to keep track with the condition id of the mesh. In my problemtype, it has been kept track manually like

*set cond Surface_Load *elems *canRepeat
*loop elems *OnlyInCond
*condID *ElemsMat
*set var condID= condID+1
*end elems

Is it possible to extract condID from GiD?

On the other hand, is it possible to interact between bas file and tcl script, for example, in bas file, the information is passed to tcl
*tcl(SaveID Surface_Load *condID)

later on condID can be extracted from tcl to bas using the same way. This is my idea, I think it’s possible but i’m not able to find that in the Customization Manual

Giang

GiD applied conditions doesn’t has internally any id, it is stored as a list.
You can implictly use the list order as an id, as you have done.

At .bas level you can use direcly the *loop inner counter, named *loopvar, without another extra variable:
e.g.

*set cond Surface_Load *elems *canRepeat
*loop elems *OnlyInCond
*LoopVar *ElemsMat
*end elems

About passing variables between .bas an .Tcl, it is explained in the customization manual
http://www.gidhome.com/documents/customizationmanual/PROBLEMTYPE%20’CLASSIC’/TEMPLATE%20FILES/Commands%20used%20in%20the%20.bas%20file/Specific%20commands

This is the example related on the manual:

Example: In this example the *Tcl command is used to call a Tcl function defined in the problem type .tcl file. That function can receive a variable value as its argument with *variable. It is also possible to assign the returned value to a variable, but the Tcl procedure must return a numerical value.
In the .bas file:

*set var num=1
*tcl(WriteSurfaceInfo *num)
*set var num2=tcl(MultiplyByTwo *num)

In the .tcl file:

proc WriteSurfaceInfo { num } {
return [GiD_Info list_entities surfaces $num]
}

proc MultiplyByTwo { x } {
return [expr {$x*2}]
}

As is explained you can assing the value returned by a *tcl procedure to a .bas variable, but it is limited to integer or real numbers, because .bas variables can’t store strings.
A trick to pass a string from Tcl to .bas is to set the value of an auxiliary ‘General data’ question (that can be hidden). It is possible to set the value from Tcl and ask this value with *gendata()

I could communicate between bas and tcl using a global variable in tcl, e.g. create a list variable in tcl and fill it in bas, then call it out from tcl in bas

So far this approach works well without problem. However, GiD may crash if the tcl variable is the same with some GiD internal variable. But it’s not likely.

Thanks for the link to the manual anyway.

Giang

How are you accessing a Tcl variable from the .bas?

That’s pretty simple. In Tcl, declare the global variable and subroutines to read/write it

set g_conddict [dict create]

proc SaveCond { cond_type args } {
    global g_conddict
    dict append g_conddict $cond_type "$args\n"
    return ""
}

proc GetCond { cond_type } {
    global g_conddict
    if { [dict exists $g_conddict $cond_type] } {
        return [dict get $g_conddict $cond_type]
    } else {
        return ""
    }
}

then it’s straightforward to use it within bas file

*tcl(SaveCond Surface_Mortar_MasterIndex *condID *cond(1))
*tcl(GetCond Surface_Mortar_MasterIndex)