On Mon, Nov 13, 2017 at 10:17 AM vilkdage <[email protected]> wrote:
> my apologies, is there a way I can edit original post?
>
I think only moderators (myself) can edit posts. But no reason to do it as
this point since many people already received it via email.
>
> Yes, that is a problem. I would not have it if I used cmds, but PyMel
> throws back and node type which makes it impossible to compare values
> between what i am getting from findItems() and pm.ls(sl=1) unless I were
> to remove the first part of each string which tells nodetype. I also would
> not have this kind of problem if I used maya API, but I am not familiar
> with its syntax.
>
> Is the best solution to remove nodetype from what pm.ls(sl=1) gives me?
>
Lets just look at this snippet specifically:
def populateSourceItems(self):
sourceItems = pm.ls(sl=1)
# items currently listed in QListWidget
lst = [i.text() for i in self.sourceWidget.findItems("",
QtCore.Qt.MatchContains)]
for i in sourceItems:
item = QtWidgets.QListWidgetItem("%s" % i)
self.sourceWidget.addItem(item)
You have full control over what value from your PyMel objects that you want
to add to your widget. So it shouldn't matter if its the cmds module,
PyMel, the API, or whatever. You just have to choose if you are going to
convert it to a string, or specifically use the shortName() vs longName().
If you are currently just dumping all of the list values, why not check if
you already have it in the list before adding it?
# items currently listed in QListWidget
existing = set(i.text() for i in
self.sourceWidget.findItems("", QtCore.Qt.MatchContains))
for i in sourceItems:
text = str(i)
if text in existing:
continue
item = QtWidgets.QListWidgetItem(text)
item.setData(QtCore.Qt.UserRole, i)
self.sourceWidget.addItem(item)
As you can see, you could also store the PyMel node on the item so that it
could be retrieved later via item.data(QtCore.Qt.UserRole)
--
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/2efd9ddf-1f61-4b4b-8c44-86191a81d8ec%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/2efd9ddf-1f61-4b4b-8c44-86191a81d8ec%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1ngM3mEjMw1xnYO57ZTATLXAM%2BBZy%2BLf4vziiiBpN77Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.