Beginner that needs help with creating a tool in Python


#1

Hello people :slight_smile:

I’m a VFX student and at the moment I’ve been trying to create a very basic tool. But I’m currently having problems with it.

I’m a complete novice. I just started learning a week ago and I’ve been watching tutorials on python and a bit on MEL. For this tool I’m working with Python.

I’ve screenshot and provided some annotations with it:

This is a quick overview of the tool I’m creating: i.imgur.com/hIaHFB8.png

This is the problem I’m having: i.imgur.com/K6dKE7C.png

This is what I want: i.imgur.com/lN8sMi

I had a better idea of linking the fractal shader to the sculpt geo tool > attribute maps > import but I think that’s too much for me as I have no idea how to do it since I just started.

Any help would great please? thank you.


#2

Many solutions :

1 - the easiest :


import maya.mel as mel
mel.eval('artImportMapDialog "artPuttyCtx";') #to execute a mel string from python

2 - in Mel, you can do :

whatIs artImportMapDialog; // return the path of the script, you can open it and check how it works 

#3

For the 1 - easiest’’. I tried copying and pasting it in the maya python script editor and it gives me this:

artImportMapDialog “artPuttyCtx”;
// Error: line 1: Cannot find procedure “artImportMapDialog”. //

Error: line 1: RuntimeError: file <maya console> line 3: Error occurred during execution of MEL script

line 1: line 1: Cannot find procedure “artImportMapDialog”. #
// Result: scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|formLayout87|formLayout89|paneLayout2|paneLayout3|tabLayout2|formLayout94|cmdScrollFieldExecuter4 //

I’m most likely sure that I shouldnt just copy and paste it in and hope it works, I’m guessing theres more to it than that.

The maya.mel as mel acts as a converter from MEL into a Python data type and returns it. From my basic understanding I think?

Note: Trying my best to understand, so I’m sorry if I’m slow when it comes to figuring it out :slight_smile:


#4

Huuum, it is working fine here.

did you execute :

import maya.mel as mel
 mel.eval('artImportMapDialog "artPuttyCtx";')

#5
Oh I tried again and it works thanks :)

I have another small problem now.
When I open my py file into the script editor. it gives me this when I click on the UI button.

# Error: NameError: file &lt;maya console&gt; line 123: global name 'assignObjectListToShader' is not defined # 

This is the part.

    def assignSelectionToShader(shader=None,*args):
        sel = cmds.ls(sl=True, l=True)
        if sel:assignObjectListToShader(sel,shader)
        assignSelectionToShader('lambert1') 

This is the UI button:

cmds.button('assignSelectionToShader', label="Default Lambert",w= 131, h= 34,command = terrain().assignSelectionToShader)

But it didnt give me that error the last time I was on Maya. the UI button worked fine.