Visible switch with cheat code

CheatCode

Mouse

How to use

Press middle button to show or hide selected features. Sample code also brings the concept of cheat code, enter “idkfa” to show all components.

EDIT: Using the V key conflicted with the shortcut for copying and pasting component, so it’s cancelled. Use the middle mouse button to show or hide selected components or features.

Plugin.VisibleSwitch.zip (3.0 KB)
Unzip to C:\Program Files\Visual Components\Visual Components Premium 4.x\

Sample code

using Caliburn.Micro;
using System;
using System.ComponentModel.Composition;
using System.Windows.Controls;
using System.Windows.Input;
using VisualComponents.Create3D;
using VisualComponents.UX.Shared;

namespace VisibleSwitch
{
    [Export(typeof(IPlugin))]
    public class VisibleSwitch : IPlugin
    {
        Grid grid;
        IApplication app;
        ISelectionManager selection;
        IRenderService render;

        string cheatCode = "IDKFA";
        int currentIndex = 0;

        public void Exit()
        {            
        }

        public void Initialize()
        {
            app = IoC.Get<IApplication>();
            render = IoC.Get<IRenderService>();
            selection = app.SelectionManager;

            grid = IoC.Get<IDirect3DViewportViewModel>().ControlGrid;
            if (grid != null)
            {                
                grid.PreviewKeyDown += Grid_PreviewKeyDown;
                grid.PreviewMouseDown += Grid_PreviewMouseDown;
            }
        }

        private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            
            if (e.MiddleButton == MouseButtonState.Pressed)
            {
                var selectedComponents = selection.GetSelection<ISimComponent>();
                foreach (var selected in selectedComponents)
                {
                    selected.IsVisible = selected.IsVisible == false;
                }

                var selectedFeatures = selection.GetSelection<IFeature>();
                foreach (var selected in selectedFeatures)
                {
                    selected.IsVisible = selected.IsVisible == false;
                }             
            }          
        }

        private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
        {            
            if (e.Key.ToString() == cheatCode[currentIndex].ToString())
            {
                currentIndex++;

                if (currentIndex == cheatCode.Length)
                {
                    foreach (var component in app.World.Components)
                    {
                        component.IsVisible = true;
                    }
                    render.RequestRender();
                    currentIndex = 0;
                }
            }
            else
            {
                currentIndex = 0;
            }
        }
    }
}
6 Likes

hey, i don’t know what i did wrong, but it doesn’t work. I unziped it to the correct path. Did i forgot a setting or something or did something go wrong while unzip, because my .dll file has only 3KB.

Can someone help me, because this Add.On would be very nice. Thank you. :slight_smile:

What is your version? Just in case could you show the image of the folder of the file you placed?

Now i use Version Visual components Premium 4.7, as you can see in the pictures.


Cool, you are using the same version as mine.
I tested it, it should work.
Try to select a component or feature, press mouse wheel button.
Not V key, because it’s conflicted with paste shortcut (ctrl + v).

I try, but it wouldn’t work. nothing will happen if I press the mouse wheel sorry.

Try this one, I add another shortcut, select components or features, press F4 key or mouse wheel button. After unzip, it should be 6.5 KB. If the file size is different after unzip, try to download .dll directly.

Plugin.VisibleSwitch.dll.zip (3.0 KB)
Plugin.VisibleSwitch.dll (6.5 KB)

1 Like

Now it works. Thank you very much

1 Like

Hi Chungmin.

Is it possible to use this and/or a signal to turn on/off the visibility of a feature?

Use case: I am recording a video and want to turn on/off specific component features at specific times in the video

I.E.:

-Select a feature
-Connect a signal to the parent component
-Connect the signal to a timer
-Set timer
-Feature turns off when timer turns off

Thanks.