Graphics

 View Only
  • 1.  Xpression: Modifying a material shader by VBscript

    Posted 11-21-2019 22:33

    I need some help with scripting. I've written the script below with examples from the forum, but I'm uncertain about the order of things.

    Document1 is an image added from ENPS Xpression plugin

    Doc1PathReport is just to get the file path of image in Document1

    ...and that part works, thanks to @bford

    Then, I need a shaded version of Document1...I made a material (Document1Gradient) with the image (shader: Document1Image) and a gradient to accomplish that and applied it to a quad...Document1Shaded. 

    In visual logic, I link Doc1PathReport.text to Doc1Path.text.

    My script will compile, but doesn't replace the image in the shader.

    Can anybody see what I'm doing wrong? Is what I want even possible?

    Thanks in advance,

    James.

     

    Dim Document1 as xpBaseObject
    Dim Mat as xpMaterial
    Dim Shader as xpBaseShader
    Dim Doc1PathReport as xpTextObject

    Self.GetObjectByName("Document1", Document1)
    Self.GetObjectByName("Doc1PathReport", Doc1PathReport)

    If Document1.GetMaterial(0,Mat) then
    If Mat.GetShader(0,Shader) then
    Doc1PathReport.text=shader.FileName

    end if
    end if

    Dim Document1Shaded as xpBaseObject
    Dim Document1Gradient as xpMaterial
    Dim Document1Image as xpBaseShader
    Dim Doc1Path as xpTextObject

    Self.GetObjectByName("Document1Shaded", Document1Shaded)
    Self.GetMaterialByName("Document1Gradient", Document1Gradient)
    Self.GetShaderByName("Document1Image", Document1Image)
    Self.GetObjectByName("Doc1Path", Doc1Path)

    If Document1Shaded.GetMaterial(0,Document1Gradient) then
    If Document1Gradient.GetShader(0,Document1Image) then
    Shader.SetFileName("Doc1Path.Text")

    end if
    end if



  • 2.  RE: Xpression: Modifying a material shader by VBscript

    Posted 11-25-2019 16:09

    There could be more things, but at least one error I spot is the line:

    self.GetMaterialByName and self.GetShaderByName.

     

    Depending on which script event you are using (OnOnline or OnSetText) self could refer to either the scene or a text object.  (Looks like you are maybe using ononline though, so self is the scene).

    A scene does not have materials or shaders.  You probably want self.project.getmaterialbyname, and Document1Gradient.GetShaderByName.

    You also retrieve Document1Image as a xpBaseshader, but then you never do anythign with it; you later call Shader.SetFileName but maybe you meant Document1Image.SetFileName.  

     


    #XPression


  • 3.  RE: Xpression: Modifying a material shader by VBscript

    Posted 11-26-2019 02:24

    Brian!

    Thanks for looking over my script. It will be a little bit before I can work on it. I'll let you know how it works.

    Thanks again,

    James.


    #XPression