Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

getTranslation is not working or I'm doing something wrong.

getTranslation is not working or I'm doing something wrong.

Anonymous
Not applicable
700 Views
3 Replies
Message 1 of 4

getTranslation is not working or I'm doing something wrong.

Anonymous
Not applicable

Hey guys, using the C++ maya API to get the position of a object, I am using: 

 

  MFnTransform fn(obj);
  
  MVector Translation = fn.getTranslation(MSpace::kTransform);

  std::string s = std::to_string(Translation.x);
  MString m(s.c_str());
  cerr << m << endl;

  std::string ss = std::to_string(Translation.y);
  MString mm(ss.c_str());
  cerr << mm << endl;

  std::string sss = std::to_string(Translation.z);
  MString mmm(sss.c_str());
  cerr << mmm << endl;

But It's not assigning / I'm using the wrong class to get the XYZ, 

 

Screenshot_111.png

 

 

0 Likes
701 Views
3 Replies
Replies (3)
Message 2 of 4

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

MFnTransform seems working fine, could it be wrong at where you getting the object? I've just tested it with Maya 2017 with code below.

 

import maya.OpenMaya as om

selList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(selList)

obj = om.MObject()
selList.getDependNode(0,obj)
fnTransform = om.MFnTransform(obj)

vec = fnTransform.getTranslation(om.MSpace.kTransform)
print vec.x,vec.y,vec.z

Yours,

Li

Message 3 of 4

Anonymous
Not applicable

 

 

//...   
  MItDependencyNodes it(MFn::kMesh);

  while (!it.isDone()) {
    MObject m(it.item());
    CenterOrign(m);
    it.next();
  }
//...

void MyPlugin::CenterOrign(MObject& obj) {
MFnTransform fn(obj);
MVector Translation = fn.getTranslation(MSpace::kTransform);
}

Screenshot_112.png

And I can't check to see if it's assigned so I'm kinda lost here.

Thanks for your reply!

The only thing I can think of is that I am assigning KMeshs as my MObject. Do you know if I am able to call getTranslation on a kMesh? 

 

0 Likes
Message 4 of 4

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I am afraid you have to call it with transform nodes.

 

Yours,

Li