Home Technical Talk

Repeat command at mouse position

CreativeSheep
polycounter lvl 8
Offline / Send Message
CreativeSheep polycounter lvl 8
Is there a way to show selected points in world position in Maya ?

I'm trying to understand repeat command at mouse position, if you move a point on a mesh what is it related to; world or local position because, if you repeat the same command on another point on the mesh the results are not the same as was the first point ?

Replies

  • Fansub
    Options
    Offline / Send Message
    Fansub sublime tool
    Use the draggerContext command along with the -anchorPoint flag to get the current mouse position.You can change the space coordinate type by using the -space flag (world,object and screen space are available iirc).

    edit : not sure if that answered your question tho :/
  • CreativeSheep
    Options
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    I don't think this code is right to find the current mouse position ?

    var pp[] = `draggerContext -anchorPoint -dragPoint`;

  • Fansub
    Options
    Offline / Send Message
    Fansub sublime tool
    You're using the -anchorPoint to get the mouse position,but like the documentation says :

    Anchor point (double array) where dragger was initially pressed.
    Which means it will only give you the mouse position when you click somewhere in the viewport.First you need to declare the -pressCommand flag and give it a procedure or any other command to execute.The procedure we are talking about here is the queried result of the -anchorPoint flag.

    Basically,everytime you click somewhere in the viewport the -pressCommand will get the -anchorPoint which will retrieve the mouse position.

    This is what it looks like in MEL :

    proc MousePos() {
               
    float $MP[] = `draggerContext -query -anchorPoint MPosition`;
    print(" Mouse position : " + $MP[0] + " " + $MP[1] + " " + $MP[2]  + "\n");

    }

    draggerContext -pressCommand "MousePos" -cursor "crossHair" -ch 0 MPosition;

    setToolTo MPosition;
    Pretty sure you can shorten the script,but having the -pressCommand in a procedure can help for future use.
  • CreativeSheep
    Options
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    Ahh, function I see you set the empty array as a float variable, from what I know of MEL you don't have too ? 

    The script worked, although after I run it a few times it fires an error on line 8 ?

    Where did you get MPosition ?

     


  • Fansub
    Options
    Offline / Send Message
    Fansub sublime tool
    Where did you get MPosition ?

    MPosition is the name of your context tool here.


    The script worked, although after I run it a few times it fires an error on line 8 ?


    That's because you're trying to create a context tool twice,which is technically impossible since two tools can't have the same name AFAIK.

    The line "setToolTo MPosition" is all you need to start the tool if you have already run it at least one time in a Maya session.To make the tool persistent forever,you need to add an if statement that run the whole script I've provided if the "MPosition" context tool doesn't exist,and if it exists only the "setToolTo MPosition" line will be executed.

    The final result should look like this :


    if (`draggerContext -exists "MPosition"`) {
        setToolTo MPosition;
    }

    else {
        proc MousePos() {             
        float $MP[] = `draggerContext -query -anchorPoint MPosition`;
        print(" Mouse position : " + $MP[0] + " " + $MP[1] + " " + $MP[2]  + "\n");
        }
        draggerContext -pressCommand "MousePos" -cursor "crossHair" -ch 0 MPosition;
        setToolTo MPosition;
    }

    If you see an "-exists" flag in a Maya command always assume that it might be there to let the user change his script's behavior depending on it's value.

    Ahh, function I see you set the empty array as a float variable, from what I know of MEL you don't have too ?

    That's just a personal preference here.When working on big projects you tend to manage hundreds of lines and i really like making everything clear and using "float $Something" instead of "$Something" is also more readable imho.I've also never encountered a bug using this technique,so this might explain that :p
  • CreativeSheep
    Options
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    If one position of a point is here; Mouse position : 947 540 0.  Then it must be possible to take that point and select, like symmetrical do the same thing on another point except opposite world coordinates by storing it into a empty array, selecting another point and applying the same world coordinates to the other point except the world coordinates would be opposite of the object.  

    Store the point mouse position, select another point then repeat command.  I'm not sure what repeat command does at present but when you select a point, followed by moving it, select another point and apply the repeat command it is erratic, where the other point is moved.
  • Saf
    Options
    Offline / Send Message
    Saf polycounter lvl 11
    Interesting question. How to get component name under the cursor using MEL? Not selecting and clicking on it?
  • claydough
    Options
    Offline / Send Message
    claydough polycounter lvl 10
    Saf said:
    Interesting question. How to get component name under the cursor using MEL? Not selecting and clicking on it?

    dagObjectHit

    http://tech-artists.org/forum/showthread.php?419-popUpMenu-mel-notes-quot-dagObjectHit-quot

    example showing right click viewport feedback but the same could be done with modifiers only.

    (without clicking on the highlighted component)


  • CreativeSheep
    Options
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    It helps but it still doesn't answer my question ? :)
Sign In or Register to comment.