The ability of Presenter is available only in COM API currently. It is provided in terms of a plug-in. You will need to use COM interop if you work with .NET API.
In theory, there are three ways to get material, but there are some limitations with the current API.
1) assume you have added a material to the palette by UI. you can iterate and find it by name. this works with plug-in or control.
2) you can add a material from archive. But this only works in a plug-in. It does not work in .NET or ActiveX control.
3) API has one method to add material from a bitmap. However it is not implemented yet.
The following code shows the 3 ways. Please note the comments.
public void applyMaterial()
{
ComApi.InwOpState10 state;
ComApi.InwOwPresenterElement m_presenter = null;
state = ComBridge.State;
//find presenter plugin
foreach (ComApi.InwBase oPlugin in state.Plugins())
{
if (oPlugin.ObjectName == "nwOwPresenterElement")
{
m_presenter = (ComApi.InwOwPresenterElement)oPlugin;
break;
}
}
if (m_presenter == null)
{
System.Windows.Forms.MessageBox.Show("cannot find presenter plugin!");
return;
}
ComApi.InwOwUserMaterialsColl materials = m_presenter.UserMaterials();
ComApi.InwOwMaterial material_to_apply = null;
String oMaterial_name_to_apply = "Shiny texture";
// way1: assume the "Shiny texture" has been added to the palette by UI
// iterate and find the material
//bool flgFind = false;
//foreach (dynamic dmaterial in m_presenter.UserMaterials())
//{
// ComApi.InwOwMaterial nmaterial = dmaterial as ComApi.InwOwMaterial;
// if (nmaterial.name == oMaterial_name_to_apply)
// {
// material_to_apply = nmaterial;
// flgFind = true;
// break;
// }
//}
// way2: in plugin, you can add from Archive
// Note: this does not work with ActiveX control or .NET control
try
{
m_presenter.UserMaterials().AddFromArchive(oMaterial_name_to_apply);
material_to_apply = m_presenter.UserMaterials().Last() as ComApi.InwOwMaterial;
}
catch (SystemException ex)
{ ;}
//// way3: from bitmap // this is NOT implemented!!
//try
//{
// //m_presenter.UserMaterials().LoadFromFile(@"c:\mytest.bmp");
//}
//catch (SystemException ex)
//{ ;}
if (material_to_apply != null)
{
// apply the material to the selected object
if (state.CurrentSelection.Paths().Count > 0)
{
foreach (ComApi.InwOaPath path in state.CurrentSelection.Paths())
{
m_presenter.MaterialMappings().AddMapping(oMaterial_name_to_apply, path, false);
}
}
}
}
About changing background, you could find a sample in SDK \api\COM\examples\Auto\AutoPresenterExample
or refer to this blog:
http://adndevblog.typepad.com/aec/2012/07/changing-background-for-publishing-file-using-script-automation-in-navisworks.html