Jump to content
  • Advertisement
Sign in to follow this  
Flawe

Maya api: MFnSet::create

This topic is 3804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create a set through the Maya API and I'm getting MStatus::kSuccess, but no set is created. MFnSet set; MObject dagSet = set.create(selectionList, MFnSet::kNone, status); The selection list is a list of all selected meshes in the scene and dagSet.isNull() is always true. Anyone have any ideas what I'm doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Alright, heh, this was fun...

The above line actually has to be

MObject dagSet = set.create(selectionList, MFnSet::kNone, &status);

since it needs the pointer to the status variable. Not sending the reference caused an old, obsolete method to be called instead of the one that works. Nothing about it in the documentation, oh well...

Share this post


Link to post
Share on other sites
Still got some troubles with this. It seems that the set is created alright. It shows up in the outliner and it can be manipulated as a set created from within Maya. Though if I save the scene and re-open it, the set disappears. No traces of it whatsoever.

MFnSet::create is supposed to add the object to the dependency graph, according to the documentation. Anyone knows if there's something else I need to do?

Share this post


Link to post
Share on other sites
It should work fine? (I've never had any problems with it anyway). I guess maya might strip it out if there are no objects contained within the set, but I'd be suprised if that was the case. There's always the sets mel command you can fall back on, but typically that just exposes the MFnSet funcs to mel... So it should work the same.

have you tried an

ls -type objectSet

to see if the set is there (and just not displayed in the outliner?)

Share this post


Link to post
Share on other sites
Yeah, I really can't imagine what could go wrong.

I tried your line above and my set seems to be listed there. And it does have meshes inside, as I create it based on the current selection.

Still nothing, if I save the scene and open it again, it's like the set never existed.


EDIT: I've tried using mel commands and I get the same result. I can create the sets, add the attributes I want and change them however I want. All sets disappear after a save/load.

[Edited by - Flawe on July 8, 2008 8:17:52 AM]

Share this post


Link to post
Share on other sites
hmmm... well, I've tried this code and it works for me fine. (and you can re-load)

class SetTest
: public MPxCommand
{
public:
virtual bool isUndoable() const ;
MStatus doIt(const MArgList& args);
static void* creator();
private:
};

bool SetTest::isUndoable() const
{
return false;
}
void* SetTest::creator()
{
return new SetTest;
}
MStatus SetTest::doIt(const MArgList& args)
{
// the return status
MStatus status = MS::kSuccess;
MFnSet fn;
MSelectionList sl;
status = MGlobal::getActiveSelectionList(sl);
if (status != MS::kSuccess)
{
return status;
}
MObject oset = fn.create(sl,MFnSet::kNone,false,&status);
return status;
}

#ifdef WIN32
#define MLL_EXPORT __declspec(dllexport)
#else
#define MLL_EXPORT
#endif

MLL_EXPORT MStatus initializePlugin(MObject obj)
{
MFnPlugin plugin( obj, "SetTest", "1.0", "Any");
return plugin.registerCommand("setTest",SetTest::creator);
}
MLL_EXPORT MStatus uninitializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj);
return plugin.deregisterCommand( "setTest" );
}



Have you made sure that:

1. The file is not set to read only?
2. You are writing to the file you think you are? (not reading from scenes dir, writing to another dir?)
3. Is it being created as a display layer? (passing false as the third param of MFnSet::create should make sure...)

Share this post


Link to post
Share on other sites
Rob, thank you for your reply.

The file is not read only as all other changes are saved except for the sets created through the api. I have checked several times for any mistakes and I'm not saving/loading different files.

This is how I do it...



MSelectionList selectionList;
if( MStatus::kFailure == MGlobal::getActiveSelectionList( selectionList ) ) {
return MStatus::kFailure;
}

MObjectArray selectedSets;
MGlobal::getAssociatedSets( selectionList, selectedSets );
if( selectedSets.length() == 0 ) {
MStatus status;
MFnSet set;
MObject dagSet = set.create( selectionList, MFnSet::kNone, false, &status );
if( status == MStatus::kFailure || dagSet.isNull() ) {
return MStatus::kFailure;
}
}




I'm starting to think it's some small thing I've overlooked. Maya 2008 API btw, if that makes any difference.

EDIT: I see you have yours as a command plugin. The way I'm implementing this is through an exporter plugin. I've also seen that Maya sometimes creates transparent sets while you work which are removed on save/load. Could the way I create the sets cause Maya to handle them like those temporary sets perhaps?

Share this post


Link to post
Share on other sites
Don't test for the failure condition, test to see if it's not a success (since failure is only returned for a very small number of failures, it's normally other things like invalid operation, out of memory etc). It's normally a good idea to propogate those errors back via return args (and a CHECK_STATUS macro makes life a lot easier for debugging - i.e. print out the line and file it failed in). It's Generally a good idea to test every single returned status, since failures do not terminate execution, but normally just generate a tonne more errors for you....

I'm also not entirely sure why you are testing to see if the returned set is null? If the create method succeeded, it's going to be valid...


MSelectionList selectionList;
status = MGlobal::getActiveSelectionList(selectionList);
if( MStatus::kSuccess != status )
return status;

MObjectArray selectedSets;
status = MGlobal::getAssociatedSets(selectionList,selectedSets);
if(status != MStatus::kSuccess)
return status;

if( selectedSets.length() == 0 )
{
MStatus status;
MFnSet set;
MObject dagSet = set.create(selectionList,MFnSet::kNone,false,&status);
if(status != MStatus::kSuccess)
return status;
}


Share this post


Link to post
Share on other sites
Quote:
Original post by Flawe
EDIT: I see you have yours as a command plugin. The way I'm implementing this is through an exporter plugin. I've also seen that Maya sometimes creates transparent sets while you work which are removed on save/load. Could the way I create the sets cause Maya to handle them like those temporary sets perhaps?


It shouldn't make too much difference, though Maya may do funny things if your export process fails and returns a fail code. Generally that's why i test every single return arg....

Share this post


Link to post
Share on other sites
That's a good idea, to test for success only. Didn't really think of that.

I was testing dagSet for null since I had some troubles before when I forgot to send status as a reference. It would then call an obsolete create method which would return null but give MStatus::kSuccess.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!