Selects object of a certain type and name display

This may be a noob question, however, I am having trouble in trying to grab and check if my selection is of camera /mesh type.

For example, if user clicks onto this button, it will queries if it is a camera. If it is a camera, it will input and displays the name of the camera into a text field. If it is not a camera, it will prompts up a warning asking user to select a camera.

  1. I tried using cmds.ls(type=‘camera’) but it does not seems to be helping in my cause. I will still try to find some other ways, but am I in the right direction?

  2. Then I would like to ask if the following code to grab the camera name, is it the correct way to do so where currentCamTxt is the name of qLineEdit? Cause I realized if I am using just the first line of the code, it will display [u’camera1’] instead of camera1 and this is the only method i can think of, unless there are other better ways in doing it

curSel = cmds.ls(sl=True)
camPath = cmds.listRelatives(curSel, f=True)
camName = str(camPath).split('|')
self.currentCamTxt.setText(str(camName[1]))

To answer your number 1 question :

userCam = cmds.ls(sl=True)
camSceneName = [cmds.listRelatives(c, p=1)[0] for c in cmds.ls(type='camera')]
if set(userCam) & set(camSceneName):
	print userCam[0]

Hope it helps

[QUOTE=AbsurdityDW;25312]To answer your number 1 question :

userCam = cmds.ls(sl=True)
camSceneName = [cmds.listRelatives(c, p=1)[0] for c in cmds.ls(type='camera')]
if set(userCam) & set(camSceneName):
	print userCam[0]

Hope it helps[/QUOTE]

Hi AbsurdityDW, what is this set command that you have used it in the if sentence? I am unable to find any set command other than the sets command (sets command)

Its part of python its self

https://docs.python.org/2/library/sets.html

He’s using intersection from it to test for what exists in both sets

You could just use the ls command to list all the cameras in the selection:

print mc.ls(sl=1, type=‘camera’, dag=1, l=1)