MPxData read/WriteASCII

56 views
Skip to first unread message

33th...@gmail.com

unread,
Mar 10, 2017, 1:04:59 PM3/10/17
to Python Programming for Autodesk Maya
Hi there,

I'm having some problems implementing the read/write ASCII methods for MPxData. Writing it doesn't seem to be a problem, but reading the arglist within the readASCII method is proving to be rather confusing.

I'm trying to create an MDoubleArray using MArgList::get() or MArglist::asDoubleArray. but give me the same results. However, when I just loop over the length of the array, and fill each value individually from the arglist, it works.


void ProxyData::readArrayFromASCII(MDoubleArray &array, const MArgList &args, unsigned &lastParsedElement){
unsigned int len = (unsigned) args.asInt(lastParsedElement++);
if (!len)
return;

// this works
array.setLength(len);
for (int i = 0; i < len; ++i)
args.get(lastParsedElement++, array[i]);

// // I dont know why this doesnt work
// MStatus stat;
// stat = args.get(lastParsedElement, array);
// CHECK_MSTATUS(stat);

}


From the docs, it states the index argument should point to the int number of items in the array, and the array should follow. So in my ascii, I have something like: 5 0.21 0.35 0.78 0.89 1.2

also, setting the size of the array first, doesn't seem to help.


Any ideas?
Thanks!

33th...@gmail.com

unread,
Mar 10, 2017, 3:30:51 PM3/10/17
to Python Programming for Autodesk Maya
also having some problems with the read/writeBinary methods as well for writing/reading MDoubleArray. I thought it would be something like this, but its not working.

write:
unsigned int weightsLength = weights.length();
out.write( (char*) &weightsLength, sizeof(weightsLength));
out.write( (char*) &weights, sizeof(double)*weightsLength);

read:
unsigned int weightsLength = 0;
in.read( (char*) &weightsLength, sizeof(weightsLength) );
this->weights.setLength(weightsLength);
in.read( (char*) &this->weights, sizeof(double)*weightsLength);


help :)

33th...@gmail.com

unread,
Mar 10, 2017, 4:43:03 PM3/10/17
to Python Programming for Autodesk Maya
ok, got the binary methods working,

unsigned int weightsLength = 0;
in.read( (char*) &weightsLength, sizeof(weightsLength) );
double *w = new double[weightsLength];
in.read( (char*) w, sizeof(double)*weightsLength );
weights = MDoubleArray(w, weightsLength);
delete w;

but still having issues with the ascii :(
Reply all
Reply to author
Forward
0 new messages