GiD_AssignData only in one field

Moderator: GiD Team

gonzaloalen
Posts: 2
Joined: Tue Oct 15, 2019 8:27 am

GiD_AssignData only in one field

Postby gonzaloalen » Fri Oct 18, 2019 2:59 pm

Hello,

I'm trying to assign a variable in a specific field, however, with this function I have to specify also a value for the other fields that I don't want to change.

Here my code:

set values [list SCS {0.0} {0.0} {0.0} $cn {0.0} {0.0} {0.0} {0.0} {0.0} {0.0} {0.0}]
catch {
GiD_AssignData condition Losses_Model body_elements $values [lindex $aa 0]
}

When I use this function to assign the value $cn in the fourth field, I change the others to "0.0". Is there any way to assign one field (one position in the list) without affect the previous values of the fields?

Thanks in advance!
User avatar
escolano
Posts: 1580
Joined: Thu Sep 18, 2014 3:31 pm

Re: GiD_AssignData only in one field

Postby escolano » Mon Oct 21, 2019 4:36 pm

An advice: avoid the use of catch if it is not really necessary, to avoid hide you errors.

About applying conditions:
if do you apply again the same condition to the same entity
a) if the condition is defined as canrepeat: no (by default), then the old assignation is deleted and a new one is created
b) is the condition is defined as canrepeat: yes , then multiple assigned values are attached to the entity.

You cannot modify a field value of an assigned condition, what you can do is delete a previous assignation and assign a new one

Then, in case of canrepeat:no (probably your case) to modify only a value you must ask by the previous values, if any, an then replace the item of the list that you want, and apply then new list of values

e.g. to assign to element_id to the 4th value to $cn can do something like this:

proc My_Assign_Condition_Losses_Model_Element { element_id $pos_to_set $value_to_set } {
#assuming canrepeat=no (single assign), the 0-item is the first item, (In case of multiple assign could be more then one item)
set item [lindex [GiD_Info conditions Losses_Model body_elements mesh $element_id] 0]
if { $item != "" } {
#previous values
set values [lindex $item 3]
} else {
#default values
set values [list SCS 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]
}
lset values $pos_to_set $cn
GiD_AssignData condition Losses_Model body_elements $values [list $element_id]
}

#e.g. to modify/assign to element 25 the 4th question (starting from 0) to a value of 1
My_Assign_Condition_Losses_Model_Element 25 4 1

Return to “Mesh”

Who is online

Users browsing this forum: No registered users and 6 guests