Python API - Setting and deleting attributes
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
- As you see I created, the beam element via the 1D> Line Mesh tool in 2024.1 version using direction vector.
- After to set the direction node you can set directly by assigning the entity:
- Unset the directionnode by assigning the value None to the data name
I hope you are well and sorry for the late answer. Please do not use the __setattr__ , delattr.
import hm
import hm.entities as ent
model = hm.Model()
node=ent.Node(model,5)
elem=ent.Element(model,1)
elem.directionnode=node
Please in case this solves your question, or you need any extra information, please do not hesitate to reply to this.
Thank you!
Hi @andre_f_a_silva97,
I hope you are well and sorry for the late answer. Please do not use the __setattr__ , delattr.
import hm
import hm.entities as ent
model = hm.Model()
node=ent.Node(model,5)
elem=ent.Element(model,1)
elem.directionnode=node
Please in case this solves your question, or you need any extra information, please do not hesitate to reply to this.
Thank you!
Hi Dimitrios,
Thank you for the support.
Sorry I forgot to update this thread but I managed to get it to work some time ago.
The difference is that with my current script I can select multiple CBEAM elements and select multiple reference nodes. Then I align each CBEAM according to the node that closest to node A and B of the CBEAM.
Then I figured I had to do what you mention about removing the direction node from the card edit of the CBEAMs.
It works pretty well and saves a lot of time avoiding the alignment of each CBEAM individually when the reference nodes vary.
But in general anyone who follows what you described should be successful. I have a very similar methodology in my code and it performs as intended.
Regardless, thank you very much for the support.
Kind regards.
I thank you 😊!