Getting started with the SDK

Hi,

I need to create a PW API based application but I am struggling with the SDK documentation : from what I have seen it seems to be code generated document listing function and struct of PW module with a brief description of parameters...What I need to perform seems quite basic : connect to PW then fetch a document, modify it and then save it back to PW. I haven't found any project in the samples showing how to fetch a document for instance. I can't imagine Bentley sells the SDK leaving users without a "Getting started" document so I think I am surely missing something...

Do you know about an overview documentation ? What would you recommand to get quickly up and running with the SDK ?  

Thanks.

Parents
  • The ProjectWise SDK class would be one way to get up and running with the SDK, but I'm a bit bias since I'm the instructor for most of those classes.

    You should search through the various postings on this site for various questions about "how do I..." with the SDK.

    To get the SDK samples to compile and get them running, that will take a little bit of work on your part depending upon your development environment, version of Visual Studio, version of ProjectWise, skills and experience, etc.

    Not all the samples compile into .exe's, many are "custom modules" which are essentially DLLs that get loaded by ProjectWise Explorer at start up in a specific way.  The Custom Module Manager is the tool to use to configure your custom module for debugging and testing, check the documentation for details.

    If you start with a simple Windows console application, the basic flow is:

    • Initialize the SDK
    • Log into a datasource
    • Do something
    • Log out of the datasource
    • Uninitialize the SDK

    Here's some sample code that I provide in the class early on to show the flow:

    /****************************************************************************
    *
    *             ProjectWise(TM) CONNECT Edition Software Development Kit
    *             Sample Application
    *             Copyright (C) 2018 Bentley Systems, Incorporated
    *             All Rights Reserved
    *
    ****************************************************************************/
    // MyConsoleApp02.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "MyConsoleApp02.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    // The one and only application object
    
    CWinApp theApp;
    
    using namespace std;
    
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
        int nRetCode = 0;
    
        HMODULE hModule = ::GetModuleHandle(NULL);
    
        if (hModule != NULL)
        {
            // initialize MFC and print and error on failure
            if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
            {
                // TODO: change error code to suit your needs
                _tprintf(_T("Fatal Error: MFC initialization failed\n"));
                nRetCode = 1;
            }
            else
            {
                // TODO: code your application's behavior here.
                LONG        lV1, lV2, lV3, lV4;
                WCHAR       szVersion[100];
                BOOL        bRetCode = FALSE;
                HDSOURCE    hDs = NULL;
    
                aaApi_Initialize (AAMODULE_ALL);
                aaApi_GetAPIVersion (&lV1, &lV2, &lV3, &lV4);
                wsprintf (szVersion, L"%d.%d.%d.%d", lV1, lV2, lV3, lV4);
                aaApi_MessageBox (szVersion, MB_OK);
    
    			//bRetCode = aaApi_Login (AAAPIDB_UNKNOWN, 
    			//            L"win2k3pwv8isdk:PWDemo", 
    			//            L"admin", 
    			//            L"admin", 
    			//            NULL);
    			bRetCode = aaApi_Login (0, 
    			            L"pwcesdk:PWDemo", 
    			            L"pwadmin", 
    			            L"pwadmin", 
    			            NULL);
    			if (!bRetCode)
                {
                    aaApi_MessageBox (L"Could not login!", MB_OK);
                    aaApi_Uninitialize();
                    nRetCode = -1;
                }
                else
                {
                    aaApi_MessageBox (L"Login successful!", MB_OK);
                    hDs = aaApi_GetActiveDatasource();
                    aaApi_LogoutByHandle (hDs);
                    aaApi_Uninitialize();
                    nRetCode = 0;
                }
            }
        }
        else
        {
            // TODO: change error code to suit your needs
            _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
            nRetCode = 1;
        }
    
        return nRetCode;
    }
    

    This is C++ and uses Microsoft's MFC classes, but you should get the general idea of the flow of the steps.  The login API is hardcoded, but you can change that to use a dialog.  Check out the documentation for the differences of loging in in as a user or as an administrator.

    As for "fetching" a document and modifying it, it "all depends" upon what you mean by "modify".  To modify a ProjectWise Document, you don't need to fetch, you need to use one of the many "aaapi_Select..." functions to fill a specific buffer, and then you can examine that buffer.  Then you can use various API functions to modify properties of the Document, but it gets a bit complicated quickly because "words get in the way", meaning you need to understand the various "parts" of a document as not everything a user sees in the GUI of ProjectWise Explorer is in "the document", it somewhere else, but tied to the document by IDs.  

    If you want to modify the file that is attached to a document, then you need to check out the document, which will put a copy of the file into your working directory, but in a controlled manner.  Start by looking at aaApi_CheckOutDocument() and go from there.

    Answer Verified By: Guillaume Charbonnier 

  • Hi Dan,

    Thank you for the code snippet that you shared. I am able to run and execute successfully. I have few queries.

    1. I am able to run the above PW SDK code without using MFC. Is MFC mandatory? Why have you initialized the MFC?
    2. When I look at the functions at the PW SDK document, it doesn’t show me what header file and library I have to include. Please suggest me how I can find out what header and library to include when I include and PW SDK functions and decelerations?

    Thank you.

    Regards,

    Ramnath.

  • 1) No, using MFC is not mandatory.  I used it because I tend to use it my C++ customizations.

    2) Take a look at the SDK help.  It is organized by "modules".  

    You only need to include the one header file that includes all of the other header files for the module.  As for the library file, just change the extension on the noted DLL to LIB.  For this module, you would use DMSCLI.LIB.

    Then for the linker, add in the libraries that you need.  I personally just include all of the ones I have used, or might use because only the ones that are reference will be linked in, and compilers and development machines are so much faster than in the past, that it doesn't add any noticeable performance "hit", at least not that I have noticed!

      

    And then in your source, include the headers that you need.  Again, I tend to include all the ones that I have used, or might use since adding them all doesn't add any noticeable performance penalty, again, that I have noticed!

    Of course, you can just include the ones you use if that makes more sense for your needs.

  • Thank you Dan for the valuable information. Is there any way to add an extension on the server (like Addin/Plugin/Hook that silently sits over the server) to listen or monitor and capture the file transfer between the server and client and vice versa? Is there any hook or event listener at server side PW Design Integration Server?

Reply Children
No Data