Material directly into Material Manager

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 12/01/2009 at 10:02, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   11 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Okay, really excited about my getting of my duff and exploring the possibility of developing my own plugin.

Would like to know how (code, function, etc.) i need to use to get material to show up in the material manager directly from plugin response.

Thanks!

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 12/01/2009 at 10:52, xxxxxxxx wrote:

Not sure that I understand the question completely. You create a material using:

Material* mat = Material::Alloc();
if (!mat) // return some error
doc- >InsertMaterial(mat, NULL, FALSE);
mat->Message(MSG_UPDATE);
EventAdd();

To 'attach' the material to a particular scene object, you must have a Texture tag and association:

TextureTag* ttag = TextureTag::Alloc();
if (!ttag) // return some error
op- >InsertTag(ttag);
// Set projection to relevant projection
ttag->SetParameter(DescID(TEXTURETAG_PROJECTION),          GeData(TEXTURETAG_PROJECTION_UVW), DESCFLAGS_DONTCHECKMINMAX);
// Make Material<->TextureTag association
ttag->SetMaterial(mat);
ttag->Message(MSG_UPDATE);
EventAdd();

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 12/01/2009 at 10:55, xxxxxxxx wrote:

robert,

you answered my question. thanks.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/01/2009 at 11:43, xxxxxxxx wrote:

Need some help...tried the code and did below:

BaseDocument     *doc = GetActiveDocument(); //if(!doc) return FALSE;

BaseMaterial* mat = BaseMaterial::Alloc(Mbase);
if (!mat) // return some error
doc->InsertMaterial(mat, NULL, FALSE);
mat->Message(MSG_UPDATE);
EventAdd();

Unfortunately, don't think that this is correct. When this part of the code is executed in my plugin, the application simply closes. No material, nothing.

I suspect that I am not declaring mat and doc, etc. as I am supposed to. Help.

Thanks.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/01/2009 at 12:09, xxxxxxxx wrote:

You have to allocate a Material (as my code above shows). The BaseMaterial is just the base class for the instantiation you see in the document. That is, it doesn't represent a complete material that C4D can use in the document. InsertMaterial() uses an argument of BaseMaterial to allow it to support various types of material (Material, PluginMaterial for the moment).

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/01/2009 at 03:12, xxxxxxxx wrote:

if (!mat) // return some error

-> you really have to complete this line otherwise doc->InsertMaterial(...) will only be executed if mat == NULL!

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/01/2009 at 07:46, xxxxxxxx wrote:

Good point. Yes, I was just making comment as the error response depends upon what the coder is doing. This must actually be 'return FALSE;' or something similar otherwise it reads like this, which isn't good:

if (!mat) doc->InsertMaterial(mat, NULL, FALSE);

You can go the positive route:

if (mat)
{
doc->InsertMaterial(mat, NULL, FALSE);
mat->Message(MSG_UPDATE);
EventAdd();
}

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/01/2009 at 14:02, xxxxxxxx wrote:

holy crud! beautiful and i did not even begin to consider that if (!mat) // return some error was the culprit!

thank you!