What's new

Add-On Using Previous Assembly's Information?

KageDev

Member
We've run into an issue while running our add-on after switching from one assembly to another. The previous assembly's information gets used when re-running the add-on in the new assembly. Even when the previous assembly is closed. It seems like Alibre is caching the information to be used in the add-on and the only way we've known to fix it is by completely closing Alibre and restarting with the new assembly. Is there a way to clear the cache or fix however this issue is happening?
 

KageDev

Member
Just found this thread.
Could this be related to my issue?
 

stepalibre

Alibre Super User
I would need to see the code to know for sure but, how are you accessing the root? You have to change the session, if the data is the same you haven't changed it. Or your variable/object is not being updated as you change and close assemblies. Are you using Topmost?

If multiple instances of Alibre Design.exe are running then you might encounter similar issues.

I use code similar to this that can help:

Code:
Sub Main()
    Try           
    For Each process In System.Diagnostics.Process.GetProcessesByName("Alibre Design")
        process.Kill()
    Next
    Catch ex As ArgumentException
        Console.WriteLine(ex.Message)
    End Try
End Sub
 

KageDev

Member
I'm using C# to develop. Here is how my code looks for getting the Session information.
C#:
public class CADPackOperations : IAlibreAddOn
{
    private const int MenuIdRoot = 1001;
    private const int MenuIdAssmOp = 1101;
    private const int MenuIdCost = 1201;
    private const int MenuIdSave = 1301;
    private int[] _menuIdsRoot;
    private IADRoot _alibreRoot;
    private IntPtr _parentWinHandle;
    public CADPackOperations(IADRoot alibreRoot, IntPtr parentWinHandle)
    {
        _alibreRoot = alibreRoot;
        _parentWinHandle = parentWinHandle;
        BuildMenuTree();
    }

    public int RootMenuItem => MenuIdRoot;
    private void BuildMenuTree()
    {
        _menuIdsRoot =
        [
           MenuIdAssmOp,
           //MenuIdCost
           MenuIdSave
        ];
    }
    public bool HasPersistentDataToSave(string sessionIdentifier)
    {
        return false;
    }

    public bool HasSubMenus(int menuId)
    {
        return menuId switch
        {
            MenuIdRoot => true,
            _ => false
        };
    }

    public IAlibreAddOnCommand InvokeCommand(int menuID, string sessionIdentifier)
    {
        var session = _alibreRoot.Sessions.Item(sessionIdentifier);
        return menuID switch
        {
            MenuIdAssmOp => DoAssemblyOperations(session),
            MenuIdCost => DoCostEvaluation(session),
            MenuIdSave => DoPartsSave(session),
            _ => DoNothing(session),
        };
    }


    /// <summary>
    /// Runs the task for finding the lasercut parts and exporting to the server
    /// </summary>
    /// <param name="session"></param>
    private IAlibreAddOnCommand DoAssemblyOperations(IADSession session)
    {
        AlibreSession attach = new(session);
        switch (session.SessionType)
        {
            case ADObjectSubType.AD_PART:
                PartOperations partProgram = new(attach);
                partProgram.Run((IADPartSession)session);
                break;
            case ADObjectSubType.AD_ASSEMBLY:
                AssemblyOperations assyProgram = new(attach);
                assyProgram.Run((IADAssemblySession)session);
                break;
            case ADObjectSubType.AD_SHEET_METAL:
                PartOperations smpProgram = new(attach);
                smpProgram.Run((IADPartSession)session);
                break;
        }
        attach.Dispose();
        return null;
    }

    private IAlibreAddOnCommand DoPartsSave(IADSession session)
    {
        AlibreSession attach = new(session);
        SaveMetaData program = new(attach);
        switch (session.SessionType)
        {
            case ADObjectSubType.AD_PART:
                program.PartSave((IADPartSession)session);
                break;
            case ADObjectSubType.AD_ASSEMBLY:
                program.Run((IADAssemblySession)session);
                break;
            case ADObjectSubType.AD_SHEET_METAL:
                program.PartSave((IADPartSession)session);
                break;
        }
        attach.Dispose();
        return null;
    }


    /// <summary>
    /// Runs the task for finding the lasercut parts and exporting to the server
    /// </summary>
    /// <param name="session"></param>
    private IAlibreAddOnCommand DoCostEvaluation(IADSession session)
    {
        return null;
    }

    private IAlibreAddOnCommand DoNothing(IADSession session)
    {
        return null;
    }

    public void LoadData(IStream pCustomData, string sessionIdentifier)
    {
    }

    public string MenuIcon(int menuID)
    {
        return menuID switch
        {
            MenuIdRoot => "kage.ico",
            MenuIdAssmOp => "kage.ico",
            MenuIdSave => "kage.ico",
            //MenuIdCost => "kage.ico",
            _ => "CAD Pack Operations"
        };
    }

    public ADDONMenuStates MenuItemState(int menuId, string sessionIdentifier)
    {
        return ADDONMenuStates.ADDON_MENU_ENABLED;
    }

    public string MenuItemText(int menuID)
    {
        return menuID switch
        {
            MenuIdRoot => "CAD PAC Operations",
            MenuIdAssmOp => "Session Operations",
            MenuIdSave => "Save Meta Data",
            //MenuIdCost => "Cost Evaluations",
            _ => "CAD PAC Operations"
        };
    }

    public string MenuItemToolTip(int menuID)
    {
        return menuID switch
        {
            MenuIdAssmOp => "Opens list of all parts with the ability to export laser cut parts.",
            MenuIdSave => "Opens a browser to select which parts to save M-Files meta data to.",
            //MenuIdCost => "Cost Evaluations",
            _ => ""
        };
    }

    public bool PopupMenu(int menuID)
    {
        return false;
    }

    public void SaveData(IStream pCustomData, string sessionIdentifier)
    {
    }

    public void setIsAddOnLicensed(bool isLicensed)
    {
    }

    public Array SubMenuItems(int menuId)
    {
        return menuId switch
        {
            MenuIdRoot => _menuIdsRoot,
            _ => null
        };
    }

    public bool UseDedicatedRibbonTab()
    {
        return false;
    }
}
 
Top