Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[Maya API Question] How to remove a manipToPlugCallback?

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
1059 Views, 6 Replies

[Maya API Question] How to remove a manipToPlugCallback?

Anonymous
Not applicable

I'm learning Maya API. I'm work with the example "rotateManip".

I knew the code which is used to connect the rotate manipulator and add a callback to the rotate plug.

rotatePlugIndex = addManipToPlugConversionCallback( rotatePlug,
(manipToPlugConversionCallback)
&rotateManipContainer::rotationChangedCallback);

 

Because I want to break the connection between the rotate manipulator and the  rotate plug, I tried these:

MModelMessage::removeCallback(rotatePlugIndex);

 

But, no luck. It didn't work.

So, my questions are:

(1)How to break or stop connection between the rotate manipulator and the rotate plug?

(2)How to remove manipToPlug Callback?

 

Thanks for helping.

Tony

 

0 Likes

[Maya API Question] How to remove a manipToPlugCallback?

I'm learning Maya API. I'm work with the example "rotateManip".

I knew the code which is used to connect the rotate manipulator and add a callback to the rotate plug.

rotatePlugIndex = addManipToPlugConversionCallback( rotatePlug,
(manipToPlugConversionCallback)
&rotateManipContainer::rotationChangedCallback);

 

Because I want to break the connection between the rotate manipulator and the  rotate plug, I tried these:

MModelMessage::removeCallback(rotatePlugIndex);

 

But, no luck. It didn't work.

So, my questions are:

(1)How to break or stop connection between the rotate manipulator and the rotate plug?

(2)How to remove manipToPlug Callback?

 

Thanks for helping.

Tony

 

Labels (1)
6 REPLIES 6
Message 2 of 7
jmreinhart
in reply to: Anonymous

jmreinhart
Advisor
Advisor

you can't remove the callback manually because when you create it. It doesn't give you a callback id. I suppose you could get a list of all callbacks and their ids and somehow find it. Why are you trying to delete the callback?

0 Likes

you can't remove the callback manually because when you create it. It doesn't give you a callback id. I suppose you could get a list of all callbacks and their ids and somehow find it. Why are you trying to delete the callback?

Message 3 of 7
Anonymous
in reply to: jmreinhart

Anonymous
Not applicable

In fact, few days ago, I was trying to write a world-base rotation manipulator.

By observing the original one in Maya, 3 rotation axes will always keep at the initial direction.

To realize the behavior, I used the code in its MPxManipContainer::doRelease()

rotateManipFn.setInitialRotation(MEulerRotation(0.0,0.0,0.0));

 

The code realized the behavior I wanted, but the problem was coming.

The problem is that the rotate plugs will be initialized simultaneously, when the setInitialRotation() is executing.

 

