🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Python API - Setting and deleting attributes

User: "andre_f_a_silva97"
Altair Community Member
Updated by Michael Herve

Hello all,

Does anybody know if it is possible to set and/or delete attributes in Python API?

In short, I wanted to assign a node to a beam element and for that I have my collector "element" and I wrote:
element.directionnode.__setattr__("id",node)

This only works if there is a prior node as reference for the orientation of the beam. If the beam is not oriented based on a reference node (therefore, is referenced by a vector) then it does not work.

I get the message:

AttributeError: "id"

Same thing happens if I want to remove a node from the attribute with

delattr(element.directionnode,"id")

Any clue if this is possible to do?
Thanks

 

Find more posts tagged with

Sort by:
1 - 1 of 11
    User: "Dimitrios Tolis"
    Altair Employee
    Accepted Answer

    Hi @andre_f_a_silva97,

    I hope you are well and sorry for the late answer. Please do not use the __setattr__ , delattr.

    • As you see I created, the beam element via the 1D> Line Mesh tool in 2024.1 version using direction vector.
    Screenshot 2025-06-19 171046.png

    • After to set the direction node you can set directly by assigning the entity:
    Screenshot 2025-06-19 170647.png

    import hm

    import hm.entities as ent

    model = hm.Model()

    node=ent.Node(model,5)

    elem=ent.Element(model,1)

    elem.directionnode=node

    • Unset the directionnode by assigning the value None to the data name
    Screenshot 2025-06-19 170700.png

    Please in case this solves your question, or you need any extra information, please do not hesitate to reply to this.

    Thank you!