print() Error #4147
-
I am attempting to print the location of the object. According to this discussion on GitHub - #207, it appears that you can access the force and other information through the SOFA UI. However, I am hoping to receive this information in real-time during the simulation. According to this discussion on GitHub - #3002, it appears that the position information is stored in the MechanicalObject and can print the info using print(). To access it, I followed the code below:
However, I keep encountering the following error:
Basically, I cannot print anything and I am unsure why. I have a SofaPython plugin, and when I attempted to also call the DataContainer plugin, it resulted in a fatal error. I am unsure of what I might have overlooked. Thank you~ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, you can have a look on the documentation website. It mentions the need to add |
Beta Was this translation helpful? Give feedback.
-
Hi @james12parker, As pointed by @alxbilger, to get the value of a data field you need to use the "value" attribute. import Sofa
class AClass(object):
def __init__(self, **kwargs):
self.MO = kwargs.get("MechanicalObject")
print(str(self.MO.position))
print(str(self.MO.position.value))
def createScene(root):
"""This scene is just one mechanical object with position that are printed by a function"""
mo = root.addObject("MechanicalObject")
AClass(MechanicalObject=mo)
createScene(Sofa.Core.Node("root")) And, as expected it prints
without the error. |
Beta Was this translation helpful? Give feedback.
Hi,
you can have a look on the documentation website. It mentions the need to add
.value
after a Data. Also, make sure thatself.MO
is theMechanicalObject
. We cannot say it from what you shared, because we don't know what you put inkwargs
.