Create material from template (Set as default)
-
On 08/01/2013 at 14:00, xxxxxxxx wrote:
I am creating a new material with this scipt:
lMat = c4d.BaseMaterial(5703) doc.InsertMaterial(lMat) c4d.EventAdd()
However, this creates a default material. Is there any way to create a user-defined material? You know, the user can customize his material and then save it as default by selecting 'Set as default' in the attribute manager. For example any time I create a new material, the specular channel is deactivated and a fresnel shader is loaded into the reflection channel. This is my template for a default material.
-
On 09/01/2013 at 01:27, xxxxxxxx wrote:
Originally posted by xxxxxxxx
However, this creates a default material. Is there any way to create a user-defined material? You know, the user can customize his material and then save it as default by selecting 'Set as default' in the attribute manager. For example any time I create a new material, the specular channel is deactivated and a fresnel shader is loaded into the reflection channel. This is my template for a default material.
You can call the command that creates a new material with the ID 13015 (IDM_MENU, defined in resource\c4d_symbols.h ) :
c4d.CallCommand(13015)
This is also outputted to the Script Log when the "New Material" menu in the Material Manager is clicked.
-
On 11/01/2013 at 06:58, xxxxxxxx wrote:
Thank you for you reply. This works for a standard material, but not for Vray Materials. The script log says for a new VrayAdvancedMaterial the following: CallCommand(58000); // 3D Shader
However, it says the same for all Vray Materials: Advanced, Blend, Override, 2Sided, etc. Calling this command again from the script manager does not seam to do anything. -
On 11/01/2013 at 09:09, xxxxxxxx wrote:
You need to allocate the material with BaseMaterial::Alloc, using the ID for the material you want. So for a Vray Advanced Material you would do:
BaseMaterial *mat = BaseMaterial::Alloc(ID_VRAYBRDF_MATERIAL);
That's in C++, just translate into Python for your script. You can find the IDs you need in the vraybridge/res/description folder, in files such as mVrayAdvancedMaterial.h, mVray2SidedMaterial.h, etc.
-
On 11/01/2013 at 12:49, xxxxxxxx wrote:
Isn't this the same as what I posted in my first post? And would this really create a user-defined material (one that the user set as default earlier)?
-
On 11/01/2013 at 13:25, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Isn't this the same as what I posted in my first post? And would this really create auser-defined material (one that the user set as default earlier)?
It depends on what the actual integer representation of the plugin ID for a vray advanced
material is. I do not not have vray, so i cannot test it, but i highly doubt it is 5703, because
third party plugin ids are usually longer. 5703 sounds more something that c4d uses for its
native 'types' . if i am wrong about the number, the code steve has posted is the same as
the code you have posted on your first posting. i think he just wanted to stress that it is
more convenient to use the string form of an ID than the actual number.myVrayMaterial = c4d.BaseMaterial(c4d.ID_VRAYBRDF_MATERIAL)
that is the way in c4d to instantiate a subtype of an base class - you pass the plugin ID of
the subtype to the constructor of the base class. this also includes any type of plugin class
which has been derived from this base class.i am not sure hat you mean with user defined. your code does the same , as if you would
createa material from scratch in the material editor. your code has nothing to do with loading
a material preset. if you want to do something like that you should check c4d.documents. -
On 12/01/2013 at 02:01, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Isn't this the same as what I posted in my first post?
No, of course not. It uses the plugin ID for that specific kind of material. You would do the same - with a different ID - for other materials, such as simbiont shaders, the old SLA shaders, etc. It's all in the ID. Look up BaseMaterial::Alloc in the SDK, and then at the 'type' parameter.
I don't know what you mean by a 'user-defined' material either. If you mean a shader that someone else has coded, then you use this technique with the appropriate ID.
(Edit: looking back at your original post, if the user changes the default settings for a particular material, then creating a new material of that type will load it with the new settings.)
-
On 12/01/2013 at 02:54, xxxxxxxx wrote:
Originally posted by xxxxxxxx
(Edit: looking back at your original post, if the user changes the default settings for a particular material, then creating a new material of that type will load it with the new settings.)
Unfortunately, that's not the case. If I create a new VrayAdvancedMaterial with ID_VRAYBRDF_MATERIAL (or with the Interger ID which I looked up and it is indeed longer, the 5703 was for the c4d material), the new settings will not be loaded. The material will be created as if after a clean install. The user settings will not be taken in account. This is the same as with default C4D materials (see first post). When you create a new c4d material with its corresponding ID, the user settings will not be loaded.
-
On 12/01/2013 at 03:17, xxxxxxxx wrote:
That's interesting. I wouldn't have thought that would happen. There must be something different between creating one by using Alloc and creating it in C4D itself.
I've just done some tests with a COFFEE script and indeed you get the original settings, not the changed default. So your only option I think is to create the new material, then change its settings to what you want, then insert it into the document. It looks as thought you can't rely on getting the saved default settings.