Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Custom Script works only once - Obj is not callable

Custom Script works only once - Obj is not callable

The-Digital-Shaman
Advocate Advocate
535 Views
2 Replies
Message 1 of 3

Custom Script works only once - Obj is not callable

The-Digital-Shaman
Advocate
Advocate

Hi there,

 

I am learning to source code from external files.

 

That's a default path for custom scripts:

...\Documents\maya\2022\Scripts\

 

However, I am grouping some of them in here:

...\Documents\maya\2022\Scripts\Sourced\

 

Having to navigate to another folder causes some challenges I try to understand.

 

I.e. Joe's script is run by calling a function named rapidPlace() inside the code.

I renamed *.py file to "JoeWu_RapidPlace_266", placed in the "Sourced" directory now I'm trying to run it using this script:

 

from Sourced import JoeWu_RapidPlace_266
rapidPlace()

 

Result:

# Error: NameError: file <maya console> line 10: name 'rapidPlace' is not defined #

 

Even without renaming python files, I still can't make them work from the "Sourced" folder.

 

Some similar scripts do work, but only once and then;

# Error: TypeError: file <maya console> line 12: 'module' object is not callable # 

 

This is the case with SpeedCut, which I call using this script;

 

from Sourced import JoeWu_SpeedCut
JoeWu_SpeedCut()

 

 

 

Is it apparent what mistake am I making?

 

Cheers,

DS

 
 
 
 
 
0 Likes
Accepted solutions (1)
536 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

You are importing your module correctly, but you aren't telling maya what module you want to run your function from.

 

Correct Synthax would be this:

from Sourced import JoeWu_RapidPlace_266
JoeWu_RapidPlace_266.rapidPlace()

 

The second error stems from the fact that you are trying to call your script like a function. Your Module is called "JoeWu_SpeedCut" but you can't call the module directly. You need to call a function or class inside it. If there isn't a function in the script, open the script file and place the entire script inside a function called "execute" and call it as follows:

from Sourced import JoeWu_SpeedCut
JoeWu_SpeedCut.exectue()

 

 

I hope it helps!

 

Message 3 of 3

The-Digital-Shaman
Advocate
Advocate

I see...makes sense.

It works now.

 

Much appreciated!

0 Likes