Object Hierarchy | Related C++ Class: Library
Library
v4.0
A library is a container of objects of the same kind. For example, a material library contains a list of materials. The storage of a library can be either internal or external. For internal storage, it is saved within the scene file. For external, it is saved in a separate file. The library can be exported and imported into a dotXSI format or a native binary format.
/*
This example illustrates how to get a material library and how to
enumerate all materials in a library
*/
NewScene(null, false);
// First create some libraries and materials
CreatePrim("Sphere", "MeshSurface");
ApplyShader(null, "", null, "", siLetLocalMaterialsOverlap);
CreateLibrary();
SelectObj("Sources.Materials.MaterialLibrary");
SetValue("Sources.Materials.MaterialLibrary.Name", "MyLibrary");
SetCurrentMaterialLibrary("Sources.Materials.MyLibrary");
SelectObj("sphere", null, true);
ApplyShader(null, "", null, "", siLetLocalMaterialsOverlap);
// Now enumerate all materials in all libraries
var oScene = Application.ActiveProject.ActiveScene;
var oMaterialLibraries = oScene.MaterialLibraries;
Application.LogMessage("There are " + oMaterialLibraries.Count + " libraries under the scene.");
for( var i=0; i<oMaterialLibraries.Count; i++ ) {
var oLibrary = oMaterialLibraries(i);
Application.LogMessage(oLibrary.Name + " has " + oLibrary.Items.Count + " defined materials");
var oMaterials = oLibrary.Items;
for( var j=0; j<oMaterials.Count; j++ ) {
Application.LogMessage(" - " + oMaterials(j).Name);
}
}
// Expected result:
// INFO : There are 2 libraries under the scene.
// INFO : DefaultLib has 2 defined materials
// INFO : - Scene_Material
// INFO : - Material
// INFO : MyLibrary has 1 defined materials
// INFO : - Material
|