# Getting Camera Loc in python

**URL:** <https://blenderartists.org/t/getting-camera-loc-in-python/294833>\
**Category:** Python Support\
**Created:** [April 8, 2002, 12:43pm UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833 "2002-04-08T12:43:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rndrdbrian](https://blenderartists.org/user_avatar/blenderartists.org/rndrdbrian/32/20_2.png) [@rndrdbrian](https://blenderartists.org/u/rndrdbrian)\
**Post date:** [April 8, 2002, 12:43pm UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/1 "2002-04-08T12:43:02Z")

</div>

I have been busy working on the RenderB\*tch export code.

SO far, things are progressing rapidly, I can handle mutiple objects, and  
correctly handle the single vertex list.

One thing I am stuck on is getting the LocX, LocZ, and LocY of the main camera.

I tried the following code:

```auto

	#Get Camera Position
	Cams = Blender.Camera.Get()
	OorCam = Cams[0]
	Pos = OorCam.getPosition()
	Xloc = round(OorCam.LocX,3)
	Yloc = round(OorCam.LocY,3)
	Zloc = round(OorCam.LocZ,3)

```

but Blender doesn’t seem to like this, as it spits the following error  
message out:

```auto

Traceback (most recent call last):
  File "xport03.py", line 54, in EventGUI
  File "xport03.py", line 163, in Xport
SystemError: error return without exception set

```

Line, 163 being

```auto
Xloc = round(OorCam.LocX,3)

```

Any suggestions? I would have thought this would have worked…

But it doesn’t.

help!

thanks in advance

- 

brian

---

<div class="post-metadata">

**Author:** ![Jamesk](https://blenderartists.org/user_avatar/blenderartists.org/jamesk/32/5_2.png) [@Jamesk](https://blenderartists.org/u/Jamesk)\
**Post date:** [April 8, 2002, 1:26pm UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/2 "2002-04-08T13:26:51Z")

</div>

Looks like you need surround something with a try-catch clause there…

---

<div class="post-metadata">

**Author:** ![ilac](https://blenderartists.org/letter_avatar_proxy/v4/letter/i/9e8a1a/32.png) [@ilac](https://blenderartists.org/u/ilac)\
**Post date:** [April 8, 2002, 2:31pm UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/3 "2002-04-08T14:31:29Z")

</div>

WARNING: My python skills are newbie at best so I might be uttering complete nonsense - but a matrix might solve your problems.

Not sure if this is the right way to do it but:

```auto

Cams = Blender.Object.Get("Camera")
CM = Cams.matrix

XLoc = CM[3][0]
YLoc = CM[3][1]
ZLoc = CM[3][2]

```

It’s probably a screw up but it might inspire a solution 😉

Regards  
Fabrizio

---

<div class="post-metadata">

**Author:** ![theeth](https://blenderartists.org/user_avatar/blenderartists.org/theeth/32/9_2.png) [@theeth](https://blenderartists.org/u/theeth)\
**Post date:** [April 8, 2002, 7:36pm UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/4 "2002-04-08T19:36:22Z")

</div>

Fabrizio: actually, the matrix is always the good solution, since it updates itself even if the object is linked to an armature, which doesn’t always hapen when using .Loc\*

Becareful though printing the matrix might crash Blender!

also, it is not a list of list of float, like one might expect. To convert it to a list of list, just use the folowing function:

```auto

def convert_float(mtx):
      final = []
      row = []
      for oRow in mtx:
            row = [x for x in oRow]
            final.append(row)
      return final

```

Martin

---

<div class="post-metadata">

**Author:** ![ilac](https://blenderartists.org/letter_avatar_proxy/v4/letter/i/9e8a1a/32.png) [@ilac](https://blenderartists.org/u/ilac)\
**Post date:** [April 9, 2002, 12:34am UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/5 "2002-04-09T00:34:21Z")

</div>

Theeth: Well, thanks to you for pointing me to Matrices a few weeks ago 🙂 though as you can see I haven’t had time to learn much about them.

Hasn’t anybody yet figured out how to make days a ‘few’ hours longer yet?! 😛

Rgds  
Fabrizio

---

<div class="post-metadata">

**Author:** ![rndrdbrian](https://blenderartists.org/user_avatar/blenderartists.org/rndrdbrian/32/20_2.png) [@rndrdbrian](https://blenderartists.org/u/rndrdbrian)\
**Post date:** [April 9, 2002, 1:40am UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/6 "2002-04-09T01:40:40Z")

</div>

> [@ilac](#):
>
> WARNING: My python skills are newbie at best so I might be uttering complete nonsense - but a matrix might solve your problems.
> 
> Not sure if this is the right way to do it but:
> 
> ```auto
> 
> Cams = Blender.Object.Get("Camera")
> CM = Cams.matrix
> 
> XLoc = CM[3][0]
> YLoc = CM[3][1]
> ZLoc = CM[3][2]
> 
> ```
> 
> It’s probably a screw up but it might inspire a solution 😉
> 
> Regards  
> Fabrizio

Cheers Fabrizio. Copied that in to the code, and it works!

thanks.

- 

brian

---

<div class="post-metadata">

**Author:** ![ilac](https://blenderartists.org/letter_avatar_proxy/v4/letter/i/9e8a1a/32.png) [@ilac](https://blenderartists.org/u/ilac)\
**Post date:** [April 9, 2002, 5:20am UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/7 "2002-04-09T05:20:31Z")

</div>

> Cheers Fabrizio. Copied that in to the code, and it works!
> 
> thanks.
> 
> - 
> 
> brian

I’m the king of the road, baby 😃 !!!

Joking aside, make sure you double x100 check it. I’d take Martin’s advice over mine anytime when it cames to python and he was probably anticipating something my still-developing-python-mind cannot yet fathom. It might prevent some nasty bug in your script turning out later on!

Oh, and good luck with the script! 🙂

---

<div class="post-metadata">

**Author:** ![rndrdbrian](https://blenderartists.org/user_avatar/blenderartists.org/rndrdbrian/32/20_2.png) [@rndrdbrian](https://blenderartists.org/u/rndrdbrian)\
**Post date:** [April 9, 2002, 5:57am UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/8 "2002-04-09T05:57:52Z")

</div>

> [@ilac](#):
>
> I’m the king of the road, baby 😃 !!!
> 
> Joking aside, make sure you double x100 check it. I’d take Martin’s advice over mine anytime when it cames to python and he was probably anticipating something my still-developing-python-mind cannot yet fathom. It might prevent some nasty bug in your script turning out later on!
> 
> Oh, and good luck with the script! 🙂

There doesn’t seem to be any error in that bit of code! It is certainly exporting the camera location OK!

The main problem I’m having is that the file format for RenderBitch isn’t documented, so I’m having to look at the demo scene files, and look through the source code! :-?

Oh, and the RenderBitch website seems to be down as the author has exceeded his monthly bandwidth limit :x

- 

brian

---

<div class="post-metadata">

**Author:** ![eeshlo](https://blenderartists.org/user_avatar/blenderartists.org/eeshlo/32/51_2.png) [@eeshlo](https://blenderartists.org/u/eeshlo)\
**Post date:** [April 9, 2002, 12:45pm UTC](https://blenderartists.org/t/getting-camera-loc-in-python/294833/9 "2002-04-09T12:45:28Z")

</div>

You don’t really have to pay attention to this, since everything works now as you say, but just to inform:  
Blender.Camera.Get() gets you the camera data only, that is, things like Lens, clipping values and so on. To get the location you want the data from the object, which is done with Blender.Object.Get(cameraname).  
So it would be something like:

```auto

cam = Blender.Object.Get(cameraname)
locX, locY, locZ = cam.LocX, cam.LocY, cam.LocZ

```

or

```auto

cam = Blender.Object.Get(cameraname)
loc = cam.loc

```

loc will be a 3-float tuple with the location values.

But the matrix method of course works just as well…

Where did that getPosition() come from? There is a ob.getLocation() function in Publisher though…
