0

I want to access different modules using a for loop in PySpin Library Python. For example, to change the values of Exposure time and Frame Rate of the camera, you can use camera.ExposureTime.SetValue(1000) and camera.AcquisitionFrameRate.SetValue(5).The main idea is to replace those values using an array instead.

    try:
    result = True
    cam.ExposureAuto.SetValue(PySpin.ExposureAuto_Off)
    for i in item:
        if i[1] is not None:
            if cam.i[0].GetAccessMode() != PySpin.RW:
                return {"message": "Unable to set {i[0]}"}
            cam.i[0].SetValue[i[1]]

In this case, I get the error below : TypeError: 'CameraPtr' object is not subscriptable

Can anyone help please? Thanks a lot !!!

Diap Rope
  • 13
  • 4
  • No, objects don't work like that. Besides, how can you generalize that when each control has different ranges and possible values? – Tim Roberts Jan 20 '22 at 21:23
  • Well, in my case I want the user to sent via API a json file with the parameters that he want to change for example {"ExposureTime":"100","AcquisitionFrameRate":"20"} So the item represents the json request of the user. – Diap Rope Jan 20 '22 at 21:42
  • Well, then you can do `s = 'ExposureTime'` / `getattr(cam,s).SetValue(1000)`. – Tim Roberts Jan 20 '22 at 21:46

1 Answers1

0

You could set up your own array, if you really want to do this, by doing:

camidx = [
    cam.Exposure,
    cam.ExposureAuto,
    cam.Brightness
]

Now you can write camidx[0].SetValue(7). I'm not convinced that's better.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
  • Many many thanks!!! The camidx approach and getattr(cam,s).SetValue(1000) solved my issue. You saved me 8 hours of work! – Diap Rope Jan 20 '22 at 22:13