Home Coding, Scripting, Shaders

2D Texture Node Not Working #Mel

polycounter lvl 5
Offline / Send Message
Pinned
jayantbhatt007 polycounter lvl 5
Hi, I'm just trying to create a blinn material in which it has the attached 2D texture. I got some mel line but it seems like they are not connecting to the blinn material. Here is the command so far

string $myBlinn = `shadingNode -asShader blinn`;
hyperShade -assign $myBlinn;
string $selection[] = `ls -sl`; 
defaultNavigation -createNew -destination ($selection[0]+".color");
createNewOverride(($selection[0]+".color"), true);
createRenderNode -allWithTexturesUp  ($selection[0]+".color") "";
createRenderNodeCB -as2DTexture "" file ($selection[0]+".color");
shadingNode -asUtility place2dTexture;
 

Replies

  • throttlekitty
    Not sure what you're setting up with the navigation and override lines, here's a simpler go at it:

    string $myBlinn = `shadingNode -asShader blinn`;
    hyperShade -assign $myBlinn;
    string $myFile = `createRenderNodeCB -as2DTexture "" file ("")`;
    connectAttr ($myFile+".outColor") ($selection[0]+".color");
  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Hi thank you so much it's creating the material but not assigning to the selected object Why?
  • throttlekitty
    Right, because creating the blinn makes it the current selection. Try this:

    string $mySel[] = `ls -sl`;
    string $myBlinn = `shadingNode -asShader blinn`;
    hyperShade -assign $myBlinn $mySel;
    string $myFile = `createRenderNodeCB -as2DTexture "" file ("")`;
    connectAttr ($myFile+".outColor") ($myBlinn+".color");
  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Hi thank you so much this is what I wanted :)


    string $mySel[] = `ls -sl`;
    string $myBlinn = `shadingNode -asShader blinn`;
    string $myFile = `createRenderNodeCB -as2DTexture "" file ("")`;
    connectAttr ($myFile+".outColor") ($myBlinn+".color");
    select $myFile;
    AEfileTextureBrowser ("AEassignTextureCB " + $myFile + ".fileTextureName") $myFile image;
    select -r $mySel; 
    hyperShade -assign $myBlinn $mySel;

  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Right, because creating the blinn makes it the current selection. Try this:

    string $mySel[] = `ls -sl`;
    string $myBlinn = `shadingNode -asShader blinn`;
    hyperShade -assign $myBlinn $mySel;
    string $myFile = `createRenderNodeCB -as2DTexture "" file ("")`;
    connectAttr ($myFile+".outColor") ($myBlinn+".color");
    Hi small error came I restarted maya and run this new script it does something (Didn't assign the material to the selected object as I expected  ) But again when I run this command it worked perfectly why?


    string $mySel[] = `ls -sl`;
    string $myBlinn = `shadingNode -asShader blinn`;
    string $myFile = `createRenderNodeCB -as2DTexture "" file ("")`;
    setAttr ($myBlinn + ".specularRollOff")0.2;
    connectAttr ($myFile+".outColor") ($myBlinn+".color");
    select $myFile;
    AEfileTextureBrowser ("AEassignTextureCB " + $myFile + ".fileTextureName") $myFile image;
    select -r $mySel; 
    hyperShade -assign $myBlinn $mySel;



  • Panupat
    Offline / Send Message
    Panupat polycounter lvl 15
    The last line will not work. You need to do:

    select $mySel;
    hyperShade -assign $myBlinn;

  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Panupat said:
    The last line will not work. You need to do:

    select $mySel;
    hyperShade -assign $myBlinn;

    Still the same issue any idea?
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    you probably need to source "AEfileTemplate" as that may get sourced somewhere else which is why it works the second time around. (C:\Program Files\Autodesk\Maya\scripts\AETemplates\AEfileTemplate.mel). Probably better to use filedialog or filebrowserdialog to do the UI for selecting a texture rather than dealing with mel files hidden.
  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    you probably need to source "AEfileTemplate" as that may get sourced somewhere else which is why it works the second time around. (C:\Program Files\Autodesk\Maya\scripts\AETemplates\AEfileTemplate.mel). Probably better to use filedialog or filebrowserdialog to do the UI for selecting a texture rather than dealing with mel files hidden.
    hi seems a bit complex for me. Hi, I got this file dialog command but it's not showing images on my desktop why?


    string $singleFilter = "image";
    string $result[] = `fileDialog2 -fileFilter $singleFilter -dialogStyle 1`;
  • Panupat
    Offline / Send Message
    Panupat polycounter lvl 15
    what error message were you getting?
    Panupat said:
    The last line will not work. You need to do:

    select $mySel;
    hyperShade -assign $myBlinn;

    Still the same issue any idea?

    Any error message you can post here?
  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Panupat said:
    what error message were you getting?
    Panupat said:
    The last line will not work. You need to do:

    select $mySel;
    hyperShade -assign $myBlinn;

    Still the same issue any idea?

    Any error message you can post here?
    in another version of Maya I'm getting this error cannot find AEfileTemplate procedure. I think @haiddasalami is right I have load texture through file dialog which I don't know.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Just add source "AEfileTemplate" at the top of your script should work. Don't have Maya on me ATM so can't  say what's wrong with the filedialog
  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Just add source "AEfileTemplate" at the top of your script should work. Don't have Maya on me ATM so can't  say what's wrong with the filedialog
    Hi thank you so much today I know the meaning of source.
  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Just add source "AEfileTemplate" at the top of your script should work. Don't have Maya on me ATM so can't  say what's wrong with the filedialog 
    Do you have any idea regarding condition because when I run this command it's opening texture filedialog but when I cancel that  file dialog it's still assigning blinn material it shouldn't happen. Any idea?
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Just add source "AEfileTemplate" at the top of your script should work. Don't have Maya on me ATM so can't  say what's wrong with the filedialog 
    Do you have any idea regarding condition because when I run this command it's opening texture filedialog but when I cancel that  file dialog it's still assigning blinn material it shouldn't happen. Any idea?
    I wouldn't suggest using this code as you are constantly making new shading graphs. You should probably catch the exit way earlier by asking for the texture first and early out then if the user cancelled. At the moment if you cancel you leave the shading networks around. Anywho here is a way to do the conditional check. 

    source "AEfileTemplate";
    string $mySel[] = `ls -sl`;
    string $myBlinn = `shadingNode -asShader blinn`;
    string $myFile = `createRenderNodeCB -as2DTexture "" file ("")`;
    setAttr ($myBlinn + ".specularRollOff")0.2;
    connectAttr ($myFile+".outColor") ($myBlinn+".color");
    select $myFile;
    AEfileTextureBrowser ("AEassignTextureCB " + $myFile + ".fileTextureName") $myFile image;
    string $filePath = `getAttr ($myFile+".fileTextureName")`;
    if($filePath != "")
    {
    select $mySel;    
    hyperShade -assign $myBlinn;
    }

  • jayantbhatt007
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Just add source "AEfileTemplate" at the top of your script should work. Don't have Maya on me ATM so can't  say what's wrong with the filedialog 
    Do you have any idea regarding condition because when I run this command it's opening texture filedialog but when I cancel that  file dialog it's still assigning blinn material it shouldn't happen. Any idea?
    I wouldn't suggest using this code as you are constantly making new shading graphs. You should probably catch the exit way earlier by asking for the texture first and early out then if the user cancelled. At the moment if you cancel you leave the shading networks around. Anywho here is a way to do the conditional check. 

    source "AEfileTemplate";
    string $mySel[] = `ls -sl`;
    string $myBlinn = `shadingNode -asShader blinn`;
    string $myFile = `createRenderNodeCB -as2DTexture "" file ("")`;
    setAttr ($myBlinn + ".specularRollOff")0.2;
    connectAttr ($myFile+".outColor") ($myBlinn+".color");
    select $myFile;
    AEfileTextureBrowser ("AEassignTextureCB " + $myFile + ".fileTextureName") $myFile image;
    string $filePath = `getAttr ($myFile+".fileTextureName")`;
    if($filePath != "")
    {
    select $mySel;    
    hyperShade -assign $myBlinn;
    }

    Hi thank you so much sure next time i will keep these things my mind.
Sign In or Register to comment.