1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ Sessions listing

Discussion in 'Add-on Development' started by m.marek, Sep 26, 2019.

  1. m.marek

    m.marek Member

    Hello all,

    My task is to get the list of all openned sessions.
    I need to know the parts and assemblies NAMES and file paths (if saved).
    Is there any existing example code for C++ develpment.

    Note:
    I dont't have an "Item" object when using C++.
    objRoot.Sessions.Items(1)
     
  2. simonb65

    simonb65 Alibre Super User

    Here is a snippet of a sessions iterator (in C++), you need to use the root object that you get from the COM hook ...

    Code:
    IADSessionPtr CAddOnInterface::GetSessionFromIdentifier(/*[in]*/ BSTR sessionIdentifier)
    {
        IADSessionPtr pSession = NULL;
    
        IADSessionsPtr pSessions = theApp.m_pRoot->GetSessions();
        if (pSessions != NULL)
        {
            if (pSessions->GetCount() > 0)
            {
                IEnumVARIANTPtr pEnumSessions = pSessions->GetEnumerator();
                ULONG fetched;
                _variant_t var;
                HRESULT res = pEnumSessions->Next(1, &var, &fetched);
                while (SUCCEEDED(res) && fetched > 0)
                {
                    pSession = (IADSessionPtr)var;
                    BSTR id = (BSTR)pSession->GetIdentifier();
                    if (wcscmp(id, sessionIdentifier) == 0)
                        return pSession;
                    else
                        res = pEnumSessions->Next(1, &var, &fetched);
                }
            }
            pSessions = NULL;
        }
        return NULL;
    }
    
    Just use pSession to drill down through its members and get the info you need.

    What you show, looks like VB to me !
     
  3. m.marek

    m.marek Member

    Thank you for your reply, yes it was an example VB code.

    I'll try your code, but temporary I testes this solution and it sems to work:

    int count;
    VARIANT Myindex;


    Root->Sessions->get_Count( &count);

    for(int i=0 ; i<count ; i++)
    {
    Myindex.lVal = i; //session index
    Myindex.vt = VT_I4;
    Root->Sessions->get_Item( Myindex , iSession);
    NAME = iSession->Name;
    }

    BR
    Marcin
     
  4. m.marek

    m.marek Member

    Your code was better.
    My code freezes the thread when accesing the BOM or Drawing session type. Don't know why.

    BR Marcin
     

Share This Page