Trouble with SDK flat set and attributes

(Google translation, sorry)

Hello

I have a problem with the flat set.

  1. By creating them, by hand or with

aaApi_CreateFlatSet(lngProjectId, lngDocumentCreeId, 0, 0, ptrStrNomJeu, ptrStrDescription,

lngChildProjectId, lngChildDocumentId, 0)

the link request to the environment attributes table record does not return a record :

NbValues = aaApi_SelectLinkDataByObject(lngTablePropID, AADMSLDT_DOCUMENT, lngProjectId, lngDocumentID, 0, 0, 0, 0)

NbValue is null.

 

  1. In the user interface, simply filling in an attribute creates the link that becomes visible to aaApi_SelectLinkDataByObject

NbValue equal 1

 

This problem does not occur with a normal document.

 

My program must inform the attributes of the newly created flat set, I search how to create this link to the table, but I cannot find.

I tried various things, but without success.

 

Does anyone have ideas or tracks?

Thank you !

  • On reflection, I think that the creation of the flat set does not create a corresponding record in the attribute table, that's why nothing is returned.

  • looking at the set functions. Set creation does not have the option of creating an attribute sheet like normal document creation does. You would need to use the DataLink and EnvAttr functions to create a data sheet for the Flat Set document.  You would need the lplDocument id returned by the create function with the LONG project Id supplied to the set create function to begin the process.  Creating an attribute sheet is not a one function process.  I don't have an example ready to show. If I can find one. I will post it.

  • Take a look at this post: https://communities.bentley.com/products/programming/projectwise_programming/f/projectwise-programming---forum/158362/how-to-create-update-attributes-for-a-document-using-c

    Creating/updating/deleting attributes (or "sheets") use the same process for flat sets as for documents.  You need to determine the ProjectId and DocumentId for the flat set and use those values in your calls to the functions to create/update/delete the attributes.

    HTHs

  • Thank you for the code. it's a bit complicated

    I translated it into VBA for MS-Office:

        ' Sélectionne les enregistrements dans le tampon statique
        NbLignes = aaApi_SelectLinkDataByObject(lngTableAttributs, AADMSLDT_DOCUMENT, lngProjectId, lngDocumentCreeId, 0, 0, 0, 0)
        Select Case NbLignes
        Case Is = ID_ABORT ' -1
            lOK = aaApi_ShowLastErrorMessageBox
            Stop
    
        Case Is = ID_NONE ' 0 : il faut créer l'enregitrement
            lColCount = aaApi_SelectColumnsByTable(lngTableAttributs)
            Select Case lColCount
            Case Is = ID_ABORT ' -1
                lOK = aaApi_ShowLastErrorMessageBox ' renvoie un strptr sur le message de l'erreur
                Stop
            Case Is = ID_NONE ' 0 : table vide ?
                Stop
            End Select
            ' Nettoyer le descripteur d'insertion (?)
            aaApi_FreeLinkDataInsertDesc
            ' Remplir une colonne
            strText = "Via API"
            ptrstrText = StrPtr(strText)
            lColumnId = 1
            lOK = aaApi_SetLinkDataColumnValue(lngTableAttributs, lColumnId, ptrstrText)
            If lOK = 0 Then
                lOK = aaApi_ShowLastErrorMessageBox
                MsgBox aapi
                Stop
            End If
            ' Créer l'enregistrement dans PW
            ptrrecAttribute = 0
            Linkage.lLinkageType = AADMS_EALNK_DOCUMENT
            Linkage.DocumentID.lProjectId = lngProjectId
            Linkage.DocumentID.lDocumentId = lngDocumentCreeId
            Linkage.lEnvironmentId = 0
            ptrLinkage = VarPtr(Linkage)
            lOK = aaApi_CreateEnvAttr(lngTableAttributs, ptrLinkage, ptrrecAttribute)
            If lOK = 0 Then
                lOK = aaApi_ShowLastErrorMessageBox
                Stop
            End If
    
    
    

    Everything works up to aaApi_CreateEnvAttr, and then I have the error:

    "Error while creating link data. Some parts of the mandatory code are empty"

    What did I forget?

    Answer Verified By: Didier POUZET 

  • I would have to see all of your code in order to walk through it, but if you are trying to create rows in the attribute table (the environment), and there are no existing rows, then there's no point in trying to select the existing links and I would use aaApi_SelectLinks() instead of aaApi_SelectLinkDataByObject() to do that as it is more efficient as the point of the ByObject function is being able to pass a WHERE clause which will bypass any cached data and force a "over the wire" database select and return of data.

    To create a new row, you just need to determine the tableId and the column id for the AttributeId column, then you can initialize the buffer, set the properties of the attributes you want to fill in, and the create the row.

    Take another look at the sample I posted, specifically the function DocCmd_CreateNewSheet().  The key steps are:

    • Use aaApiGetEnvTableinfoByProject()
      • To get the keys to tableId, AttrColId
    • Use aaApi_SelectColumnsByTable()
      • To get the ids to the columns you want to populate
    • Use aaApi_FreeLinkDataInsertDesc()
      • To initialize the buffer
    • Use aaApi_SetLinkDataColumnValue()
      • To set the value for the columns you want to populate
    • Use aaApi_CreateEnvAtt()
      • To write the data

    And of course, keep checking for errors as you go.