.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Monitor for profile change

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
makepeace1
530 Views, 3 Replies

Monitor for profile change

I have got a ribbon that loads using a dll

 

At the moment i have got it monitoring to see if the "WSCURRENT" changes but when the profile changes it doesnt change the "WSCURRENT"

 

as long as its not autocad calssic it will reload the ribbon

 

 If Not Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("WSCURRENT").ToString.ToLower = "autocad classic" Then

 

How can i monitor for a profile change ?

3 REPLIES 3
Message 2 of 4
quigs
in reply to: makepeace1

Hi,

You could look at Event Handlers.  I am not sure what one but I would assume there is some kind of event that could be used for this.

My name is Martin.. 😄
Message 3 of 4
makepeace1
in reply to: quigs

ok

 

I have worked out how to do it but it seems to unload again once i click ok to close the window where you change the profile

 

AddHandler Autodesk.AutoCAD.ApplicationServices.Application.UserConfigurationManager.CurrentProfileChanged, AddressOf acApp_CurrentProfileChanged

 

Private Sub acApp_CurrentProfileChanged(ByVal sender As Object, ByVal e As ProfileEventArgs)

            LOADMENU()

        End Sub

 Any idea's?

Message 4 of 4
makepeace1
in reply to: makepeace1

I asked the question to autodesk this is the reponse that i got

 

The RibbonPaletteSet.Loaded event is the best way to ensure your ribbon items get re-created whenever a disrupting action occurs in AutoCAD.

 

Here is a complete example:

 

[CommandMethod("SimpleButton")]
public void SimpleButton()
{
    RibbonServices.RibbonPaletteSet.Loaded += 
        new EventHandler(RibbonPaletteSet_Loaded);           

    // Makes sure Ribbon is visible (crash otherwise)
    // If not make Ribbon visible
    if (Autodesk.Windows.ComponentManager.Ribbon != null)
    {
        CreateSimpleButton();
    }
    else
    {
        Autodesk.AutoCAD.ApplicationServices.Application.Idle +=
            new EventHandler(Application_Idle);

        Document doc = Application.DocumentManager.MdiActiveDocument;
        doc.SendStringToExecute("RIBBON ", true, false, false);
    }
}

void RibbonPaletteSet_Loaded(object sender, EventArgs e)
{
    Autodesk.AutoCAD.ApplicationServices.Application.Idle +=
        new EventHandler(Application_Idle);
}

void Application_Idle(object sender, EventArgs e)
{
    if (Autodesk.Windows.ComponentManager.Ribbon != null)
    {
        Autodesk.AutoCAD.ApplicationServices.Application.Idle -= 
            new EventHandler(Application_Idle);

        var ribbon = Autodesk.Windows.ComponentManager.Ribbon;

        var tab = ribbon.FindTab("ADN_TAB_ID");

        if (tab == null || !tab.IsVisible)
        {
            CreateSimpleButton();
        }
    }
}

public void CreateSimpleButton()
{
    RibbonControl ribbonControl = 
        ComponentManager.Ribbon;

    RibbonTab Tab = new RibbonTab();
    Tab.Title = "Test Ribbon";
    Tab.Id = "ADN_TAB_ID";

    ribbonControl.Tabs.Add(Tab);

    RibbonPanelSource srcPanel = 
        new RibbonPanelSource();

    srcPanel.Title = "Panel1";

    RibbonPanel Panel = new RibbonPanel();
    Panel.Source = srcPanel;
    Tab.Panels.Add(Panel);

    Autodesk.Windows.RibbonButton button1 = 
        new RibbonButton();

    button1.Text = "Button";
    button1.Size = RibbonItemSize.Large;
    button1.Orientation = System.Windows.Controls.Orientation.Horizontal;   

    button1.Image = 
        getBitmap(Properties.Resources.Apps, 16, 16);

    button1.LargeImage = 
        getBitmap(Properties.Resources.Apps, 32, 32);

    button1.ShowText = false;
    button1.CommandParameter = "._LINE ";
    button1.CommandHandler = new SimpleButtonCmdHandler();

    srcPanel.Items.Add(button1);
            
    Tab.IsActive = true;
}

//Use: getBitmap(Properties.Resources.a_large);
BitmapImage getBitmap(Bitmap bitmap, int height, int width)
{
    MemoryStream stream = new MemoryStream();
    bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);

    BitmapImage bmp = new BitmapImage();
    bmp.BeginInit();
    bmp.StreamSource = new MemoryStream(stream.ToArray());
    bmp.DecodePixelHeight = height;
    bmp.DecodePixelWidth = width;
    bmp.EndInit();

    return bmp;
}

public class SimpleButtonCmdHandler : 
    System.Windows.Input.ICommand
{
    public bool CanExecute(object parameter)
    {
        return true;
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
        if (parameter is RibbonButton)
        {
            // builds escape sequence to cancel active commands
            string esc = "";

            string cmds = (string) Application.
                GetSystemVariable("CMDNAMES");

            if (cmds.Length > 0)
            {
                int cmdNum = cmds.Split(new char[] { '\'' }).Length;

                for (int i = 0; i < cmdNum; i++)
                    esc += '\x03';
            }

            RibbonButton button = parameter as RibbonButton;

            Document doc = Application.
                DocumentManager.MdiActiveDocument;

            doc.SendStringToExecute(esc + button.CommandParameter, 
                true, false, false); 
        }
    }
}

 Seems to do the job

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost