15 #include "maya_funcs.h"
17 #include "pre_maya_include.h"
18 #include <maya/MObject.h>
19 #include <maya/MAngle.h>
20 #include <maya/MFnDependencyNode.h>
21 #include <maya/MStatus.h>
22 #include <maya/MFnStringData.h>
23 #include <maya/MFnNumericData.h>
24 #include <maya/MPlugArray.h>
25 #include <maya/MPlug.h>
26 #include <maya/MFnAttribute.h>
27 #include <maya/MFnTypedAttribute.h>
28 #include <maya/MFnNumericAttribute.h>
29 #include <maya/MFnEnumAttribute.h>
30 #include <maya/MFnCompoundAttribute.h>
31 #include <maya/MFnMatrixData.h>
32 #include <maya/MMatrix.h>
33 #include "post_maya_include.h"
40 get_maya_plug(MObject &node,
const string &attribute_name, MPlug &plug) {
42 MFnDependencyNode node_fn(node, &status);
45 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
49 MObject attr = node_fn.attribute(attribute_name.c_str(), &status);
54 MFnAttribute attr_fn(attr, &status);
57 <<
"Attribute " << attribute_name <<
" on " << node_fn.name().asChar()
58 <<
" is a " << attr.apiTypeStr() <<
", not an Attribute.\n";
62 plug = MPlug(node, attr);
72 is_connected(MObject &node,
const string &attribute_name) {
74 if (!get_maya_plug(node, attribute_name, plug)) {
78 return plug.isConnected();
87 has_attribute(MObject &node,
const string &attribute_name) {
89 MFnDependencyNode node_fn(node, &status);
92 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
96 node_fn.attribute(attribute_name.c_str(), &status);
110 remove_attribute(MObject &node,
const string &attribute_name) {
112 MFnDependencyNode node_fn(node, &status);
115 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
119 MObject attr = node_fn.attribute(attribute_name.c_str(), &status);
128 MFnAttribute attr_fn(attr, &status);
131 <<
"Attribute " << attribute_name <<
" on " << node_fn.name().asChar()
132 <<
" is a " << attr.apiTypeStr() <<
", not an Attribute.\n";
137 MFnDependencyNode::MAttrClass type = node_fn.attributeClass(attr, &status);
140 <<
"Couldn't get class of attribute " << attribute_name <<
" on "
141 << node_fn.name().asChar() <<
".\n";
145 status = node_fn.removeAttribute(attr, type);
148 <<
"Couldn't remove attribute " << attribute_name <<
" from "
149 << node_fn.name().asChar() <<
".\n";
162 get_bool_attribute(MObject &node,
const string &attribute_name,
164 if (!has_attribute(node, attribute_name)) {
170 if (!get_maya_attribute(node, attribute_name, value)) {
172 <<
"Attribute " << attribute_name
173 <<
" does not have a bool value.\n";
174 describe_maya_attribute(node, attribute_name);
186 get_angle_attribute(MObject &node,
const string &attribute_name,
189 if (!get_maya_attribute(node, attribute_name, maya_value)) {
191 <<
"Attribute " << attribute_name
192 <<
" does not have an angle value.\n";
193 describe_maya_attribute(node, attribute_name);
196 value = maya_value.asDegrees();
206 get_vec2_attribute(MObject &node,
const string &attribute_name,
211 if (!get_maya_attribute(node, attribute_name, vec2_object)) {
213 <<
"Attribute " << attribute_name
214 <<
" does not have a vec2 object value.\n";
215 describe_maya_attribute(node, attribute_name);
219 MFnNumericData data(vec2_object, &status);
222 <<
"Attribute " << attribute_name <<
" is of type "
223 << vec2_object.apiTypeStr() <<
", not a NumericData.\n";
227 status = data.getData(value[0], value[1]);
230 <<
"Unable to extract 2 floats from " << attribute_name
231 <<
", of type " << vec2_object.apiTypeStr() <<
"\n";
243 get_vec3_attribute(MObject &node,
const string &attribute_name,
248 if (!get_maya_attribute(node, attribute_name, vec3_object)) {
250 <<
"Attribute " << attribute_name
251 <<
" does not have a vec3 object value.\n";
252 describe_maya_attribute(node, attribute_name);
256 MFnNumericData data(vec3_object, &status);
259 <<
"Attribute " << attribute_name <<
" is of type "
260 << vec3_object.apiTypeStr() <<
", not a NumericData.\n";
264 status = data.getData(value[0], value[1], value[2]);
267 <<
"Unable to extract 3 floats from " << attribute_name
268 <<
", of type " << vec3_object.apiTypeStr() <<
"\n";
280 get_vec2d_attribute(MObject &node,
const string &attribute_name,
284 MObject vec2d_object;
285 if (!get_maya_attribute(node, attribute_name, vec2d_object)) {
287 <<
"Attribute " << attribute_name
288 <<
" does not have a vec2d object value.\n";
289 describe_maya_attribute(node, attribute_name);
293 MFnNumericData data(vec2d_object, &status);
296 <<
"Attribute " << attribute_name <<
" is of type "
297 << vec2d_object.apiTypeStr() <<
", not a NumericData.\n";
301 status = data.getData(value[0], value[1]);
304 <<
"Unable to extract 2 doubles from " << attribute_name
305 <<
", of type " << vec2d_object.apiTypeStr() <<
"\n";
317 get_vec3d_attribute(MObject &node,
const string &attribute_name,
321 MObject vec3d_object;
322 if (!get_maya_attribute(node, attribute_name, vec3d_object)) {
324 <<
"Attribute " << attribute_name
325 <<
" does not have a vec3d object value.\n";
326 describe_maya_attribute(node, attribute_name);
330 MFnNumericData data(vec3d_object, &status);
333 <<
"Attribute " << attribute_name <<
" is of type "
334 << vec3d_object.apiTypeStr() <<
", not a NumericData.\n";
338 status = data.getData(value[0], value[1], value[2]);
341 <<
"Unable to extract 3 doubles from " << attribute_name
342 <<
", of type " << vec3d_object.apiTypeStr() <<
"\n";
353 get_mat4d_attribute(MObject &node,
const string &attribute_name,
357 if (!get_maya_attribute(node, attribute_name, matrix)) {
361 MFnMatrixData matrix_data(matrix, &status);
364 <<
"Attribute " << attribute_name <<
" is of type "
365 << node.apiTypeStr() <<
", not a Matrix.\n";
369 const MMatrix &mat = matrix_data.matrix();
370 for (
int i = 0; i < 4; i++) {
371 for (
int j = 0; j < 4; j++) {
372 value(i, j) = mat(i, j);
387 MFnDependencyNode node_fn(node, &status);
390 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
394 string name = node_fn.name().asChar();
397 for (i = 0; i < node_fn.attributeCount(); i++) {
398 MObject attr = node_fn.attribute(i, &status);
400 MFnAttribute attrib(attr, &status);
402 string attribute_name = attrib.name().asChar();
403 if (attribute_name.find(
"tag", 0) != string::npos) {
404 maya_cat.info() <<
":" << name <<
":" <<
" is tagged with <"
405 << attribute_name <<
">" << endl;
406 tag_names.push_back(attribute_name);
418 get_enum_attribute(MObject &node,
const string &attribute_name,
423 if (!get_maya_plug(node, attribute_name.c_str(), plug)) {
427 MObject attrib = plug.attribute();
428 MFnEnumAttribute enum_attrib(attrib, &status);
431 <<
"Not an enum attribute: " << attribute_name <<
"\n";
436 status = plug.getValue(index);
439 <<
"Could not get numeric value of " << attribute_name <<
"\n";
440 status.perror(
"MPlug::getValue(short)");
444 MString name = enum_attrib.fieldName(index, &status);
447 <<
"Invalid value for " << attribute_name <<
": " << index <<
"\n";
448 status.perror(
"MFnEnumAttribute::fieldName()");
452 value = name.asChar();
462 get_string_attribute(MObject &node,
const string &attribute_name,
466 MObject string_object;
467 if (!get_maya_attribute(node, attribute_name, string_object)) {
469 <<
"Attribute " << attribute_name
470 <<
" does not have an string object value.\n";
471 describe_maya_attribute(node, attribute_name);
475 MFnStringData data(string_object, &status);
478 <<
"Attribute " << attribute_name <<
" is of type "
479 << string_object.apiTypeStr() <<
", not a StringData.\n";
483 value = data.string().asChar();
493 set_string_attribute(MObject &node,
const string &attribute_name,
494 const string &value) {
498 MObject string_object;
499 if (!get_maya_attribute(node, attribute_name, string_object)) {
501 <<
"Attribute " << attribute_name
502 <<
" does not have a string object value.\n";
503 describe_maya_attribute(node, attribute_name);
507 MFnStringData data(string_object, &status);
510 <<
"Attribute " << attribute_name <<
" is of type "
511 << string_object.apiTypeStr() <<
", not a StringData.\n";
515 MString mstring_value(value.data(), value.length());
516 status = data.set(mstring_value);
518 status.perror(attribute_name.c_str());
523 if (!set_maya_attribute(node, attribute_name, string_object)) {
525 <<
"Attribute " << attribute_name
526 <<
" suddenly does not have a string object value.\n";
539 describe_compound_attribute(MObject &node) {
542 MFnCompoundAttribute comp_attr(node, &status);
544 maya_cat.info() <<
"comp_attr has:" << comp_attr.numChildren() <<
" children" << endl;
545 for (
size_t i = 0; i < comp_attr.numChildren(); i++) {
546 MObject child = comp_attr.child(i, &status);
547 if (child.apiType() == MFn::kAttribute3Float){
555 else if (child.apiType() == MFn::kNumericAttribute) {
556 MFnNumericAttribute numeric(child, &status);
558 switch(numeric.unitType()) {
559 case MFnNumericData::kFloat :
561 status = numeric.getDefault(alpha);
562 maya_cat.info() <<
"found a float :" << alpha << endl;
564 case MFnNumericData::kBoolean :
566 status = numeric.getDefault(v);
567 maya_cat.info() <<
"found a bool :" << v << endl;
569 maya_cat.info() << numeric.unitType() << endl;
573 else if (child.apiType() == MFn::kEnumAttribute) {
574 MFnEnumAttribute enu(child, &status);
577 status = enu.getDefault(blah);
578 maya_cat.info() <<
"found a string :" << blah.asChar() << endl;
579 MPlug plug = MPlug(node, child);
580 maya_cat.info() <<
"plug name" << plug.name().asChar() << endl;
593 describe_maya_attribute(MObject &node,
const string &attribute_name) {
595 MFnDependencyNode node_fn(node, &status);
598 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
602 MObject attr = node_fn.attribute(attribute_name.c_str(), &status);
605 <<
"Object " << node_fn.name().asChar() <<
" does not support attribute "
606 << attribute_name <<
"\n";
611 <<
"Attribute " << attribute_name <<
" on object "
612 << node_fn.name().asChar() <<
" has type " << attr.apiTypeStr() <<
"\n";
616 string_mfndata_type(MFnData::Type type) {
618 case MFnData::kInvalid:
621 case MFnData::kNumeric:
624 case MFnData::kPlugin:
627 case MFnData::kPluginGeometry:
628 return "kPluginGeometry";
630 case MFnData::kString:
633 case MFnData::kMatrix:
636 case MFnData::kStringArray:
637 return "kStringArray";
639 case MFnData::kDoubleArray:
640 return "kDoubleArray";
642 case MFnData::kIntArray:
645 case MFnData::kPointArray:
646 return "kPointArray";
648 case MFnData::kVectorArray:
649 return "kVectorArray";
651 case MFnData::kComponentList:
652 return "kComponentList";
657 case MFnData::kLattice:
660 case MFnData::kNurbsCurve:
661 return "kNurbsCurve";
663 case MFnData::kNurbsSurface:
664 return "kNurbsSurface";
666 case MFnData::kSphere:
669 case MFnData::kDynArrayAttrs:
670 return "kDynArrayAttrs";
672 case MFnData::kDynSweptGeometry:
673 return "kDynSweptGeometry";
675 case MFnData::kSubdSurface:
676 return "kSubdSurface";
683 return "**invalid**";
694 list_maya_attributes(MObject &node) {
696 MFnDependencyNode node_fn(node, &status);
699 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
703 string name = node_fn.name().asChar();
706 MPlugArray connections;
707 status = node_fn.getConnections(connections);
709 status.perror(
"MFnDependencyNode::getConnections");
713 << name <<
" has " << connections.length() <<
" connections.\n";
714 for (i = 0; i < connections.length(); i++) {
715 MPlug plug = connections[i];
718 <<
" " << i <<
". " << plug.name().asChar() <<
", "
719 << plug.attribute().apiTypeStr() <<
", "
720 << plug.node().apiTypeStr();
721 if (plug.attribute().apiType() == MFn::kCompoundAttribute) {
725 if (plug.isConnected()) {
735 << name <<
" has " << node_fn.attributeCount() <<
" attributes.\n";
736 for (i = 0; i < node_fn.attributeCount(); i++) {
737 MObject attr = node_fn.attribute(i, &status);
739 MFnTypedAttribute typed_attrib(attr, &status);
743 <<
" " << i <<
". " << typed_attrib.name().asChar()
744 <<
" [" << attr.apiTypeStr() <<
", "
745 << string_mfndata_type(typed_attrib.attrType()) <<
"]\n";
747 MFnAttribute attrib(attr, &status);
751 <<
" " << i <<
". " << attrib.name().asChar()
752 <<
" [" << attr.apiTypeStr() <<
"]\n";
756 <<
" " << i <<
". [" << attr.apiTypeStr() <<
"]\n";
This is the base class for all three-component vectors and points.
This is a 4-by-4 transform matrix.
This is the base class for all two-component vectors and points.
This is the base class for all two-component vectors and points.
This is the base class for all three-component vectors and points.