PDA

View Full Version : C++ API - Create a camera and set active viewport to that camera


vishangshah
03-26-2009, 07:21 AM
Hi,
Here is a question,
how can I create a camera and set it to current viewport view in C++ API,

here is code so far,


M3dView view;
MObject camera;
MDagPath cameraPath;
// create new camera
view = M3dView::active3dView(&status);
MFnCamera fnCamera;
fnCamera.create(camera,NULL);
//
// get dagpath for new camera
cameraPath = pathFromObject(camera);
view.setCamera(cameraPath); // this is causing maya crash


Camara creation successful but setCamera results in Maya crash,
I wonder how can I get dagPath of a newly created MObject,

Thanks

vishangshah
03-26-2009, 09:55 AM
Found the answer,

M3dView view;
MObject camera;
MDagPath cameraPath;
// create new camera
view = M3dView::active3dView(&status);
MFnCamera fnCamera;
fnCamera.create(camera);
fnCamera.getPath(cameraPath);
//
view.setCamera(cameraPath); // this is causing maya crash

ticket01
03-26-2009, 09:59 AM
MFnCamera::create() returns the transform for a newly created camera, in case you don't provide one as first parameter. You do but it's MObject::kNullObj, so you actually don't. ;)

Using MObject camera = fnCamera.create(); will return the transform of the new camera.

Get the MDagPath of that transform or its shape, don't know which one you need exactly and you're done.

CGTalk Moderation
03-26-2009, 09:59 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.