CustomMeshObject: IsHighlighted does not work?

Again, still experimenting with CustomMeshObject. When selecting an object using a selection menu (e.g. when multiple objects are present at the pick point) I would like to have the object be drawn in a highlight color (e.g. Color.LightPink)

I try to do this by the code below, but IsSelected(false) is never greater than zero. I do see that when the custom mesh is highlighted, that its wireframe gets drawn with thicker lines though.

Highlight surface:

Highlight mesh (notice thicker lines):

What I would like is that the second picture gets drawn in the highlight color, not in black.

private Color GetColor(Color defaultColor)
{
    if (IsSelected(false) > 0)
    {
        return Color.Yellow;
    }

    if (IsHighlighted(false) > 0)
        return Color.LightPink;
                        
    return defaultColor;
}

protected override void OnDraw(DrawEventArgs e)
{
    if (Attributes.ColorSource == ObjectColorSource.ColorFromLayer || Attributes.ColorSource == ObjectColorSource.ColorFromParent)
    {
        int layerIndex = Attributes.LayerIndex;
        Layer l = e.RhinoDoc.Layers[layerIndex];
        e.Display.DrawMeshWires(MeshGeometry, GetColor(l.Color));
    }

    else if (Attributes.ColorSource == ObjectColorSource.ColorFromMaterial)
    {
        Material m = GetMaterial(true);
        DisplayMaterial dm = new DisplayMaterial(m);
        e.Display.DrawMeshShaded(MeshGeometry, dm);
        Color c = GetColor(Color.Empty);
        if (c != Color.Empty)
            e.Display.DrawMeshWires(MeshGeometry, c);
    }

    else // color from object
    {
        e.Display.DrawMeshWires(MeshGeometry, GetColor(Attributes.ObjectColor));
    }
}

Sort of solved it. Highlight is apparently not the property I was looking for. The distinguising difference to “detect” the selection menu being active is

  1. The custom object is not selected and
  2. The DepthMode of the display pipeline is AlwaysInFront

This seems to work, so I now have the code below. Let me know if this is more simple to solve. What I don’t like is that I look at the depth mode - any scenario in which it is AlwaysInFront (maybe in a VisualAnalysisMode or other DisplayPipeLine) will show the mesh in light pink.

private Color GetColor(Color defaultColor, DepthMode mode)
{
    // selection menu active
    if (IsSelected(false) <= 0 && mode == DepthMode.AlwaysInFront)
    {
        return Color.FromArgb(255, 214, 237);
    }
            
    if (IsSelected(false) > 0)
    {
        return Color.Yellow;
    }

    return defaultColor;
}

protected override void OnDraw(DrawEventArgs e)
{
    if (Attributes.ColorSource == ObjectColorSource.ColorFromLayer || Attributes.ColorSource == ObjectColorSource.ColorFromParent)
    {
        int layerIndex = Attributes.LayerIndex;
        Layer l = e.RhinoDoc.Layers[layerIndex];
        e.Display.DrawMeshWires(MeshGeometry, GetColor(l.Color, e.Display.DepthMode));
    }

    else if (Attributes.ColorSource == ObjectColorSource.ColorFromMaterial)
    {
        Material m = GetMaterial(true);
        DisplayMaterial dm = new DisplayMaterial(m);
        e.Display.DrawMeshShaded(MeshGeometry, dm);
        Color c = GetColor(Color.Empty, e.Display.DepthMode);
        if (c != Color.Empty)
            e.Display.DrawMeshWires(MeshGeometry, c);
    }

    else // color from object
    {
        e.Display.DrawMeshWires(MeshGeometry, GetColor(Attributes.ObjectColor, e.Display.DepthMode));
    }
}

Solved it completely now by calling

base.OnDraw(e);

instead of the complete OnDraw method above. This base method call will draw the mesh including highlighting and selection color.

A post was split to a new topic: CustomMeshObject and Python