Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maya Python Noob Question
#1
I am learning Python and stuck with the task of passing the Var from one Def to another one inside a Class.
This is a Maya script which duplicates selected objects.
For other parts of the script i need to store both the list of initially selected objects as well as list of duplicated objects.
Would be very thankful for the help. Not sure what I'm doing wrong.

When executing this i get en error -
Error:
# Error: ValueError: No object matches name: *_Gradient_Source #
which makes me feel that self.initial_selection was not passed from the first Def.
(first Def seems to be running without problems)

from maya import cmds


class gradient():

    def __init__(self):
        self.initial_selection = []
        self.the_selection = []


    def selection(self):

        self.initial_selection = cmds.ls(selection=True)
        # Check if something is selected, if not - error message
        if not self.initial_selection:
            nothing_selected_error_message = 'Nothing is selected. Select an object!'
            raise RuntimeError(nothing_selected_error_message)


    def duplication(self):

        # Duplicate and rename with _Gradient_Source
        for each_object in self.initial_selection:
            cmds.duplicate(each_object, name='%s' % each_object + '_Gradient_Source')

        # Hide original objects
        cmds.select(self.initial_selection)
        cmds.hide(self.initial_selection)

        # Select duplicates with _Gradient_Source name
        cmds.select('*_Gradient_Source')
        self.the_selection = cmds.ls(selection=True)
Reply


Messages In This Thread
Maya Python Noob Question - by Iurii_Ledin - Jun-08-2018, 06:42 PM
RE: Maya Python Noob Question - by Iurii_Ledin - Jun-08-2018, 07:55 PM
RE: Maya Python Noob Question - by Iurii_Ledin - Jun-08-2018, 09:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  total Noob question: Why is the code not executed MarkMan 5 633 May-09-2025, 06:15 PM
Last Post: deanhystad
  Function not scriptable: Noob question kaega2 3 2,313 Aug-21-2022, 04:37 PM
Last Post: kaega2
  how to call an object in another function in Maya bstout 0 2,774 Apr-05-2021, 07:12 PM
Last Post: bstout
  Noob question about lists adifrank 4 3,963 Nov-19-2020, 03:26 AM
Last Post: adifrank
  Python class noob nallster7 2 45,905 Sep-17-2020, 10:56 PM
Last Post: snippsat
  Noob question: why is shapesize() not working for my turtle adifrank 8 9,464 Sep-09-2020, 11:13 PM
Last Post: adifrank
  Noob question adifrank 6 4,139 Aug-18-2020, 11:50 PM
Last Post: adifrank
  Python WebsocketServer ? its probably simple but im a noob. qbot333 1 2,709 Jun-03-2020, 06:30 PM
Last Post: ingnelson
  PySide2 Hotkey works only once in Maya LalaGhost 0 2,341 May-19-2020, 05:05 PM
Last Post: LalaGhost
  Code Clean-up and Maya/Python Slicing issues mvvthology 1 3,300 Aug-05-2019, 10:43 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020