Home Website Youtube GitHub

"TypeError: 'str' object is not callable," Mgear 4 custom step problem

I hope I can explain myself with clarity lol I am extremely amateurish in scripting in general.

So in following the first Data Centric Rigging workshop, I’m trying to rebuild guide with the provided custom step import_geo, just importing the geo asset with the rig build. There’s a custom step script provided by Miquel that I’m trying to execute, but, probably since I’m using Mgear 4/Python 3, I get a Syntax error: SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape.

Maybe this is incorrect but I’m trying to accommodate for Python 3 by changing the script to double backslashes (e.g. …\build\assets\examplegeo.ma") or as a raw string (e.g. r"path\of\file\etc) after “pm.importFile”…this results in the error TypeError: ‘str’ object is not callable.

I’m thinking if I step back to earlier Mgear/Python 2 then it’ll be easier following the workshop, but I’d be interested in any insights with this anyways!

Hi @slhouette welcome. When asking for help with scripting, it’s important to actually share the script you’re attempting to run. Then we can help spot the syntax problems. Otherwise we can only guess.

It’s also often helpful to post your full error.

Use three backticks ` to surround your code, and it will show up correctly in the forum.

image

# Your code goes here

Oops sorry! I assumed my link to the video was sufficient.

So here’s the original, just copied from Miquel’s tutorial.

import os
import mgear.shifter.custom_step as cstp
import pymel.core as pm

class CustomShifterStep(cstp.customShifterMainStep):

    def setup(self):
        """
        Setting the name property makes the custom step accessible
        in later steps.

        i.e: Running  self.custom_step("import_bodygeo")  from steps ran after
             this one, will grant this step.
        """
        self.name = "import_bodygeo"

    def run(self):
        """Run method.

            i.e:  self.mgear_run.global_ctl
                gets the global_ctl from shifter rig build base

            i.e:  self.component("control_C0").ctl
                gets the ctl from shifter component called control_C0

            i.e:  self.custom_step("otherCustomStepName").ctlMesh
                gets the ctlMesh from a previous custom step called
                "otherCustomStepName"

        Returns:
            None: None
        """
        self.import_geometry()
        
        pm.select("guide") 
    
    def import_geometry(self):
        path = "\\".join(os.path.abspath(
            os.path.dirname(__file__)).split("\\")[:-2])
        
        pm.importFile("C:\Users\.........\build\assets\bodygeo.ma")

In reference to the backslashes/raw string, here’s both of those.

import os
import mgear.shifter.custom_step as cstp
import pymel.core as pm

class CustomShifterStep(cstp.customShifterMainStep):

    def setup(self):
        """
        Setting the name property makes the custom step accessible
        in later steps.

        i.e: Running  self.custom_step("import_bodygeo")  from steps ran after
             this one, will grant this step.
        """
        self.name = "import_bodygeo"

    def run(self):
        """Run method.

            i.e:  self.mgear_run.global_ctl
                gets the global_ctl from shifter rig build base

            i.e:  self.component("control_C0").ctl
                gets the ctl from shifter component called control_C0

            i.e:  self.custom_step("otherCustomStepName").ctlMesh
                gets the ctlMesh from a previous custom step called
                "otherCustomStepName"

        Returns:
            None: None
        """
        self.import_geometry()
        
        pm.select("guide") 
    
    def import_geometry(self):
        path = "\\".join(os.path.abspath(
            os.path.dirname(__file__)).split("\\")[:-2])
        
        pm.importFile("C:\\Users\\.........\\build\\assets\\bodygeo.ma")

or

import os
import mgear.shifter.custom_step as cstp
import pymel.core as pm

class CustomShifterStep(cstp.customShifterMainStep):

    def setup(self):
        """
        Setting the name property makes the custom step accessible
        in later steps.

        i.e: Running  self.custom_step("import_bodygeo")  from steps ran after
             this one, will grant this step.
        """
        self.name = "import_bodygeo"

    def run(self):
        """Run method.

            i.e:  self.mgear_run.global_ctl
                gets the global_ctl from shifter rig build base

            i.e:  self.component("control_C0").ctl
                gets the ctl from shifter component called control_C0

            i.e:  self.custom_step("otherCustomStepName").ctlMesh
                gets the ctlMesh from a previous custom step called
                "otherCustomStepName"

        Returns:
            None: None
        """
        self.import_geometry()
        
        pm.select("guide") 
    
    def import_geometry(self):
        path = "\\".join(os.path.abspath(
            os.path.dirname(__file__)).split("\\")[:-2])
        
        pm.importFile(r"C:\\Users\\.........\\build\\assets\\bodygeo.ma")

I hope this is sufficient information, I’m a bit embarrassed aha. The learning curve is steep ya’ll!

No need for embarrassment. Scripting is definitely steep, and we’re here to help.

I edited your post. When using backticks, put them above and below your code on separate lines, and it will separate them correctly.

But, is that the actual code you’re running, as is?

  1. pm.importFile("C:\Users\.........\build\assets\bodygeo.ma")

You’ll need to make sure you actually specify a real path here.

  1. Also, it looks like you put 3 different scripts here. Which one is causing the error? Or at least, one-at-a-time, which is the first one causing the error? Fix one, then the next, then the next, etc.

  2. Lastly, please post your entire error. It’s pretty hard to know which part of the multiple scripts are causing the problem. It’s kind of important to see things in actual context.

1 Like