![]() |
String not callable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: String not callable (/thread-15982.html) |
String not callable - nexahs - Feb-08-2019 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. ![]() 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 # RE: String not callable - ichabod801 - Feb-08-2019 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+). RE: String not callable - nexahs - Feb-09-2019 (Feb-08-2019, 10:52 PM)ichabod801 Wrote: You need the % operator for string formatting, like you have on all of the other lines. ![]() 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. |