<?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: How can I read a float array attribute with Mel or Python? in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13834047#M18053</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;1) What happens if you call &lt;STRONG&gt;setArray(true)&lt;/STRONG&gt; on the attribute before adding it in C++?&lt;BR /&gt;&lt;BR /&gt;2) Did you try saving out a &lt;STRONG&gt;.ma&lt;/STRONG&gt; file to see what the difference is between the attribute created in C++ vs scripting?&lt;/P&gt;</description>
    <pubDate>Thu, 02 Oct 2025 08:26:55 GMT</pubDate>
    <dc:creator>brentmc</dc:creator>
    <dc:date>2025-10-02T08:26:55Z</dc:date>
    <item>
      <title>How can I read a float array attribute with Mel or Python?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13832154#M18049</link>
      <description>&lt;P&gt;I created a node with a float array attribute. Its initialize function is as follows:&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;MStatus MyTestNode::initialize()
{
	MStatus status;
	MFnTypedAttribute tAttr;
	MFnFloatArrayData fnData;

	MObject oData = fnData.create(&amp;amp;status);
	CHECK_MSTATUS_AND_RETURN_IT(status);

	aPositions = tAttr.create("positions", "pos", MFnData::kFloatArray, oData, &amp;amp;status);
	CHECK_MSTATUS_AND_RETURN_IT(status);

	CHECK_MSTATUS_AND_RETURN_IT(addAttribute(aPositions));
	return MS::kSuccess;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, whenever I try to set to values and read from it using a script, I always read back a single value of 0.0.&lt;/P&gt;&lt;P&gt;But if I add a float array attribute to the node using a script, I am then able to access that new attribute.&lt;/P&gt;&lt;P&gt;Here is an example Python script:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import maya.cmds as mc

mc.createNode('MyTestNode', n='MyTestNode1')
mc.addAttr(ln='fArray', sn='fa', dt='floatArray')
mc.setAttr("MyTestNode1.positions", (0.1, 0.25, 0.5, 0.75), type="floatArray")
mc.setAttr("MyTestNode1.fArray", (0.1, 0.25, 0.5, 0.75), type="floatArray")
print('positions : {0}'.format(mc.getAttr("MyTestNode1.positions")))
print('fArray : {0}'.format(mc.getAttr("MyTestNode1.fArray")))
print("")

print('positions type : {0}'.format(mc.getAttr("MyTestNode1.positions", type=True)))
print('fArray type : {0}'.format(mc.getAttr("MyTestNode1.fArray", type=True)))&lt;/LI-CODE&gt;&lt;P&gt;Reading from positions returns 0.0&lt;/P&gt;&lt;P&gt;Reading from fArray returns&amp;nbsp;[0.10000000149011612, 0.25, 0.5, 0.75]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The types are also different. positions returns a type of "typed" while fArray returns a type of "floatArray".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I am wondering what is different between the attribute created with the C++ API and the one created with maya.cmds.&lt;/P&gt;&lt;P&gt;And how can I use the C++ API to create a float array attribute that can be accessed with scripts, or alternatively, how can I access the C++ float array attribute using scripts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: My goal is to use a single float array attribute and not an array of float attributes (attribute created with&amp;nbsp;setArray(true)).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2025 02:29:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13832154#M18049</guid>
      <dc:creator>morinnicolas8944</dc:creator>
      <dc:date>2025-10-01T02:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a float array attribute with Mel or Python?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13834047#M18053</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;1) What happens if you call &lt;STRONG&gt;setArray(true)&lt;/STRONG&gt; on the attribute before adding it in C++?&lt;BR /&gt;&lt;BR /&gt;2) Did you try saving out a &lt;STRONG&gt;.ma&lt;/STRONG&gt; file to see what the difference is between the attribute created in C++ vs scripting?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 08:26:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13834047#M18053</guid>
      <dc:creator>brentmc</dc:creator>
      <dc:date>2025-10-02T08:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a float array attribute with Mel or Python?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13834100#M18054</link>
      <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;1) What happens if you call &lt;STRONG&gt;setArray(true)&lt;/STRONG&gt; on the attribute before adding it in C++?&lt;/BLOCKQUOTE&gt;&lt;P&gt;When I do this I get an array of (floatArray) attributes. I also need to index into the array to add values with&lt;/P&gt;&lt;LI-CODE lang="python"&gt;mc.setAttr("MyTestNode1.positions[0]", (0.1, 0.25, 0.5, 0.75), type="floatArray")&lt;/LI-CODE&gt;&lt;P&gt;Not adding the&lt;STRONG&gt; [0]&lt;/STRONG&gt; returns an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;2) Did you try saving out a &lt;STRONG&gt;.ma&lt;/STRONG&gt; file to see what the difference is between the attribute created in C++ vs scripting?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Good idea. After running the script in my previous post, the node in the .ma file only contains "0" as the value for &lt;STRONG&gt;positions&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;On the other hand &lt;STRONG&gt;fArray&lt;/STRONG&gt; contains the values I set in the script.&lt;/P&gt;&lt;P&gt;The section of the .ma file for the node is this:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;createNode MyTestNode -n "MyTestNode1";
	rename -uid "C1A2621C-427B-495A-7C67-64854965B319";
	addAttr -ci true -sn "fa" -ln "fArray" -dt "floatArray";
	setAttr ".pos" 0;
	setAttr ".fa" -type "floatArray" 4 0.1 0.25 0.5 0.75 ;&lt;/LI-CODE&gt;&lt;P&gt;Just out of curiosity, I tried setting the value of &lt;STRONG&gt;positions&lt;/STRONG&gt; using MEL instead of Python using the command saved in the .ma file for &lt;STRONG&gt;fArray&lt;/STRONG&gt;, but it didn't make any difference.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;setAttr "MyTestNode1.positions" -type "floatArray" 4 0.1 0.25 0.5 0.75 ;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 09:01:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13834100#M18054</guid>
      <dc:creator>morinnicolas8944</dc:creator>
      <dc:date>2025-10-02T09:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a float array attribute with Mel or Python?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13834182#M18055</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;What version of Maya are you using. I did a similar test here and it works as expected!?&lt;BR /&gt;The only difference is I named the attribute &lt;STRONG&gt;input&lt;/STRONG&gt;/&lt;STRONG&gt;in&lt;/STRONG&gt; since I adapted a plugin node I had lying around to test.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;positions : [0.10000000149011612, 0.25, 0.5, 0.75]
fArray : [0.10000000149011612, 0.25, 0.5, 0.75]

positions type : floatArray
fArray type : floatArray&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 10:40:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13834182#M18055</guid>
      <dc:creator>brentmc</dc:creator>
      <dc:date>2025-10-02T10:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a float array attribute with Mel or Python?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13835144#M18056</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was using Maya 2024, but I just tried with Maya 2026 and had the same problem.&lt;/P&gt;&lt;P&gt;Maybe I can make a clean project with only that node and send it to you because it seems like I am doing something different (and wrong) in the code for the node.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 00:18:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13835144#M18056</guid>
      <dc:creator>morinnicolas8944</dc:creator>
      <dc:date>2025-10-03T00:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a float array attribute with Mel or Python?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13835216#M18057</link>
      <description>&lt;P&gt;Indeed the problem was on my side.&lt;/P&gt;&lt;P&gt;I was doing some manipulations in the attribute changed callback to avoid having identical values in the array, but treating the attribute as an attribute array.&amp;nbsp;That was messing up the attribute when setting its value. After disabling that callback I was able to write to and read the attribute as an array (in both Maya 2024 and 2026).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help and sorry for my mistake!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 02:01:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13835216#M18057</guid>
      <dc:creator>morinnicolas8944</dc:creator>
      <dc:date>2025-10-03T02:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a float array attribute with Mel or Python?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13835613#M18058</link>
      <description>&lt;P&gt;No problem. Glad to hear you got to the bottom of the issue!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 08:10:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-can-i-read-a-float-array-attribute-with-mel-or-python/m-p/13835613#M18058</guid>
      <dc:creator>brentmc</dc:creator>
      <dc:date>2025-10-03T08:10:24Z</dc:date>
    </item>
  </channel>
</rss>

