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
#2
I have also tried putting everything inside one Def and it works fine,
which again makes me feel that the problem is with passing the Variable from first Def to the Second one.
Reply
#3
I just realized that i was not running the .py file correctly inside Maya.
The actual Py code is fine, i was just running each function in a separate class instance what is why it was not working correctly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function not scriptable: Noob question kaega2 3 1,170 Aug-21-2022, 04:37 PM
Last Post: kaega2
  how to call an object in another function in Maya bstout 0 2,069 Apr-05-2021, 07:12 PM
Last Post: bstout
  Noob question about lists adifrank 4 2,863 Nov-19-2020, 03:26 AM
Last Post: adifrank
  Python class noob nallster7 2 31,318 Sep-17-2020, 10:56 PM
Last Post: snippsat
  Noob question: why is shapesize() not working for my turtle adifrank 8 5,745 Sep-09-2020, 11:13 PM
Last Post: adifrank
  Noob question adifrank 6 2,730 Aug-18-2020, 11:50 PM
Last Post: adifrank
  Python WebsocketServer ? its probably simple but im a noob. qbot333 1 1,972 Jun-03-2020, 06:30 PM
Last Post: ingnelson
  PySide2 Hotkey works only once in Maya LalaGhost 0 1,773 May-19-2020, 05:05 PM
Last Post: LalaGhost
  Code Clean-up and Maya/Python Slicing issues mvvthology 1 2,414 Aug-05-2019, 10:43 PM
Last Post: Yoriz
  Python on Linux, Total Noob to Both halcyon 4 3,049 May-27-2019, 10:40 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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