• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Check selection type with python

New Here ,
Jul 22, 2021 Jul 22, 2021

Copy link to clipboard

Copied

Hi, 

let's say I make a selection with a python function like:

 

def Select(D):
    ctx = sd.getContext()
    app = ctx.getSDApplication()
    uiMgr = app.getQtForPythonUIMgr() 
    selection = uiMgr.getCurrentGraphSelection()
       
    return selection
 

 

How do I check the type of this selection??
I use to do it with type() but now I can't.. I check the sdtype docs but I didn't understand the use of it,
I just want to get a bool value to do an if (check if is array):
TOPICS
How to , Scripting

Views

272

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

Hello,

 

First, please note the getCurrentGraphSelection() method of the SDUIMgr and QtForPythonUIMgrWrapper classes are deprecated. Use the getCurrentGraphSelectedNodes() and getCurrentGraphSelectedObjects() methods instead.

 

Similarly to getCurrentGraphSelection(), these methods return array objects, which you can go through with a simple for loop.

 

And to clarify, you may get the type of an SDProperty's value, however array objects and items selected in a graph do not have a type, but a class name which you can access using the getClassName() method.

 

Here is an example:

 

import sd

ctx = sd.getContext()
app = ctx.getSDApplication()
uiMgr = app.getUIMgr() 

selected_objects = uiMgr.getCurrentGraphSelectedObjects()
selected_nodes = uiMgr.getCurrentGraphSelectedNodes()


print('Object selection class= ' + selected_objects.getClassName())

# print class for graph objects (comments, frames, pins)
for obj in selected_objects:
  print('Class= ' + obj.getClassName())


print('Node selection class= ' + selected_nodes.getClassName())

# print if the selection object is an array
if selected_nodes.getClassName() == 'SDArray':
	print('This is indeed an array.')

# print if the array is empty
if not selected_nodes:
	print('...but nothing is selected!')
else:
  # print class and id/label for graph nodes
  for node in selected_nodes:
    print('Class= ' + node.getClassName())
    print('Node= {} / {}'.format(
      node.getDefinition().getId(), 
      node.getDefinition().getLabel()
      ))
	

 

 

And an example of what this code does:

LucaGiarrizzo_2-1627036230235.png

LucaGiarrizzo_3-1627036241522.png

 

I hope this is helpful!

 

Best regards.

 

Luca Giarrizzo | Quality Engineer, 3D & Immersive | Adobe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2021 Jul 23, 2021

Copy link to clipboard

Copied

thanks a lot for the fast answer!, I'll try that then!.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

LATEST

Happy to help!

 

Luca Giarrizzo | Quality Engineer, 3D & Immersive | Adobe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines