Getting unexpected indent error when executing python script in script editor.

Getting unexpected indent error when executing python script in script editor.

hitecom8172
Enthusiast Enthusiast
29,970 Views
36 Replies
Message 1 of 37

Getting unexpected indent error when executing python script in script editor.

hitecom8172
Enthusiast
Enthusiast

i am getting an unexpected indent error in the script editor when trying to execute this python script.i didnt write this script just copied it from somewhere else cause i dont know how to write code.i want to create lpe for the light groups automatically.I will attach the script down below.

 

import pymel.core as pmc
import mtoa

interface = mtoa.aovs.AOVInterface()

class Aov(object):
def _init_(self,name,lpe):
self.name = name
self.lpe = lpe
self.lpeGroup = None

def addlightgroup(self,lightgroup):
self.ipegroup = self.lpe.replace('L.', *L.'()'*.format(lightgroup))


aovkeys = [ Aov("diffuse_direct". lpe = "C<RD>L"),
Aov("diffuse_indirect". lpe = "C<RD>[DSVOB].*"),
Aov("specular_direct". lpe = "C<RS[^'coat']>L"),
Aov("specular_indirect". lpe = "C<RS[^'coat']>[DSVOB].*"),
Aov("transmission_direct". lpe = "C<TS>L"),
Aov("transmission_indirect". lpe = "C<TS>[DSVOB].*"),
]

def getlights():
return pmc.ls(type['aiAreaLight', 'aiSkyDomeLight'])

def getlightgroup():
groups = []
for light in getlights():
groups.append(light.aiAov.get())
return groups

for aovKey in aovKeys:
for lightgroup in getlightgroups():
sceneAov = interface.addAOV("{}_{}*.format(lightgroup,aovKey.name))
aiAov = pmc.Pynode(sceneAov.node)
aovkey.addlightgroup(lightgroup)
aiAov.lightPathExpression.set(aovkey.lpeGroup)

 

also im attaching the the screen shot of the script editor.Please help ASAP!!!.lpe script error.jpg

 

0 Likes
Accepted solutions (1)
29,971 Views
36 Replies
Replies (36)
Message 21 of 37

hitecom8172
Enthusiast
Enthusiast

Ok ill do that in a second

0 Likes
Message 22 of 37

hitecom8172
Enthusiast
Enthusiast

the code feature destroyed my code so i pasted it here instead https://paste.ofcode.org/33DxVfbwuJMzDxryqUmrXdd

0 Likes
Message 23 of 37

hitecom8172
Enthusiast
Enthusiast

my code gets distorted so here it is https://paste.ofcode.org/33DxVfbwuJMzDxryqUmrXdd

0 Likes
Message 24 of 37

kevin.picott
Alumni
Alumni

There is no error when I run that code. From the script editor window enable the "History > Show Stack Trace" option and paste the exact error text you are receiving.



Kevin "Father of the DG" Picott

Senior Principal Engineer
0 Likes
Message 25 of 37

hitecom8172
Enthusiast
Enthusiast

# Warning: Unknown object type: aiArealight # .when i run the whole thing again.

0 Likes
Message 26 of 37

kevin.picott
Alumni
Alumni

You've miscapitalized the names of the node types. It should be aiAreaLight and aiSkyDomeLight. You can see all of the correct spellings of the node types in the mtoa plug-in using this command:

cmds.pluginInfo( 'mtoa', query=True, dependNode=True )


Kevin "Father of the DG" Picott

Senior Principal Engineer
0 Likes
Message 27 of 37

hitecom8172
Enthusiast
Enthusiast

now i get this

Error: 'module' object has no attribute 'Pynode'
# Traceback (most recent call last):
# File "<maya console>", line 31, in <module>
# AttributeError: 'module' object has no attribute 'Pynode' #

0 Likes
Message 28 of 37

kevin.picott
Alumni
Alumni

The fully qualified name is pymel.core.general.PyNode(...) - you should really be digging into the documentation before trying to run these scripts. http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__PyMel_generated_classes_pymel_core_general_pym... is a good starting place.



Kevin "Father of the DG" Picott

Senior Principal Engineer
0 Likes
Message 29 of 37

hitecom8172
Enthusiast
Enthusiast

I didn't write the script i copied it but i really need this to work i want to create lpe automatically with this script im only 13 i dont know python fully. I would really appreciate if you could fix this script for me or guide me how to fix it.  I would really appreciate that.

Yours humbly, 

Om. 

0 Likes
Message 30 of 37

kevin.picott
Alumni
Alumni

Good for you for jumping into something complex like this, and let it be a lesson for you that if you try to use things without understanding how they work you are in for a lot of frustration.

 

Tip #1: Python is very fussy about capitalization and spaces so always be sure they match

Tip #2: Python has built in help that can give you a lot of information that helps you figure it out. The syntax is "help(OBJ)". In this case "help(pmc.Pynode)" would have told you that Pynode does not exist.

Tip #3: Python objects have two special members that go into constructing the help information, but which have more specific information that can help you find something you aren't quite sure about. For example "help(pmc)" would only tell you that a bunch of extra modules exist and you wouldn't think to look at "help(pmc.general)" to find PyNode, however if you "print pmc.__doc__" you'd see an entry in the dictionary for "PyNode".

Tip #4: The nice thing about Python is that it is interactive so you can execute one line at a time and see where the problems are. Learn how to interpret the error messages; they are trying to help you.
Tip #5: When in doubt the online Maya documentation is quite detailed, and Google is your friend.

 

That being said here is a version of your script with the proper object names and spacing to help you on your way: https://paste.ofcode.org/BLkfmM52zzyaXLJ4Ytd4dA



Kevin "Father of the DG" Picott

Senior Principal Engineer
0 Likes
Message 31 of 37

hitecom8172
Enthusiast
Enthusiast

thank you so much that solved the indentation error but something seems wrong here. it executes the script and create the aovs but it does not give me the contribution from the individual lights which i want instead it gives me the the global contribution for the entire scene which i get from the default aovs. the individual contribution is not there.

0 Likes
Message 32 of 37

kevin.picott
Alumni
Alumni
Accepted solution

Well I'm no Arnold expert but 5 minutes looking at the documentation https://docs.arnoldrenderer.com/display/A5AFMUG/Introduction+to+Light+Path+Expressions tells me that this script cannot do what you are trying to do as the array doesn't filter based on light sources. You probably need something like this:

aovkeys = [ Aov("RGBA", lpe = "C.<L.>*") ]

This line also needs correcting as the Python format method looks for {}, not ():

self.lpegroup = self.lpe.replace('L.',"L.'{}'".format(lightgroup))

I've pasted the corrected version i https://paste.ofcode.org/grkMLA3ErUgL3bcbWSuBEi but I'm afraid I have no further time to help. I believe the documentation sources I've given you have more than enough information for you to figure out your problem; good luck!



Kevin "Father of the DG" Picott

Senior Principal Engineer
Message 33 of 37

hitecom8172
Enthusiast
Enthusiast

that worked thank you but how do i replicate this for multiple aovs when i try copy pasting the same code and changing the names in the next line how do i make it work for mutiple aovs? And also how did you create that lpe the one that you use is not present here: https://docs.arnoldrenderer.com/display/A5ARP/Light+Path+Expression+AOVs. where do i find the ones that you used? Sorry for bothering you the people at arnold awnsers arent very helpful.

0 Likes
Message 34 of 37

kevin.picott
Alumni
Alumni

You don't have to copy/paste, just add a new entry to the aovkeys list (with a slight change to make the LPE correspond to what you'll see in the LPE documentation):

    def addlightgroup(self,lightgroup):
        self.lpegroup = self.lpe.replace('L',"<L.'{}'>".format(lightgroup))

aovkeys = [ Aov("RGBA", lpe = "CL.*"), Aov("specular", lpe="C<RS>L.*") ]

At the top of that page is this line linking to the LPE tutorials, where you'll find the other expressions I used.

There is also an Introduction to Light Path Expressions tutorial.

This line in particular is what told me what the "addlightgroup" method was doing:

For light group AOVs, using <L.> is required instead of just L.


Kevin "Father of the DG" Picott

Senior Principal Engineer
0 Likes
Message 35 of 37

hitecom8172
Enthusiast
Enthusiast

By the last line L is to be replaced with<L.> what do you mean by this? Where should this be replaced or added? 

0 Likes
Message 36 of 37

kevin.picott
Alumni
Alumni

That wasn't me, that was the documentation I referenced. Please read it. It is what the addlightinggroup method does.



Kevin "Father of the DG" Picott

Senior Principal Engineer
0 Likes
Message 37 of 37

mspeer
Consultant
Consultant

Hi!

 

Here is the other link @kevin.picott mentioned.

https://docs.arnoldrenderer.com/display/A5ARNTUT/Introduction+to+Light+Path+Expressions

 

As he mentioned he does not have time to assist you further with this.

If you are new to scripting i recommend to start with something simpler.

However if other users want to help you further with this they are free to do so.

0 Likes