Harness proD API Help
EPLAN.Harness.API.Occurrences.Workdesk Namespace / OccWdBundle Class / Material Property
Example
In This Topic
    Material Property (OccWdBundle)
    In This Topic
    Gets or sets the material name of this occurrence.
    Syntax
    public MaterialInfo Material {get; set;}
    Exceptions
    ExceptionDescription
    Api is not in an initialized state. You can get current state from EPLAN.Harness.API.HpdApi.Status property. If API is uninitialized, you can initialize it by calling EPLAN.Harness.API.HpdApi.Init method. If API is in failed state, you can not resurrect it.
    The object is in invalid state. Obtain a new one.
    The exception that is thrown when you trying to access to already deleted occurrence.
    Thrown when it is not allowed to select this material.
    Example
    This example shows how to set the material from library of an occurrence.
    // Obtain the occurrence.
    IOccPart part = designer.GetAllOccurrences<IOccPart>().FirstOrDefault(p => p.Name.Value == "Part:1");
    
    // Select a required material from connected library.
    List<MaterialInfo> materials = project.ActiveConnection.GetMaterials().ToList();
    MaterialInfo material = materials.FirstOrDefault(m => m.Name.Value == "Steel");
    
    // Set its material.
    part.Material = material;
    
    // Notice: The possible null references should be handled in the code. This is simplified sample only.
    This example shows how to set the material (color) of an occurrence from predefined materials.
    // Obtain the occurrence.
    IOccBundle bundle = designer.GetAllOccurrences<IOccBundle>().FirstOrDefault(p => p.Name.Value == "MyBundle");
    
    // Select a required material from predefined materials.
    List<MaterialInfo> materials = MaterialInfo.GetPredefinedMaterials().ToList();
    MaterialInfo material = materials.FirstOrDefault(m => m.Name.Value == "Green");
    
    // Set its material.
    bundle.Material = material;
    This example shows how to reset the material of an occurrence.
    // Obtain the occurrence.
    IOccBundle bundle = designer.GetAllOccurrences<IOccBundle>().FirstOrDefault(p => p.Name.Value == "MyBundle");
    
    // Reset its material. (The default color from Designer settings is set.)
    bundle.Material = null;
    See Also