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

Art shader, or load from content browser ?

Author
Message
  Topic Search Topic Search
Myosis View Drop Down
Member
Member


Joined: 2018 Aug 30
Online Status: Offline
Posts: 4
Direct Link To This Post Topic: Art shader, or load from content browser ?
    Posted: 2018 Aug 30 at 2:01am
Hi,

First off I’m new here, and also very new with python.
I'm trying to create a pretty basic material using python, but it seems not so easy.

I have two questions:
How can I add the Art shader to a channel?

It's not listed in the SDK shader list.
So it's probably not like I'm just missing the right word here, is it ?

matt[c4d.MATERIAL_USE_LUMINANCE] = True
Art = c4d.BaseList2D(c4d.X...something.....)
matt.InsertShader( Art )
matt[c4d.MATERIAL_LUMINANCE_SHADER] = Art

I also want it to load a image in the art shader, so I figured, why don't I just create a preset folder in the content browser and load the material form that folder. 
Turns out it's quite tricky to import materials from the content browser too.

fn = "preset://somefolder/Cube.2.c4d"
c4d.documents.LoadFile(fn)

If I use anything else then LoadFile, it will tell me to use a base document in the console.

From my understanding, I have to make a virtual base document and then import it from that.
How does that look like in code ? 

I only need one to work, but I am very interested in both!

Cheers,
Tim



Edited by Myosis - 2018 Sep 01 at 10:26am
Back to Top
Myosis View Drop Down
Member
Member


Joined: 2018 Aug 30
Online Status: Offline
Posts: 4
Direct Link To This Post Posted: 2018 Aug 30 at 11:11pm
I figured out how to load the material form the content browser:
doc = c4d.documents.GetActiveDocument()
location = "preset://somefolder.lib4d/mymat"
c4d.documents.MergeDocument(doc, location, c4d.SCENEFILTER_MATERIALS)
But I prefer creating the material in python rather then loading it, if anyone knows how to access and apply the Art shader, let me know ;)

- Tim


Edited by Myosis - 2018 Sep 01 at 10:27am
Back to Top
MaximeA View Drop Down
Forum Moderator
Forum Moderator

Forum Moderator

Joined: 2018 Jan 04
Location: France - Nantes
Online Status: Offline
Posts: 119
Direct Link To This Post Posted: 2018 Aug 31 at 4:07am
Hi Myosis, first of all, welcome in the plugincafe community!

Even if shader didn't get a proper symbols name, each BaseList2D get an ID. And symbols only refer to this ID.
So if you want to know the current ID of an Art shader. Simply create a shader in a material, then drag and drop the channel where the shader is into the console. Press enter and it will print you the ID.
For the art shader, it's 1012161.

About bitmap do the same technique, simply drag and drop the parameter into the console to know the parameter ID.

Then you can create it using the following script
import c4d

def main():
    mat = doc.GetActiveMaterial()
    if not mat:
        return
    
    # Create the bitmap shader
    bmpShader = c4d.BaseShader(c4d.Xbitmap)
    bmpShader[c4d.BITMAPSHADER_FILENAME] = "YourTexturePath"
    
    # Create a art Shader and insert our bmp shader
    artShader = c4d.BaseShader(1012161)
    artShader.InsertShader(bmpShader)
    artShader[c4d.ARTSHADER_TEXTURE] = bmpShader
    
    # Then insert our art Shader into the active material, and use it in the color channel
    mat.InsertShader(artShader)
    mat[c4d.MATERIAL_COLOR_SHADER] = artShader
    
    c4d.EventAdd()

if __name__=='__main__':
    main()
As you already figured out, in python the only way to load stuff from content browser is to use LoadFile/MergeDocument.

If you have any question, please let me know!
Cheers,
Maxime!
MAXON
SDK Specialist
Back to Top
Myosis View Drop Down
Member
Member


Joined: 2018 Aug 30
Online Status: Offline
Posts: 4
Direct Link To This Post Posted: 2018 Sep 01 at 10:19am
Hi Maxime,

Thanks, and tanks again!

I forgot about the "drag and drop codes", this will solve multiple problems for me!

I do have a another question, I struggle with file paths.
I don't fully understand how it works, so far I have this:

    path, fn = os.path.split(__file__) #Split Startup filename in path and name
    texturepath = path, "res/textures/" "texture.tif" #Set texture path
    print texturepath

    shader[c4d.BITMAPSHADER_FILENAME] = (str(texturepath))
    mat[c4d.MATERIAL_LUMINANCE_SHADER] = shader

In console:
('C:\\Program Files\\MAXON\\Cinema 4D R19\\plugins\\Tryout, 'res/textures/texture.tif')

In actual texture:
./('C://Program Files//MAXON//Cinema 4D R19//plugins//Tryout, 'res/textures/texture.tif')

I am trying to load form a folder within the plugin directory (this is where the script is saved).
There is a bunch of stuff wrong with the way it writes the path.
The split doesn't work without ,
And where do those () come from? 
And especially the ./ in the beginning when looking in the texture ?

Regardless, thanks for the help ;)

Best,
Tim



Edited by Myosis - 2018 Sep 01 at 11:51am
Back to Top
Myosis View Drop Down
Member
Member


Joined: 2018 Aug 30
Online Status: Offline
Posts: 4
Direct Link To This Post Posted: 2018 Sep 01 at 12:13pm
Ah like so:

bmp = c4d.bitmaps.BaseBitmap()
dir, file = os.path.split(__file__)
fn = os.path.join(dir, "res", "Icon.tif")
bmp.InitWith(fn)

I learned nothing because i found the part above online.

Works great though!
I'm linking it to the shader with this: 

shader = c4d.BaseList2D(c4d.Xbitmap)
shader[c4d.BITMAPSHADER_FILENAME] = (fn)
mat[c4d.MATERIAL_LUMINANCE_SHADER] = shader
mat.InsertShader(shader)


Back to Top

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.094 seconds.