BUG: scia.external update_concrete_material

I found a bug in the update_concrete_material. At least it doesn’t work as expected.

As a developer I want to use the standard available materials in the SCIA and change the properties of them. In this case C12/15 and C16/20 are never used by our users. I would like to update the properties aswell as the name of that material. e.g. → I want to change the material name : ‘C12/15’ to ‘C45/55-cracked’. I know you can do that with an xml, but viktor doesn’t allow us. The main problem is that materials in the scia file are looked up by name (nm attribute) FIRST and after that by using the object_id.

A code snippet of the model creation:

scia_model = SciaModel()

#C12/15 has an object ID of 315

material_cracked = scia_model.update_concrete_material(
                  315, C45/55, Concrete.ECPart.GENERAL, e_modulus=12000
              )

will result in xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<project xmlns="http://www.scia.cz">

    <def uri="viktor.xml.def"/>

    <container id="{16B20277-A13B-4689-97D5-68F2BACF1318}" t="EP_MaterialEC.EP_MaterialHeaderEC_EN.1">
        <table id="42334686-C9D2-463B-A9EC-C637F50EBD73" t="EP_MaterialEC.EP_MaterialCrtEC_EN.1">
            <h>
                <h0 t="Name"/>
                <h1 t="Thermal expansion "/>
                <h2 t="Unit mass"/>
                <h3 t="Density in fresh state"/>
                <h4 t="E modulus"/>
                <h5 t="Poisson coeff."/>
                <h6 t="Independent G modulus"/>
                <h7 t="G modulus"/>
                <h8 t="Log. decrement (non-uniform damping only)"/>
                <h9 t="Specific heat"/>
                <h10 t="Thermal conductivity"/>
                <h11 t="Characteristic compressive cylinder strength fck(28)"/>
                <h12 t="Calculated depended values"/>
            </h>
            <obj id="315" nm="C45/55">
              <p0 v="C45/55"/>
              <p4 v="36283188218.91413"/>
              <p6 v="0"/>
              <p12 v="0"/>
            </obj>
        </table>
    </container>
</project>

As a result this will update the C45/55 properties at object_id: 322 and not (as expected) at 315!

The quickest fix is by removing the nm attribute from the xml and there by forcing a lookup by object_id. As an alternative you could also extend the ‘update_concrete_material’ method with a ‘old_name’ parameter, but I’m afraid this will have some backwards compatibility issues.

The correct output xml should be:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<project xmlns="http://www.scia.cz">

    <def uri="viktor.xml.def"/>

    <container id="{16B20277-A13B-4689-97D5-68F2BACF1318}" t="EP_MaterialEC.EP_MaterialHeaderEC_EN.1">
        <table id="42334686-C9D2-463B-A9EC-C637F50EBD73" t="EP_MaterialEC.EP_MaterialCrtEC_EN.1">
            <h>
                <h0 t="Name"/>
                <h1 t="Thermal expansion "/>
                <h2 t="Unit mass"/>
                <h3 t="Density in fresh state"/>
                <h4 t="E modulus"/>
                <h5 t="Poisson coeff."/>
                <h6 t="Independent G modulus"/>
                <h7 t="G modulus"/>
                <h8 t="Log. decrement (non-uniform damping only)"/>
                <h9 t="Specific heat"/>
                <h10 t="Thermal conductivity"/>
                <h11 t="Characteristic compressive cylinder strength fck(28)"/>
                <h12 t="Calculated depended values"/>
            </h>
            <obj id="315"> 
              <p0 v="C45/55"/>  <! -- NEW MATERIAL NAME -->
              <p4 v="36283188218.91413"/>
              <p6 v="0"/>
              <p12 v="0"/>
            </obj>
        </table>
    </container>
</project>

WORKAROUND:

As I workaround I will remove the nm attribute myself.

Hi Wichard,

Nasty bug
 I would also expect SCIA to search by id instead of name. I did not try this myself, but would an alternative workaround be to use a non-default name instead? For example “C45/55.” (trailing dot), "C45/55 " (trailing space), or like you mentioned “C45/55-cracked”?

Tried that too, but in that case SCIA will not do anything (and won’t notify you about that). So thats nasty aswell. SCIA never fails to surprise us isn’t it.

Just because I’m a good mood, here as snippet as example to remove the specific nm attribute from the generated xml for anyone hassling with this problem.

from viktor.core import File
import lxml.etree as ET


def remove_nm_attribute_material_from_xml(xml_file: File) -> File:

    XMLNS = http://www.scia.cz
    with xml_file.open_binary() as file:
        xml_tree = ET.parse(file)

    material_objs = xml_tree.xpath(
        f'//ns:container/ns:table[@t="EP_MaterialEC.EP_MaterialCrtEC_EN.1"]/ns:obj',
        namespaces={"ns": XMLNS},
    )

    for material in material_objs:
        material.attrib.pop("nm",None)

    xml_file = File()

    with xml_file.open_binary() as writable_file:
        writable_file.write(
            ET.tostring(xml_tree, pretty_print=True, xml_declaration=True, encoding="utf-8", standalone=True)
        )

    return File.from_data(ET.tostring(xml_tree))

happy coding!

1 Like

Thanks for sharing!

We will have to do some more testing with different SCIA versions, but if the solution is indeed removing the nm attribute, I would advice to pop gracefully in case we remove it in an upcoming release:

    for material in material_objs:
        material.attrib.pop("nm", None)

good suggestion! Thanks I will edit my post