Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Shaderlink / Texbox in GeDialog ?

 Post Reply Post Reply
Author
Message
zeorge View Drop Down
Member
Member


Joined: 2006 Nov 20
Location: Australia
Online Status: Offline
Posts: 39
Post Options Post Options   Quote zeorge Quote  Post ReplyReply Direct Link To This Post Topic: Shaderlink / Texbox in GeDialog ?
    Posted: 2017 Feb 12 at 6:02am
hi there,

i am failing to get a working shaderlink / texbox in my GeDialog!

working with resource files allowed me to add a texbox with:
SHADER MY_SHADER { FIT_H; SCALE_H; }

but sadly the gui then doesn't react to any interaction


i tried the following in GeDialogs CreateLayout(self):

self.MyShader = self.FindCustomGui(MY_SHADER,c4d.CUSTOMGUI_TEXBOX)
--> just returns True, so probably doesn't work

self.MyShader = self.FindCustomGui(MY_SHADER,c4d.CUSTOMGUI_LINKBOX)
--> returns a CustomGui but then:

color = c4d.BaseShader(c4d.Xcolor)
self.SetLink(MyShader, color)
--> crashes c4d



so the question is: is it possible to have a working texbox in a GeDialog?
and if yes, how would one get there?

best, theo
                  

Edited by zeorge - 2017 Feb 13 at 2:07am
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 930
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 13 at 2:03am
Hi,

I'm afraid I haven't good news. It's not possible to use a SHADER gadget inside a dialog with the Python API.

TexBoxGui that provides access to SHADER resource is missing in the Python API.
This explains why self.FindCustomGui() returns True because the actual TexBoxGui object can't be returned.

Calling self.FindCustomGui() with CUSTOMGUI_LINKBOX (good try but not recommended at all Smile) returns a "false" LinkBoxGui and crashes as the actual dialog gadget isn't a LinkBox.






Edited by Yannick Puech - 2017 Feb 13 at 2:05am
MAXON
Developer Support
Back to Top
zeorge View Drop Down
Member
Member


Joined: 2006 Nov 20
Location: Australia
Online Status: Offline
Posts: 39
Post Options Post Options   Quote zeorge Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 13 at 2:10am
hi and thanks for your answer...

there is a post about it here, too... but it is from 2010
http://www.plugincafe.com/forum/forum_posts.asp?TID=3957&KW=CUSTOMGUI%5FTEXBOX

but can i ask to understand...
would it work to add a texbox/shader in a GeDialog in c++?
so it is just a problem of the python SDK?

and if fundamentally not possible in GeDialog with python... are there other ways?
can you construct the missing parts yourself?
It must be possible somehow to open a window, display a texbox, and get some input, not?

my goal is simply to have my own window where i can choose a texture or shader
and then set/insert it in a material shader slot.


Edited by zeorge - 2017 Feb 13 at 8:04am
Back to Top
zeorge View Drop Down
Member
Member


Joined: 2006 Nov 20
Location: Australia
Online Status: Offline
Posts: 39
Post Options Post Options   Quote zeorge Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 16 at 7:59am
nothing?

python + texbox = absolutely impossible?

shouldnt that be set on the todo list for the sdk? .)
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2246
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 16 at 10:00am
What you want to do does not require having a shader link in the dialog.
All you need is a way to target the specific image or shader type. And then a way to target the specific material you want to add it to.
Also maybe even what channels(color, bump, etc...) do want to add the image to?

For example. One way of doing this is to:
-Use a textbox for the user to enter the target material's name
-Use a Filename gadget to get the image's path on your HD that you want to add to the material.
In your code. You then get the string value from the Filename gadget. And the string value from the textbox. Then use that to insert the image into the target material like this:

   mat = doc.GetFirstMaterial()
    if mat is None: return False

    file = the string value of your Filename gadget
    if len(file) == 0: return False

    #Get the specific material based on what the user entered in the textbox
    #Then add the image file to the color channel's shader link
    while mat:
        if mat.GetName() == your textbox value:
            colorChanel = mat[c4d.MATERIAL_COLOR_SHADER]
            shdr = c4d.BaseList2D(c4d.Xbitmap)
            shdr[c4d.BITMAPSHADER_FILENAME] = file
            mat.InsertShader( shdr )
            mat[c4d.MATERIAL_COLOR_SHADER]  = sha

        mat = mat.GetNext()


Or.
What about maybe using a combobox gadget to get all of the existing materials rather than a textbox?
Then the user just selects the one they want to add the image to, rather than typing the name.
There's so many ways to do this kind of thing. There's no way to really answer your question.
Don't let the fact that we can't physically have a material link in the dialog get in your way.
Try to think about how you can work around it.

-ScottA
Back to Top
zeorge View Drop Down
Member
Member


Joined: 2006 Nov 20
Location: Australia
Online Status: Offline
Posts: 39
Post Options Post Options   Quote zeorge Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 16 at 11:11am
no no...

i wanted to code a helper plugin to setup materials
for that i must be able to select textures and all shaders, noise, layer, etc etc

so i would need a texbox :(



Edited by zeorge - 2017 Feb 16 at 11:15am
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2246
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 16 at 12:05pm
My point is that there are many ways to do what you want without using the shaderlink custom gui.
For example. You can iterate through a material/materials and get&set the shader links manually.
import c4d

shdrlist = []

def ShaderSearch(shader):
    next = shader.GetNext()
    down = shader.GetDown()
    if down: ShaderSearch(down)
    if next: ShaderSearch(next)
   
    shdrlist.append(shader.GetName())  

def main():
   
    mat = doc.GetActiveMaterial()
    if mat is None: return
   
    shdr = mat.GetFirstShader()
    if shdr is None: return
   
    ShaderSearch(shdr)
    print shdrlist
   
    c4d.EventAdd()
   
if __name__=='__main__':
    main()


Where you get the images or shaders that you want to add. And how you want the user to do that task is relative. All depending on your specific desired workflow.
The shaderlink custom gui might be the most obvious thing to use. But it's not your only option.

For visualizations. I've written dialog plugins that show the active material using a bitmap button to display it. That can be updated by clicking on them. A UserArea could also be used for this. This gets around the limitation of not being able to use a material gadget in a GeDialog.
The sdk as so many options in it that you should be able to do almost anything you want to do. But you might have to do them by hand, instead of using a pre made gadget.

-ScottA
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 930
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 17 at 1:26am
Yes, the TextBox GUI works with the C++ API.

And I've already added TexBoxGui to the Python API todo list Smile



MAXON
Developer Support
Back to Top
zeorge View Drop Down
Member
Member


Joined: 2006 Nov 20
Location: Australia
Online Status: Offline
Posts: 39
Post Options Post Options   Quote zeorge Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 17 at 3:05am
@ ScottA:
i would need to be able to choose from all available shaders in c4d, not from the shaders of a selected material.
the goal is to have the same choice for a shader like when you would be in the material editor itself.

@ Yannick:
good news :) !
but that probably wont go that fast, will it? .)


Edited by zeorge - 2017 Feb 17 at 3:05am
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 930
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Feb 17 at 5:17am
Originally posted by zeorge


good news :) !
but that probably wont go that fast, will it? .)
Missing classes and functions are regularly added to the Python API.


MAXON
Developer Support
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.063 seconds.