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: 

MEL script newbie question

2 REPLIES 2
Reply
Message 1 of 3
b00194616
366 Views, 2 Replies

MEL script newbie question

Can anyone help please?  I'm trying to write a simple MEL script that will ask the user for a number, then create that number of polycubes.  I can manage to do that and I've got validation so that the user can only input a number between 4 - 32.

However, when it comes to creating the cubes is where I am having difficulty in getting my head around the logic.

What I want to do is start with a specified polygon size (2.5,1,5) then have each successive polygon scale up in one dimension.  In addition to that I want to displace the cubes progressively so that in the end I have what looks like a staricase of cubes.

 

But... what happens is that although the right number of cubes is created, only one of them is moved to the position I want (so far I haven't tried the scaling).  I suspect I need to create a new variable to do it, but I am stumped as to how.

 

Any help will be very gratefully received

Thanks

Rosanne

This is my code so far

 

global int $No_of_Cubes;

global proc makeCube(int $No_of_Cubes) {
    
    //Sets the $count variable as an integer
    global int $No_of_Cubes;
    int $count;
    for ($count = 0;  $count < $No_of_Cubes; $count ++)
    polyCube -w 2.50 -h 1 -d 5 ;
    move -y .5;
    //Trying to create shader - doesn't work
    //createAndAssignShader lambert "";
    //connectAttr -f lambert2.outColor lambert2SG.surfaceShader;
    //sets -e -forceElement lambert2SG;

    //displace cubes
    move ($count * .5) ($count *.25) 0;
}


//global proc buttonAction(){
    //else makeCube($No_of_Cubes);
    //buttonAction();
//}


global proc makeCubeUI(){
        global int $No_of_Cubes;
        
        string $getNoCubes = `promptDialog -title "Mystery!"
     -message "Please enter a number between 4 and 32"
          -b "Click to see what happens next"`;
        
    string $getCubeString = `promptDialog -q`;
        int $No_of_Cubes = $getCubeString;

//validates $No_of_Cubes is > 4 or >32
//if yes, error message and reset
 //   int $No_of_Cubes;
    global int $No_of_Cubes;
    if (($No_of_Cubes <4)||($No_of_Cubes >32)){
            confirmDialog -t "Oops!"
        -m "Number must be between 4 - 32"
        -button "ok";
    makeCubeUI();
    }

    makeCube($No_of_Cubes);
}
makeCubeUI();

2 REPLIES 2
Message 2 of 3
TechToast
in reply to: b00194616

Hi

 

It looks like you were quite close. Your problem was that you didn't put braces (the curly ones {}) after your for loop and so it was only looping over the first command (the polyCube command in this case). So to fix it I just added the braces. Your makeCube function now looks like this:

 


global proc makeCube(int $No_of_Cubes) {
    
    //Sets the $count variable as an integer
    global int $No_of_Cubes;
    int $count;
    for ($count = 0;  $count < $No_of_Cubes; $count ++)
    {
        polyCube -w 2.50 -h 1 -d 5 ;
        move -y .5;
        //Trying to create shader - doesn't work
        //createAndAssignShader lambert "";
        //connectAttr -f lambert2.outColor lambert2SG.surfaceShader;
        //sets -e -forceElement lambert2SG;
    
        //displace cubes
        move ($count * .5) ($count *.25) 0;
    }
}

 

Hope this helps

 

Mike

Message 3 of 3
b00194616
in reply to: TechToast

Many thanks Mike - that fixed it beautifully

kind regards

Ros

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

Post to forums  

Autodesk Design & Make Report