aaApi_CreateAssociation usage

I didn't find a sample with aaApi_CreateAssociation, what are params LPCWSTR  lpctstrName,  LPCWSTR  lpctstrDesc 

I guess the latter is just a description, but what is lpctstrName? does it have to be something special or unique?

I want to check in a DWG document and xref, where the xref should be associated with the DWG.

Thanks Slight smile

~Dan

Parents
  • static void assoc(const PwDocument &pwDoc, std::vector<PwDocument> &children)
        {
            for (const auto& child : children)
            {
                if (pwDoc.isValid() && child.isValid())
                {
                    auto res = aaApi_CreateAssociation
                    (
                        pwDoc.projectId(),
                        pwDoc.documentId(),
                        child.projectId(),
                        child.documentId(),
                        0,
                        0,
                        _T("\nOHPLEASEWORK"),
                        _T("\nOHPLEASEWORK DESC")
                    );
                    if (res == 0)
                    {
                        pwApp.promptLastError(_T("\nFailed to associate"));
                    }
                }
            }
        }

    Here's my sample, I get AAERR_DMS_ERR_INVALID_ARG   58002 

  • Hi ,

    Although no line number for the error was provided to confirm which parameter is failing, I have to presume it is parameter #5 that is failing since the documentation states its value cannot be zero.

    Argument #5 (lAssociationType) is an Index, that ideally if "maintaining" should match the source documents "association type" index, obtained by calling: e.g. srcBuffer.GetNumericProperty(ASSOC_PROP_TYPE, lIndex); then applying that index value to appropriate destination/target documents in your array.

    Lastly, unless you have need to work with project and document ids directly at this layer of your code, there is an updated method (if helpful -  aaApi_GUIDCreateAssociation) that takes GUIDs and may prevent confusion/conflicts that may occur when working with source and destination document arrays managed across different data sources.

    HTH,
    Bob



    Answer Verified By: Daniel Marcotte 

  • Hi Bob,

    The function succeeds when setting param #5 to to some value, but I don't see a link in the dependency viewer, I will 

    try using GetNumericProperty(ASSOC_PROP_TYPE, lIndex); on some samples and check the values.

    the sequence is:

    aaApi_SaveDocumentDlg2

    -  aaApi_CreateAssociation

    So using the IDS seemed natural

  • Hello Bob, I'm still having trouble.

    In AutoCAD, If import a .DWG and a dependent .XREF, also a DWG.

    I can see the association in PW explorer, but when I try to get the association information, it fails

    my code

     static void testGetAssoc()
        {
            auto& data = DocVars.docData();
            auto& pwDoc = data.getPwDoc();
            if (pwDoc.isValid()) //ids are ok
            {
                const int cnt = aaApi_SelectAssociationChilds(pwDoc.projectId(), pwDoc.documentId(), -1);
                //const int cnt = aaApi_SelectAssociations(pwDoc.projectId(), pwDoc.documentId(), -1, -1, -1);
                //const int cnt = aaApi_SelectAssociations(-1, -1, -1, -1, -1);
                if (cnt < 1)
                    pwApp.promptLastError();
                for (int idx = 0; idx < cnt; idx++)
                {
                    const int ID = aaApi_GetAssociationNumericProperty(ASSOC_PROP_TYPE, idx);
                    const TCHAR* name = aaApi_GetAssociationStringProperty(ASSOC_PROP_NAME, idx);
                    const TCHAR* desc = aaApi_GetAssociationStringProperty(ASSOC_PROP_DESC, idx);
                    acutPrintf(_T("\nID=%ld, Name=%ls, Desc=%ls"), ID, name, desc);
                }
            }
        }

    code=50000, error=Not found.:

Reply
  • Hello Bob, I'm still having trouble.

    In AutoCAD, If import a .DWG and a dependent .XREF, also a DWG.

    I can see the association in PW explorer, but when I try to get the association information, it fails

    my code

     static void testGetAssoc()
        {
            auto& data = DocVars.docData();
            auto& pwDoc = data.getPwDoc();
            if (pwDoc.isValid()) //ids are ok
            {
                const int cnt = aaApi_SelectAssociationChilds(pwDoc.projectId(), pwDoc.documentId(), -1);
                //const int cnt = aaApi_SelectAssociations(pwDoc.projectId(), pwDoc.documentId(), -1, -1, -1);
                //const int cnt = aaApi_SelectAssociations(-1, -1, -1, -1, -1);
                if (cnt < 1)
                    pwApp.promptLastError();
                for (int idx = 0; idx < cnt; idx++)
                {
                    const int ID = aaApi_GetAssociationNumericProperty(ASSOC_PROP_TYPE, idx);
                    const TCHAR* name = aaApi_GetAssociationStringProperty(ASSOC_PROP_NAME, idx);
                    const TCHAR* desc = aaApi_GetAssociationStringProperty(ASSOC_PROP_DESC, idx);
                    acutPrintf(_T("\nID=%ld, Name=%ls, Desc=%ls"), ID, name, desc);
                }
            }
        }

    code=50000, error=Not found.:

Children
No Data