ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Geometry Namespace / Multipatch Class / GetPatchMaterialIndex Method
The index of the patch. Must be greater than or equal to zero and less than PartCount.
Example

In This Topic
    GetPatchMaterialIndex Method
    In This Topic
    Gets the index of the material for the specified patch (part).
    Syntax
    Public Function GetPatchMaterialIndex( _
       ByVal patchIndex As Integer _
    ) As Integer
    public int GetPatchMaterialIndex( 
       int patchIndex
    )

    Parameters

    patchIndex
    The index of the patch. Must be greater than or equal to zero and less than PartCount.

    Return Value

    The index into the materials array of the multipatch for the patch.
    Exceptions
    ExceptionDescription
    The patch index must be >= 0.
    The patch index must be less than the number of patches (parts) in the multipatch.
    This multipatch does not have materials.
    Remarks
    The material index is used in several methods to get properties of the material. If the patch has material, the returned value is greater than or equal to zero and less than MaterialCount. If the patch does not have material, -1 is returned.
    Example
    Get the texture image of a multipatch
    {
      int patchIndex = 0;
      int materialIndex = multipatch.GetPatchMaterialIndex(patchIndex);
      if (!multipatch.IsMaterialTextured(materialIndex))
        return;
    
      TextureCompressionType compressionType =
        multipatch.GetMaterialTextureCompressionType(materialIndex);
    
      string ext = compressionType == TextureCompressionType.CompressionJPEG ? ".jpg" : ".dat";
      byte[] textureBuffer = multipatch.GetMaterialTexture(materialIndex);
    
      Stream imageStream = new MemoryStream(textureBuffer);
      System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream);
      image.Save(@"C:\temp\myImage" + ext);
    }
    Get the material properties of a multipatch
    {
      if (multipatch.HasMaterials)
      {
        int patchIndex = 0;
        // Get the material index for the specified patch.
        int materialIndex = multipatch.GetPatchMaterialIndex(patchIndex);
    
        System.Windows.Media.Color color = multipatch.GetMaterialColor(materialIndex);
        int tranparencyPercent = multipatch.GetMaterialTransparencyPercent(materialIndex);
        bool isBackCulled = multipatch.IsMaterialCullBackFace(materialIndex);
    
        if (multipatch.IsMaterialTextured(materialIndex))
        {
          int bpp = multipatch.GetMaterialTextureBytesPerPixel(materialIndex);
          int columnCount = multipatch.GetMaterialTextureColumnCount(materialIndex);
          int rowCount = multipatch.GetMaterialTextureRowCount(materialIndex);
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also