Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String not callable
#1
So I followed a video from the Autodesk scripting and SDK learning channel



Everything works fine, mostly, but I can't get the last part to work, the string just keeps resulting in an error, and when I do the edit expression part it opens the text editor instead of the expression editor. Does anyone with fresher eyes know what the problem is here? I'm using Maya 2016. Wall

import maya.cmds as c

selectionList = c.ls (orderedSelection=True, type='transform')

if len(selectionList) >=2:
    
    targetName = selectionList[0]
    
    selectionList.remove(targetName)
    
    locatorGroupName = c.group(empty=True, name='expansion_locator_grp#')
    
    maxExpansion = 100
    
    newAttributeName = 'expansion' 
    
    if not c.objExists ('%s.%s' % (targetName, newAttributeName)):
        
        c.select(targetName)
        
        c.addAttr(longName=newAttributeName, shortName='exp', attributeType='double', min=0, max=maxExpansion, defaultValue=maxExpansion, keyable=True)
       
    for objectName in selectionList:
        
        coords = c.getAttr('%s.translate' % (objectName))[0]
        
        locatorName=c.spaceLocator(position=coords, name='%s_loc#'%(objectName)) [0]
        
        c.xform (locatorName, centerPivots=True)
        
        c.parent(locatorName, locatorGroupName)
        
        pointConstraintName= c.pointConstraint([targetName, locatorName], objectName, name='%s_pointConstraint#'%(objectName)) [0]
                                      
        c.expression(alwaysEvaluate=True,
                    name='%s_attractWeight'%(objectName),
                    object= pointConstraintName,
                    string='%sW0=%s-%s.%s'(targetName, maxExpansion, targetName, newAttributeName))
                    
        c.connectAttr ('%s.%s'%(targetName, newAttributeName),
                      '%s.%sW1'%(pointConstraintName, locatorName))
           
    c.xform (locatorGroupName, centerPivots=True)
Error is this
# Error: line 1: TypeError: file <maya console> line 38: 'str' object is not callable #
Reply
#2
You need the % operator for string formatting, like you have on all of the other lines.

That is and old, clunky way to handle string formatting. You should look into the format method of strings, or the even newer f-string syntax (Python 3.6+).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Feb-08-2019, 10:52 PM)ichabod801 Wrote: You need the % operator for string formatting, like you have on all of the other lines.

That is and old, clunky way to handle string formatting. You should look into the format method of strings, or the even newer f-string syntax (Python 3.6+).

Doh thank you, I can't believe I didn't cop that, I kept checking to make sure I had everything typed correctly.

We just started doing some coding in college so I wanted to learn some more stuff as I mainly use expressions for effects like fire etc. so I found that tutorial and just wanted to give it a try.
Reply


Forum Jump:

User Panel Messages

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