Home › Forum › SOFA › Using SOFA › Missing attribute: getObject
Tagged: getObject, Linux_ubuntu, SOFA, SOFA_2106, SofaPython3
- This topic has 5 replies, 4 voices, and was last updated 2 years, 11 months ago by Hugo.
-
AuthorPosts
-
5 October 2021 at 01:02 #20499daserkBlocked
Hello. This sounds like a really basic question, but after many hours of trying I wasn’t able to solve the issue.
In many example codes I see getObject() being used to get some object that is part of a node and examine or work with its data.
For example, using it with a PythonController to control the length of a CableConstraint, or the position or rotation of an object.
But regardless of what I want to do, I always get the error:
[ERROR] [SofaPython3::SceneLoader] AttributeError: Missing attribute: getObject
Which seems very weird to me, as I am clearly doing something wrong.
Even simple python scenes like this one produce the error.
import Sofa def createScene(root): object = root.getObject('defaultAnimationLoop') print(object.findData('name').value)
I think I just don’t understand how objects in Python work. Any help will be appreciated.
For reference I am running version 20.04 LTS of PopOS (Ubuntu based) with a compiled stable version of SOFA 21.06 with SofaPython3.
6 October 2021 at 08:33 #20517HugoKeymasterHi @daserk
Sorry that you struggled on this point.
Which version of SOFA and SofaPython3 are you using?The recent PR #171 fixed the node iterator in python3, preventing from doing the getObject as you are trying to do – if I am correct. This was recently merged within the master branch of SofaPython3, and available in the v21.06.01. You should be able to write:
mytoto = root.getObject("Toto") if mytoto != None: copymydata = mytoto.dataname
Could you try with the latest v21.06.01 please?
I hope this helps.
Best wishes,Hugo
19 October 2021 at 14:39 #20665ThresholdddBlockedHi, @Hugo,
I met the same problem using v21.06.01, but getObject() function still not work. I met the error
def createScene(root): model = root.addChild("model") model.addObject("RegularGridTopology", name = "grid",min = "-5 -5 0", max = "5 5 40", n = "3 3 10") print(LRmodel.getObject("grid"))
I run in python, error
[ERROR] [SofaRuntime] AttributeError: Missing attribute: getObject
in runSofa
[ERROR] [SofaPython3::SceneLoader] AttributeError: Missing attribute: getObject
29 October 2021 at 17:20 #20709HugoKeymasterHi @daserk
It’s strange. What is
LRmodel
? Is it a node ?
The functiongetObject
should work an example here ifliver
is a node anddofs
is an object in this node (a MechanicalObject here):liver.getObject("dofs").findData("position").value
Best
Hugo
10 December 2021 at 16:36 #21116EricBlockedHi Hugo,
I encountered the error of “Missing attribute getObject” as I was trying to access indices within BoxROI
tissue = root.addChild('tissue') tissue.addObject('EulerImplicitSolver', name = "tissueImplicitSolver", rayleighStiffness = "0.01", printLog = "false") tissue.addObject('CGLinearSolver', name = "tissueCgLinearSolver", iterations = "25", tolerance = "1e-09", threshold="1e-09") tissue.addObject('MeshGmshLoader', name="tissueMeshLoader", filename=tissue_mesh_model) tissue.addObject('TetrahedronSetTopologyContainer', name="tissueMeshTopo", src="@tissueMeshLoader") tissue.addObject('MechanicalObject', name = "tissueDofs", src="@tissueMeshLoader") tissue.addObject('UniformMass', name = "tissueMass", totalMass = "0.001") tissue.addObject('TetrahedronFEMForceField', template = "Vec3d", name = "tissue TetrahedronFEM Forcefield", method="large", poissonRatio="0.35", youngModulus="5000", computeGlobalMatrix="0") tissue.addObject('BoxROI', name = "tissueBoxROI",box = "-999 -999 -999 0.001 0.001 0.001") tissue_fixed_indices = tissue.getObject('tissueBoxROI').findData('indices').value
However, if I define
tissue_box = tissue.addObject('BoxROI', name = "tissueBoxROI",box = "-999 -999 -999 0.001 0.001 0.001")
and after
tissue.init()
I could access object data throughtissue_box.indices
but still cannot viatissue.getObject("tissueBoxROI").findData("indices").value
The version I am running is 21.06.02. Wonder what might be the reason for this error.
Cheers
10 December 2021 at 22:11 #21120 -
AuthorPosts
- You must be logged in to reply to this topic.