How to change the projection type for a created material.
-
For the object selected in the scene, a new material tag is added. By default, the projection type of the new material tag is set to spherical.
How to change the projection type of the new material tag?# Step 1: Create a new material material = c4d.BaseMaterial(c4d.Mmaterial) # Creating new material material.SetName("MyMat") # Assigning a name to a material material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
For a newbie in Python programming, it is very difficult to understand the large volume of documentation.
In other programming environments, for example for AfterEffects, there are functions that show the assigned effects, and field values, for a certain scene object.
Is there a trick that allows you to print the field properties of a certain tag of such an object? -
material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
This approach doesn't work.???
-
Hey @lednevandrey,
your code is 50% correct The assignment pair
TEXTURETAG_PROJECTION
andTEXTURETAG_PROJECTION_UVW
is correct and expresses setting the projection of a material tag to UVW. But they are associated with a Material Tag and not a material (as you attempt in your code). So, what you are trying there is systematically not possible, a material has no projection type. You need an object and its material tag. As a little warning, the type and symbol for a Material Tag are c4d.TextureTag andc4d.Ttexture
.I am not so sure what you mean with '' but you might want to read Python SDK - Python Console: Drag and Drop. Something like
TEXTURETAG_PROJECTION
is called a parameter in Cinema 4D and you can explore them via drag and drop in the Python console.Cheers,
Ferdinand -
Hey Ferdinand!
To the request
Material
Shows this message
<c4d.TextureTag object called Material/Material with ID 5616 at 2260375040320>But when I try to change the value of TEXTURETAG_PROJECTION with the line
Material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
As I understand, I refer to the TEXTURE tag....
then I get the message
NameError: name 'Material' is not defined. Did you mean: 'material'?And in the description of the parameters c4d.TextureTag, there is no value TEXTURETAG_PROJECTION.
How to correctly refer to the material tag?
-
Hey @lednevandrey,
without wanting to be rude, I really struggle with understanding what you want to convey.
Material[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
does not work because Python is case sensitive and you gave yourBaseMaterial
instance the symbolmaterial
. So, Python is complaining about that.But as said before, a material, i.e.,
BaseMaterial
is not the right place to set the projection. It is the counter part to the thing you see in the Material Manager of Cinema 4D and has no projection. The projection is set in the Material Tag, which slightly confusingly is calledTextureTag
in the API.Cheers,
Ferdinand"""Assigns the first material in the document to the selected object and sets its projection to UVW. """ import c4d import mxutils doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def main() -> None: """Called by Cinema 4D when the script is being executed. """ if not op: raise ValueError("Please select an object.") # Get the first material in the document. material: c4d.BaseMaterial = doc.GetFirstMaterial() if not material: raise ValueError("No materials found in the document.") # Get the first existing texture tag on #op or create a new one when none exists. tag: c4d.BaseTag = op.GetTag(c4d.Ttexture) or op.MakeTag(c4d.Ttexture) if not tag: raise ValueError("Failed to get or create a texture tag.") # Set the material and projection. tag[c4d.TEXTURETAG_MATERIAL] = material tag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW # Update the Cinema 4D UI. c4d.EventAdd() if __name__ == '__main__': main()
-