<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Custom node stringArray attribute in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9794596#M5305</link>
    <description>&lt;P&gt;I'm not sure about python but you would find a way to turn this from C++&lt;/P&gt;&lt;P&gt;You may a try the following instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;MFnTypedAttribute&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;typedFn&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;myAttr =&amp;nbsp;typedFn.create("longname",&amp;nbsp;"shortname",&amp;nbsp;MFnData::kString);&lt;BR /&gt;typedFn.setArray(true);&amp;nbsp;&lt;BR /&gt;typedFn.setUsesArrayDataBuilder(true);&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Oct 2020 19:42:00 GMT</pubDate>
    <dc:creator>stuzzz</dc:creator>
    <dc:date>2020-10-09T19:42:00Z</dc:date>
    <item>
      <title>Custom node stringArray attribute</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9794575#M5304</link>
      <description>&lt;P&gt;Hi all! I've been banging my head against the desk all day over this one. I just cannot figure out how to output a string array from a python custom node.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can initialize the plug:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;tAttr = OpenMaya.MFnTypedAttribute()
myPlugin.outPath = tAttr .create('outPath', 'outPath', OpenMaya.MFnData.kStringArray)
tAttr .setWritable(False)
myPlugin.addAttribute(myPlugin.outPath)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;But in my compute function I cannot figure out how to parse a string array as an output value. Eg for a string I would do this:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;data.outputValue(self.outPath).setString("stringToOutput")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought I'd cracked it with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;strArrayDataFn = OpenMaya.MFnStringArrayData()
strArrayDataFn.create(["STRING"])
strArray = strArrayDataFn.array()
data.outputArrayValue(self.outPath).setStringArray(strArray)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I still get a "(kInvalidParameter): Data is not an array" result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If someone could please point out what I'm missing here I would be eternally grateful!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2020 19:27:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9794575#M5304</guid>
      <dc:creator>jan</dc:creator>
      <dc:date>2020-10-09T19:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Custom node stringArray attribute</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9794596#M5305</link>
      <description>&lt;P&gt;I'm not sure about python but you would find a way to turn this from C++&lt;/P&gt;&lt;P&gt;You may a try the following instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;MFnTypedAttribute&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;typedFn&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;myAttr =&amp;nbsp;typedFn.create("longname",&amp;nbsp;"shortname",&amp;nbsp;MFnData::kString);&lt;BR /&gt;typedFn.setArray(true);&amp;nbsp;&lt;BR /&gt;typedFn.setUsesArrayDataBuilder(true);&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2020 19:42:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9794596#M5305</guid>
      <dc:creator>stuzzz</dc:creator>
      <dc:date>2020-10-09T19:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Custom node stringArray attribute</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9795317#M5306</link>
      <description>&lt;P&gt;Thanks for the response Stuzzzz....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, you'll have to forgive me if this question lays bare my fingernail grip of programming but the code you've shown me, doesn't that create the attribute on the custom node ready for connection to other nodes in the DG?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This bit I have managed. I can create a custom node with an output port of type stringArray, I can connect it to other ports of the same type. My problem is that I am incapable of writing output values to it within the plugin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am deeply confused. It appears at one point in history there was an object in openmaya called &lt;A href="https://www.highend3d.com/t/how-to-get-along-with-mstringarray/48971" target="_blank" rel="noopener"&gt;MStringArray&lt;/A&gt; which would appear to be what I need to pass to the output command. Something I imagine that is similar to:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;data.outputArrayValue(self.outPath).setStringArray(MStringArrayObject)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm lost.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 11:01:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9795317#M5306</guid>
      <dc:creator>jan</dc:creator>
      <dc:date>2020-10-10T11:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Custom node stringArray attribute</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9797464#M5307</link>
      <description>&lt;P&gt;I'm certain I'm missing something blindingly obvious here as it seems so basic. So I thought I would post the whole plugin code as an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import maya.OpenMayaMPx as OpenMayaMPx
import maya.OpenMaya as OpenMaya

nodeId = OpenMaya.MTypeId(xxxxxxxxxx)
nodeType = 'amPath' 
 
class amPath(OpenMayaMPx.MPxNode):     
     
    def __init__(self): OpenMayaMPx.MPxNode.__init__(self)   
    
    def compute(self, plug, data):   
        
        #get string
        inString = data.inputValue(self.inString).asString()

        #output string
        data.outputValue(self.outString).setString(inString)

        #output string in an array
        data.outputArrayValue(self.outStringArray).setStringArray([inString])

def initialize():
    
    tAttr = OpenMaya.MFnTypedAttribute()
    
    '''INPUT'''
    amPath.inString = tAttr.create('inString', 'inString', OpenMaya.MFnData.kString)
    tAttr.setReadable(False)
    amPath.addAttribute(amPath.inString)    
    
    '''OUTPUT''' 
    amPath.outString = tAttr.create('outString', 'outString', OpenMaya.MFnData.kString)
    tAttr.setWritable(False)
    amPath.addAttribute(amPath.outString)

    amPath.outStringArray = tAttr.create('outStringArray', 'outStringArray', OpenMaya.MFnData.kStringArray)
    tAttr.setWritable(False)
    amPath.addAttribute(amPath.outStringArray)

    '''TRIGGER'''
    amPath.attributeAffects(amPath.inString, amPath.outString)
    amPath.attributeAffects(amPath.inString, amPath.outStringArray)

def creator(): return OpenMayaMPx.asMPxPtr(amPath()) 

def initializePlugin(obj):
    try: OpenMayaMPx.MFnPlugin(obj).registerNode(nodeType, nodeId, creator, initialize)
    except: pass
 
def uninitializePlugin(obj):
    try: OpenMayaMPx.MFnPlugin(obj).deregisterNode(nodeId)
    except: pass&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 657px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/830206iF08F9BC151E66E51/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;setAttr -type "string" amPath1.inString "THIS IS A STRING";

print `getAttr amPath1.inString`;
THIS IS A STRING

print `getAttr amPath1.outString`;
THIS IS A STRING

print `getAttr amPath1.outStringArray`;
// Error: line 1: RuntimeError: file amPath.py line 24: (kInvalidParameter): Data is not an array //&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 10:50:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/custom-node-stringarray-attribute/m-p/9797464#M5307</guid>
      <dc:creator>jan</dc:creator>
      <dc:date>2020-10-12T10:50:25Z</dc:date>
    </item>
  </channel>
</rss>

