@DeadlyNightshade (DeadlyNightshade) posted a new topic, subject "PyMEL issue in Maya 2012". It read:

   I have an issue with pymel.core.nodetypes.NurbsCurve.form() in Maya 2012. It appears that the class method doesn't even exist. Try it yourself:
    
    Create a NURBS curve, select it and run this code:
    [code] 
        import pymel.core as pm
        
        sel = pm.ls(sl=True)[0]
        print sel.form()
        
    [/code]
    
    # Error: The object <nt.Transform(u'curve1')> does not support the ‘f' method
    
    # Traceback (most recent call last):
    
    # File “<maya console>”, line 4, in <module>
    
    # File “E:\Autodesk\Maya2012\Python\lib\site-packages\pymel\core\general.py”, line 2325, in **call**
    
    # raise TypeError(“The object <%s> does not support the ‘%s' method” % (repr(self.node()), self.plugAttr()))
    
    # TypeError: The object <nt.Transform(u'curve1')> does not support the ‘f' method
    
    But according to the 2011 documentation, there should be a form() class method:  
    Official docs

So @CMCPasserby (CMCPasserby) replied

    Form() is a method of NurbsCurve not Transform
    
    Try this
    [code] 
        import pymel.core as pm
        
        sel = pm.ls(sl=True)[0].getShape()
        print sel.form()
        
        
    [/code]

After which, @DeadlyNightshade (DeadlyNightshade) added

    While that might be true, it does not explain Maya's odd behavior.  
    Testing this in 2011 and 2015 generates no errors, and I get the proper return “periodic” on a selected nurbs-circle. But in 2012 I get that error message.

To which @CMCPasserby (CMCPasserby) replied

    Sometimes after the creation of a new object the shape is selected by default instead of the transform. Also I think for selections of 1 object l  
    pm.selected() and pm.ls () return a list with both the transform and the shape

@DeadlyNightshade (DeadlyNightshade) replied

    Oh yes - people have warned me about this before but this is actually the first time it has been a problem for me. I guess I'll have to be more careful when running pm.ls
    
    EDIT: But still. Why is Maya 2012 more sensitive about this?  
    Im creating a curve in both 2012 and 2015, select it and then run:
    [code] 
        import pymel.core as pm
        
        sel = pm.ls(sl=True, fl=True)[0]
        print("sel is of type %s")%type(sel)
        print sel.form()
        
    [/code]
    
    Results 2011, 2013, 2014 and 2015:  
    sel is of type <class ‘pymel.core.nodetypes.Transform'>  
    open
    
    Results 2012:  
    sel is of type <class ‘pymel.core.nodetypes.Transform'>
    
    # Error: The object <nt.Transform(u'curve1')> does not support the ‘f' method
    
    # Traceback (most recent call last):
    
    # File “<maya console>”, line 5, in <module>
    
    # File “E:\Autodesk\Maya2012\Python\lib\site-packages\pymel\core\general.py”, line 2325, in **call**
    
    # raise TypeError(“The object <%s> does not support the ‘%s' method” % (repr(self.node()), self.plugAttr()))
    
    # TypeError: The object <nt.Transform(u'curve1')> does not support the ‘f' method

To which @CMCPasserby (CMCPasserby) replied

    Does it still work on all if you explicitly use getShape()?
    
    I find it generally best to be explicit, since if you were using a different language to do this like java c++ or C# it wouldn't even compile for you little lone run

So @DeadlyNightshade (DeadlyNightshade) replied

    Yea, running getShapes() or listRelatives(shapes=True) does get the shape(s) and everything works - for all versions.

After which, @CMCPasserby (CMCPasserby) added

    I would still reccomend being explicit over implict but I think I found part of why you see this behavior.  
    http://download.autodesk.com/global/docs/maya2014/zh_cn/PyMel/generated/classes/pymel.core.nodetypes/pymel.core.nodetypes.Transform.html#pymel.core.nodetypes.Transform.attr
    
    See the checkshape kwarg seems it default to true letting you get shape data from the transform.
    
    Seems it does that for the shorthand as well, so it could possibly be doing that for methods that can't be found on the Transform object.
    
    I still believe it is best to be explicit, to reduce any risk of failure though that could be my bias of mostly working with strongly typed langues that could only do such things if generics were used.

@DeadlyNightshade (DeadlyNightshade) replied

    Agreed. I think its a good idea for me to be explicit, as I plan on moving on to other more strongly typed languages at some time (C# and then maybe one day, C++)

After which, @CMCPasserby (CMCPasserby) added

    Ya C# is very nice to work with, a lot of your python skills should apply if your are already working with its oop parts


{'source': 'discourse', 'url': 'https://forums.cgsociety.org/t/pymel-issue-in-maya-2012/1674008', 'title': 'PyMEL issue in Maya 2012', 'views': 317, 'has_accepted_answer': False, 'word_count': 724, 'like_count': 0, 'reply_count': 8, 'participant_count': 2, 'posts': 10, 'tags': '', 'author': '@DeadlyNightshade (DeadlyNightshade)', 'participants': '@DeadlyNightshade (DeadlyNightshade), @CMCPasserby (CMCPasserby)', 'image_url': '', 'created_at': '2015-01-17T10:15:14.000Z', 'last_posted_at': '2015-01-18T07:42:22.000Z'}