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
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:
I hope this is helpful!
Best regards.
Copy link to clipboard
Copied
thanks a lot for the fast answer!, I'll try that then!.
Copy link to clipboard
Copied
Happy to help!