Maxwell Render

Maxwell Render Information Repository
It is currently Mon May 20, 2013 10:02 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Apr 02, 2012 6:19 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hi !

I checked the docs, maybe I missed a spot ..

is it possible to create mxm materials with python in Cinema4d ? I'd like to create a reference material and then point to a specific mxm on the harddrive (linking it).

any input welcome !



thanks in advance !

m.

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 7:49 pm 
User avatar

Joined: Wed Nov 16, 2005 3:02 am
Posts: 7565
Location: desk #861
You can do it this way:

Code:
import c4d

ID_MXMATERIAL = 1021237;
ID_MXMFILENAME = 1002;

def main():
    material = c4d.BaseMaterial(ID_MXMATERIAL);
    material[ID_MXMFILENAME] = "C:\\carpaint_cherry.mxm";
    doc.InsertMaterial(material);
    doc.SetActiveMaterial(material);
    c4d.EventAdd();

if __name__=='__main__':
    main()


There is a slight problem with this, though, since it sets the path through the material's description; what will happen is that the plugin will pop up a dialog asking you if you really want to overwrite the material with the specified MXM. This is because switching from embedded mode to linked mode is a destructive action, even if the material in question was just created a half-second ago. To get around that, you can pre-set the MXM path to a different, valid path first, directly through the material's BaseContainer, then set the path you actually want, like this:

Code:
import c4d

ID_MXMATERIAL = 1021237;
ID_MXMFILENAME = 1002;

def main():
    material = c4d.BaseMaterial(ID_MXMATERIAL);
    data = material.GetDataInstance();
    data.SetFilename(ID_MXMFILENAME, "C:\\dummy.mxm");
    material[ID_MXMFILENAME] = "C:\\carpaint_cherry.mxm";
    doc.InsertMaterial(material);
    doc.SetActiveMaterial(material);
    c4d.EventAdd();

if __name__=='__main__':
    main()


In this case, the plugin will not warn you about damaging an existing embedded material, since the material already links to a different MXM file.

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Tue Apr 03, 2012 12:06 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hey !

thanks a lot so far. importing mxms works so far !

as you may imagine, I am doing this for multiple objects, where each object's name is the same as the referenced material (+ ".mxm"). so to actually assign the material to the mesh, does it have to be selected ? or how would I exchange the material tag to the newly imported material ?

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Tue Apr 03, 2012 2:22 pm 
User avatar

Joined: Wed Nov 16, 2005 3:02 am
Posts: 7565
Location: desk #861
If you have a TextureTag, you can set its material using TextureTag::SetMaterial. If your object has no TextureTag, you can create one using BaseObject::MakeTag(Ttexture), then call SetMaterial on the created tag:

Code:
import c4d

ID_MXMATERIAL = 1021237;
ID_MXMFILENAME = 1002;

def main():
    material = c4d.BaseMaterial(ID_MXMATERIAL);
    data = material.GetDataInstance();
    data.SetFilename(ID_MXMFILENAME, "C:\\dummy.mxm");
    material[ID_MXMFILENAME] = "C:\\carpaint_cherry.mxm";
    doc.InsertMaterial(material);
    doc.SetActiveMaterial(material);
    obj = doc.GetFirstObject();
    if not obj is None:
        tag = obj.GetTag(c4d.Ttexture);
        if tag is None:
            tag = obj.MakeTag(c4d.Ttexture);
        tag.SetMaterial(material);
    c4d.EventAdd();

if __name__=='__main__':
    main()

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Tue Apr 03, 2012 3:30 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
YESS !

got it working !

amazing help, thanks a TON !


the code is quite messy due to my naming convention, but it's working and that's what counts !

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group