Selecting scene camera with shortcode

It can be difficult to quickly find and select the scene camera from many other objects in large scenes. However, we can make an operator and assign its call to a hotkey to find the scene camera in a moment.

We can get the current scene camera with:

To select it, we can execute the following command:

Let’s create an operator to call this:

and register it Blender Python API:

All together:

After executing this code from the Blender text editor, we can call our operator, for example, from the Python console:

Now the current scene camera will be selected.

To map our operator to a shortcode, open the Preferences window and switch to the KeyMap section.

Expand the “3D View – 3D View (Global)” section and add a new keymap by pressing the “New” button.

Type the “bl_idname” value of our operator in the operator field and assign a convenient key for calling, for example, “Y”.

Now when we press the “Y” key on the keyboard, we will select the current scene camera.

To reset other selections and make only the camera selected, we can improve our operator as follows – before code of selecting the camera, type the following code for deselected all the previous selections:

We can improve our operator more by adding the centering of the viewport window on the selected camera.

We can center the viewport window on the selected object with the operator:

Let’s add this operator call after the selecting camera code.

The updated execute function of our operator now looks like the following:

Now, when we press the “Y” hotkey, only the current scene camera becomes selected, and the viewport window will center on it.


*.blend and *.py file with an example code for my subscribers on Patreon

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments