SDK: Why does aaApi_CopyDocumentAttributes always create a new attribute sheet?

Why does aaApi_CopyDocumentAttributes always creates a new attribute sheet? Is this by design? If so, is there a way to force it to overwrite the attributes of the target from the source?

Here's a simple snippet of code (very basic, no error handling, only expects one document to to be passed) that demonstrates this. It's called from a document menu added via a MRR.

extern "C" int WINAPI DocCmd_Test
(
  unsigned int uiCount, //==>Count of documents
  long* plProjArray, //==>Project number Array
  long* plDocArray //==> Document number Array
)
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState());
  HWND hWndParent = aaApi_GetActiveDocumentList();
  LONG lplProjectId = -1L;
  LONG lplDocumentId = -1L;
  // Select the source data
  aaApi_SelectDocumentDlg2 ( 
    hWndParent,
    L"Select source file of attributes",
    NULL,
    AADOCSELDF_FULLMENU,
    0L,
    &lplProjectId, // o
    &lplDocumentId // o
  );
  // Copy the source data from source to target
  aaApi_CopyDocumentAttributes (
    lplProjectId,
    lplDocumentId,
    plProjArray[0],
    plDocArray[0],
    NULL
  );
  aaApi_UpdateDocumentWindows ();
  return IDOK;
}
  • Function aaApi_CopyDocumentAttributes() adds attribute records to the existing attribute record list.
    If the attribute records managed by attribute environments, use function aaApi_CopyDocumentEnvAttrRec(). This function copies a single attribute record and you can tell the function what target attribute needs to be overwritten.

     

    Alternatively you can:
    aaApi_DeleteDocumentAttributes (targetProjectId, targetDocumentId);
    aaApi_CopyDocumentAttributes (sourceProjectId, sourceDocumentId, targetProjectId, targetDocumentId, copyFlags);

  • Yaroslav Lobachevski:
    Function aaApi_CopyDocumentAttributes() adds attribute records to the existing attribute record list.

    Thanks for confirming that this is by design. It isn't clear in the SDK documentation.

    I ended up doing what you suggested, delete the attributes prior to copying them. I would prefer to use aaApi_CopyDocumentEnvAttrRec, but since the there is no way to tell what the attribute record id's are for the selected attribute sheet (it's not passed to MRR menu commands), there really is no way of know which attribute sheet (if there are multiple) the user selected for action, since only the projectid and docid are passed to a Document command. Given that, I don't see any way of using aaApi_CopyDocumentEnvAttrRec in a standard doc command called from a MRR when dealing with documents with multiple sheets. How do the "Copy Attributes" and "Paste Attributes" commands work this out when you are dealing with documents that have multiple attribute sheets?

    Fortunately, in our case, since we aren't using multiple attribute sheets at this time, the "delete first then copy" approach is workable in our environment. But if we start using multiple attributes sheets per document, that approach will no longer work.

    Please note that I post here on a voluntary basis and am not a Bentley employee. 

  • The SDK documentation has been updated with notes to clarify the outcome of the API call.