Due to the reason, I need to understand how to control the conversion callback (in the case, it's a manip-to-plug conversion callback) manually.

 

You mentioned the first important thing, ""deleting a callback requires its ID.""

The plug index isn't ID. Therefore, I can't stop the callback, right?

 

The second thing you mentioned, ""Listing all callbacks.""

It might be a solution.

 

Any ideas, please. Thanks.

Have a good day.

Tony

 

 

 

 

0 Likes

In fact, few days ago, I was trying to write a world-base rotation manipulator.

By observing the original one in Maya, 3 rotation axes will always keep at the initial direction.

To realize the behavior, I used the code in its MPxManipContainer::doRelease()

rotateManipFn.setInitialRotation(MEulerRotation(0.0,0.0,0.0));

 

The code realized the behavior I wanted, but the problem was coming.

The problem is that the rotate plugs will be initialized simultaneously, when the setInitialRotation() is executing.

 

Due to the reason, I need to understand how to control the conversion callback (in the case, it's a manip-to-plug conversion callback) manually.

 

You mentioned the first important thing, ""deleting a callback requires its ID.""

The plug index isn't ID. Therefore, I can't stop the callback, right?

 

The second thing you mentioned, ""Listing all callbacks.""

It might be a solution.

 

Any ideas, please. Thanks.

Have a good day.

Tony

 

 

 

 

Message 4 of 7
muir.j
in reply to: Anonymous

muir.j
Contributor
Contributor

This is a fairly good article on how manipulators work. I've been doing some manipulators recently and it took a while to understand it.

 

https://around-the-corner.typepad.com/adn/2012/10/maya-custom-manipulators-.html

 

One of the key points is that when you connect the plug to the manipulator, it is a 1:1 relationship that exactly keeps the units the same.

e.g.

fnCurvePoint.connectToCurvePlug(curvePlug); //This sets up a 1:1 relationship

 

If you want to do something different than a 1:1 relationship, you have to not use the connectToPlug method, but actually use callbacks instead. Even if you want to do a conversion (radians to degrees) you have to use the callback method (which is super frustrating).

 

To do that you need to get the index of the specific manipulator pieces (e.g disc has 3 elements - its position, axis orientation and the angle itself). You need this index later to use in the callback.

 

 unsigned discAngleIndex = fnDisc.angleIndex();
unsigned discCenterIndex = fnDisc.centerIndex();
unsigned discAxisIndex = fnDisc.axisIndex();

 

To add the callback, its like this...

 

addPlugToManipConversionCallback(discCenterIndex, (plugToManipConversionCallback)&MyNodeManip::discCenterCallback);

 

For the callback code you need to check that the index matches up with the proper element, and then

 

MManipData MyNodeManip::discCenterCallback(unsigned manipIndex) {

 

if (manipIndex == discCenterIndex ) {

MManipData manipData;
MFnNumericData numData;
MObject numDataObj = numData.create(MFnNumericData::k3Double);
numData.setData(center.x, center.y, center.z);
manipData = numDataObj;
return manipData;

}

 

}

 

I hope it helps and wish I would have known the above info before writing manipulators.

0 Likes

This is a fairly good article on how manipulators work. I've been doing some manipulators recently and it took a while to understand it.

 

https://around-the-corner.typepad.com/adn/2012/10/maya-custom-manipulators-.html

 

One of the key points is that when you connect the plug to the manipulator, it is a 1:1 relationship that exactly keeps the units the same.

e.g.

fnCurvePoint.connectToCurvePlug(curvePlug); //This sets up a 1:1 relationship

 

If you want to do something different than a 1:1 relationship, you have to not use the connectToPlug method, but actually use callbacks instead. Even if you want to do a conversion (radians to degrees) you have to use the callback method (which is super frustrating).

 

To do that you need to get the index of the specific manipulator pieces (e.g disc has 3 elements - its position, axis orientation and the angle itself). You need this index later to use in the callback.

 

 unsigned discAngleIndex = fnDisc.angleIndex();
unsigned discCenterIndex = fnDisc.centerIndex();
unsigned discAxisIndex = fnDisc.axisIndex();

 

To add the callback, its like this...

 

addPlugToManipConversionCallback(discCenterIndex, (plugToManipConversionCallback)&MyNodeManip::discCenterCallback);

 

For the callback code you need to check that the index matches up with the proper element, and then

 

MManipData MyNodeManip::discCenterCallback(unsigned manipIndex) {

 

if (manipIndex == discCenterIndex ) {

MManipData manipData;
MFnNumericData numData;
MObject numDataObj = numData.create(MFnNumericData::k3Double);
numData.setData(center.x, center.y, center.z);
manipData = numDataObj;
return manipData;

}

 

}

 

I hope it helps and wish I would have known the above info before writing manipulators.

Message 5 of 7
Anonymous
in reply to: muir.j

Anonymous
Not applicable

I'm glad to get a useful message. 

You shared your experience. I feel happy.

I'll study the link and your information.

Thanks for helping.

 

By the way, I've tried "MMessage.removeCallback( ) " and "MMessage.currentCallbackId()".

The fact is that manipToPlugCallback can't be operated by MMessage Class. They are different.

Currently, there is no way to query the callback ID of manipToPlugCallback. 

 

Have a good time

Tony

 

 

0 Likes

I'm glad to get a useful message. 

You shared your experience. I feel happy.

I'll study the link and your information.

Thanks for helping.

 

By the way, I've tried "MMessage.removeCallback( ) " and "MMessage.currentCallbackId()".

The fact is that manipToPlugCallback can't be operated by MMessage Class. They are different.

Currently, there is no way to query the callback ID of manipToPlugCallback. 

 

Have a good time

Tony

 

 

Message 6 of 7
muir.j
in reply to: Anonymous

muir.j
Contributor
Contributor

It's basically its own system.

 

The important thing is this.

unsigned discCenterIndex = fnDisc.centerIndex();

 

Lets say you get discCenterIndex  = 3 from the function.

manipIndex is effectively the callbackID

 

MManipData MyNodeManip::discCenterCallback(unsigned manipIndex)

if (manipIndex == discCenterIndex )

You need to check that manipIndex == 3 here, so you know what manipulator data item it is and can pass out the correct data to it.

 

}

 

 

 

0 Likes

It's basically its own system.

 

The important thing is this.

unsigned discCenterIndex = fnDisc.centerIndex();

 

Lets say you get discCenterIndex  = 3 from the function.

manipIndex is effectively the callbackID

 

MManipData MyNodeManip::discCenterCallback(unsigned manipIndex)

if (manipIndex == discCenterIndex )

You need to check that manipIndex == 3 here, so you know what manipulator data item it is and can pass out the correct data to it.

 

}

 

 

 

Message 7 of 7
Anonymous
in reply to: muir.j

Anonymous
Not applicable

First of all, thanks for your information.

 

I've tried to modify the manipToPlugIndex.

Yes, you're right. The conversion expressions can be decided whether return or not by:

if (manipIndex == discCenterIndex ) {

      (Conversion Expressions)

}

My critical part is that the connection from the manipulator to the plug can't be reset or disconnected.

In my MPxManipContainer::doRelease(), I used the code to reset the rotate manipulator.

rotateManipFn.setInitialRotation(MEulerRotation(0.0,0.0,0.0));

 

When doRelease() is executed, the rotate manipulator is initialized and the rotation of the 3D object (ex. a mesh cube) goes back to (0.0, 0.0, 0.0) simultaneously.

 

Anyway, I really appreciate who help me in recent days.

I really like to know what you're thinking about.

Thank you.

 

 

 

 

 

 

 

 

 

0 Likes

First of all, thanks for your information.

 

I've tried to modify the manipToPlugIndex.

Yes, you're right. The conversion expressions can be decided whether return or not by:

if (manipIndex == discCenterIndex ) {

      (Conversion Expressions)

}

My critical part is that the connection from the manipulator to the plug can't be reset or disconnected.

In my MPxManipContainer::doRelease(), I used the code to reset the rotate manipulator.

rotateManipFn.setInitialRotation(MEulerRotation(0.0,0.0,0.0));

 

When doRelease() is executed, the rotate manipulator is initialized and the rotation of the 3D object (ex. a mesh cube) goes back to (0.0, 0.0, 0.0) simultaneously.

 

Anyway, I really appreciate who help me in recent days.

I really like to know what you're thinking about.

Thank you.

 

 

 

 

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report