Hi
I would like to create new versions of PDF files in ProjectWise (PW) via the API. To illustrate my problem I've made a small test program:
DgnIndexIteratorP modelIterator; DgnIndexItemP modelIndexItem; wchar_t wcModelName[MAX_MODEL_NAME_LENGTH]; DgnModelType iModelType; if (mdlSystem_findMdlDesc(L"PLOTDLG") == NULL) { mdlSystem_loadMdlProgram(L"PLOTDLG", L"PLOTDLG", NULL); mdlInput_sendSynchronizedKeyin(L"print", 0, INPUTQ_EOQ, NULL); } wchar_t szKeyin[MAXFILELENGTH + 25]; swprintf(szKeyin, L"print driver %ls", L"ArteliaDK_DDA_PDF_Plotmap.pltcfg"); mdlInput_sendSynchronizedKeyin(szKeyin, 0, MSInputQueuePos::INPUTQ_HEAD, 0); modelIterator = mdlModelIterator_create(mdlModelRef_getDgnFile(mdlModelRef_getActive())); while ((modelIndexItem = mdlModelIterator_getNext(modelIterator)) != NULL) { mdlModelItem_getData(modelIndexItem, &iModelType, NULL, NULL, NULL, NULL); if (iModelType == DgnModelType::Sheet) { mdlModelItem_getName(modelIndexItem, wcModelName, MAX_MODEL_NAME_LENGTH); WString plotfileName = L""; ConfigurationManager::GetVariable(plotfileName, L"MS_PLTFILES"); plotfileName.append(wcModelName); plotfileName.append(L".pdf"); DgnModelRefP modelRef; if (mdlModelRef_createWorkingByName(&modelRef, ISessionMgr::GetActiveDgnFile(), wcModelName, FALSE, FALSE) == SUCCESS) { mdlModelRef_activateAndDisplay(modelRef); mdlInput_sendSynchronizedKeyin(L"print boundary sheet", 0, INPUTQ_EOQ, NULL); wchar_t szKeyIn[100]; swprintf(szKeyIn, L"print scale %f", 1000.0); mdlInput_sendSynchronizedKeyin(szKeyIn, 0, INPUTQ_EOQ, NULL); swprintf(szKeyIn, L"print execute %ls", plotfileName.c_str()); mdlInput_sendSynchronizedKeyin(szKeyIn, 0, INPUTQ_EOQ, NULL); mdlModelRef_freeWorking(modelRef); if (aaApi_Initialize(AAMODULE_EXPLORER)) { BoolInt fCheckedOut; long baseProjNo, projNo, docNo, setNo; GUID docGuid; wchar_t fileName[2 * MAXFILELENGTH]; int rc = mdmMain_getActiveMDocument(&fCheckedOut, &baseProjNo, &docNo, &docGuid, &setNo, fileName, 2 * MAXFILELENGTH); // Get path to current project wchar_t projNamePath[MAXFILELENGTH]; aaApi_GetProjectNamePath2(baseProjNo, false, '\\', projNamePath, MAXFILELENGTH); // PDF files are stored in "01 Digitale plots" wcscat(projNamePath, L"\\01 Digitale plots"); // Get projectID for this folder projNo = aaApi_GetProjectIdByNamePath(projNamePath); // Check if document allready exists size_t pos = plotfileName.find_last_of(L"\\", plotfileName.length()); if (aaApi_SelectDocumentsByNameProp(projNo, &plotfileName[pos + 1], NULL, NULL, NULL) > 0) { long docID = aaApi_GetDocumentId(0); long versionDocID; if (!aaApi_NewDocumentVersion(AADOCVERF_COPY_ATTRS, projNo, docID, NULL, NULL, &versionDocID)) { lifalib_dmsg("Error creating new version:"); lifalib_dmsg("%ls", aaApi_GetLastErrorMessage()); lifalib_dmsg("%ls", aaApi_GetLastErrorDetail()); } else lifalib_log("PW_LIFATools", 0, 1, "pw_CreateDocumentsFromFiles - aaApi_NewDocumentVersion => OK, versionDocID = %d", versionDocID); } else { int newFilesToCreate = 1; wchar_t** fileNames = (wchar_t**)malloc(newFilesToCreate * sizeof(wchar_t*)); for (int index = 0; index < newFilesToCreate; index++) { fileNames[index] = (wchar_t*)malloc(MAXFILELENGTH * sizeof(wchar_t*)); wcscpy(fileNames[index], plotfileName.c_str()); lifalib_log("PW_LIFATools", 0, 1, "pw_CreateDocumentsFromFiles - %ls", fileNames[index]); } long docIDs[100]; if (aaApi_CreateDocumentsFromFiles(projNo, (LPCWSTR*)fileNames, newFilesToCreate, AADOCRULE_POSTFIX, L"", AADOCRULE_POSTFIX, L"", AARULEO_NO_UPDATE | AARULEO_NO_WIZARDS | AARULEO_RECREATE_RELATIONS, NULL, NULL, docIDs) == FALSE) { lifalib_dmsg("Error creating new documents:"); lifalib_dmsg("%ls", aaApi_GetLastErrorMessage()); lifalib_dmsg("%ls", aaApi_GetLastErrorDetail()); } // Free memory for (int index = 0; index < newFilesToCreate; index++) free(fileNames[index]); free(fileNames); } } } } } mdlModelIterator_free(modelIterator);
A short decription: This code opens the plotdialog and creates PDF files of all the sheet models in the active file. Afterwards these PDF files will be saved in PW or a new version will be created. There is no problem in creating the new documents but creating new versions does not work correctly.
After creating the first new version (Rev. A) I can see that the PW document is not updated - I use right click -> View.
Okay, then I make some more changes to the sheet models and runs the program again. This time the document in PW is updated but only if you have viewed revision A. If you have now viewed revision A then revision B looks the same as the original PDF file. If you now go back and check revision B then this revision also looks the same as the original PDF file!!!
What am I missing or doing wrong ?
TIA, Evan
I think you are missing a step. After the new version creation, you have to go and replace the file. I use aaApi_ChangeDocumentFile4(). Looks like you'd need to change your logic around line 76. Would be interesting to know if you could accomplish this via Edit-PWMicroStationDocuments in PowerShell assuming you wanted to do it non-interactively.
Dave
Answer Verified By: EvanH
Hi Dave
Thank you very much for your reply. It works just fine now...
Evan