Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
MicroStation
  • Product Communities
  • More
MicroStation
MicroStation Wiki A MicroStation VBA Example With Bentley ProjectWise
    • Sign in

    • +MicroStation Wiki
    • +Administration Wiki
    • +Annotations Wiki
    • +Bentley View Wiki
    • +MicroStation PowerDraft
    • -Programming Wiki
      • A class to help create and modify text element
      • A Complete Example
      • A MicroStation VBA Example With Bentley ProjectWise
      • AddIn Development Using VB.NET
      • C# .NET Template with IPrimitiveCommandEvents Class
      • Capturing Graphics in Dynamic Views
      • Compiling MDL Applications
      • Database Manipulation
      • Debugging Native Code MDL Applications
      • Developing Code in VBA
      • Developing MicroStation Applications For DWG Files
      • Drag and Drop in MicroStation
      • Error: "Cannot save changes to VBA project 'Support' because it is read-only"
      • Getting And Setting Elements Using Graphic Groups In VBA [CS]
      • Getting Started with Visual Basic
      • How To Write A Recursive Routine In MicroStation VBA [CS]
      • Introducing Segment3D Methods In MicroStation V8 2004 Edition
      • Known issues in MDL and MicroStationAPI
      • Launching VBA Applications As Initapps Or Dgnapps [CS]
      • Learning MicroStation Addins Step by Step
      • MDL - Getting Started With XAttributes In MicroStation V8 XM Edition
      • MDL - Native Code Application Development
      • MDL Or MicroStation BASIC Choosing The Right Tool [TN]
      • MFC Dialog And Native Window Support
      • Microsoft Office VBA Patch Utility
      • MicroStation BASIC FAQ
      • MicroStation BASIC Limits [FAQ]
      • MicroStation Developer Documentation and Example Code
      • MicroStation Programming Advice
      • MicroStation SDK
      • MicroStation V8 Programming Tools Readme
      • MicroStation V8 VBA Programming Resources [CS]
      • MicroStation V8 XM Edition View Code Updates
      • MicroStation VBA Resources Revisited [CS]
      • Migrating Dimension Code To MicroStation V8
      • Migrating MDL Applications To Native Code
      • Mouse Wheel Events And The Visual Basic 6.0 IDE
      • Porting MDL Applications To MicroStation V8
      • Reading Elements From A Microsoft Access Database With VBA [CS]
      • Running MDL Applications
      • Scanning For MicroStation V8 Elements In VBA [CS]
      • Unleash A Workspace Wizard Automating Workspace Creation With MicroStation V8 And VBA [CS]
      • Using VBA To Detect The Current Or Last Used Command
      • Using VBA To Programmatically Export A VBA Project [CS]
      • Using VBA To Programmatically Import A VBA Projects Components And References [CS]
      • VBA -- Creating A Complex Application
      • VBA Interface Error: failed creating the comp manager - 0x80040583
      • VBA interface error: unable to get IDE
      • vba recording
      • Working With Levels In MicroStation VBA [CS]
      • Writing An MDL Application To Output Custom Placemarks To Google Earth
      • [V8i C++] PointCloud IPointCloudChannelDisplayHandler
    • +Visualization Wiki

     
     Questions about this article, topic, or product? Click here. 

    A MicroStation VBA Example With Bentley ProjectWise

     

    This Client Server article is republished in its entirety from 2003 for reference purposes.

    By Michael Dougherty, Jr., Senior Analyst, Bentley Developer Support, Bentley Corporate Office
    26 May 2003 Modified: 09 November 2005

    May 26, 2003 -Bentley ProjectWise is the AEC content management solution for the engineering office. Users can consolidate decentralized engineering content into a single presentation to ensure that all project team members have access to the right data when they need it. ProjectWise is designed to handle MicroStation DGN and AutoCAD DWG files, as well as other business file formats.

    PW_Attributes

    PW_Attributes.mvba is a Microstation Visual Basic for Applications (VBA) programming example that utilizes a custom ProjectWise SDK dll called VbaHelper.dll. This example illustrates how to call into a custom ProjectWise dll, and extract and display the current document attributes information to the user. (An attribute is an identifying or descriptive property of a document.) Each ProjectWise document may have zero, one or more rows of attributes.

    Click here to Download the example.

    The ProjectWise SDK

    The ProjectWise SDK is a complete set of C-style API (Application Programming Interface) client side libraries, documentation, and examples. It currently does not have a VB style API. However, just like any other limitation in VB/VBA, this can be overcome by calling functions exposed in a dll.

     

    VbaHelper.dll

    The VbaHelper.dll is the bridge used in this example to access the ProjectWise database management system (DMS). This example exports functions that allow interaction between ProjectWise and a MicroStation VBA example project, PW_Attributes.mvba.

    PWGetDocumentIDs
    PWGetDocumentIDs is one of the exposed functions in the VbaHelper.dll that will be used in the PW_Attributes.mvba. This function will return the document ID and project ID of the MicroStation design file that is currently open. The code has a check-in place to determine whether the current design file is checked out by the current user.

    Looking at the code, notice that the function populates the ProjectID and DocumentID by calling the mcmMain_GetDocumentIdByFilePath() ProjectWise API library. This function is used to find the document and project ID by specifying its full document path.

    /*----------------------------------------------------------------------+
    |
    | name PWGetDocumentIDs
    |
    | author BSI 04/2003
    |
    | Description A function that will return the documents
    | Project and Document ID.
    |
    | Return SUCCESS or error number
    |
    +----------------------------------------------------------------------*/
    
    LONG WINAPI PWGetDocumentIDs
    (
    TCHAR **fileName, /* i Design File Name */
    LONG *ProjectID, /* o Project ID */
    LONG *DocumentID /* o Document ID */
    )
    
    {
    return mcmMain_GetDocumentIdByFilePath (*fileName, ProjectID, DocumentID);
    }
    

    PWGetDocumentAttributes

    PWGetDocumentAttributes is another function that we expose in the VbaHelper.dll. This function, when given a document ID and a project ID, will extract the document attributes and populate the provided AttributeData variable with that attribute information specific to that document. This function utilizes a query that populates the ProjectWise global static buffer. The ProjectWise API offers a flexible mechanism for performing select-style queries against a datasource. Each datasource has its own temporary region (global buffer) where the results from queries are stored. Fields (properties) of selected rows (information records) can then be accessed using a corresponding data retrieval function. If a new select statement into a static buffer is performed, previous contents of that static data buffer are destroyed.

     

    /*----------------------------------------------------------------------+
    |
    | name PWGetDocumentAttributes
    |
    | author BSI 04/2003
    |
    | Description A function that will return the documents attributes.
    |
    | Return SUCCESS or -1 if error.
    |
    +----------------------------------------------------------------------*/
    LONG WINAPI PWGetDocumentAttributes
    (
    LONG ProjectID, /* i Project ID */
    LONG DocumentID, /* i Document ID */
    void **AttributeData /* o Document attributes */
    )
    
    {
    CString message;
    LONG status = SUCCESS;
    LONG lEnvId = aaApi_GetEnvId (0);
    LONG lTabNo = aaApi_GetEnvNumericProperty (ENV_PROP_TABLEID, 0);
    LONG count = -1;
    int rowCount = -1;
    
    /* Select environment for given project */
    status = aaApi_SelectEnvByProjectId (ProjectID);
    
    if (status == -1 || status == 0)
    {
    return -1;
    }
    else
    {
    // Select the documents Attribute Data
    rowCount = aaApi_SelectLinkDataByObject (
    lTabNo, /* i Table identifier (required) */
    AADMSLDT_DOCUMENT, /* iReference Item type */
    ProjectID, /* i First item identifier */
    DocumentID, /* i Second item identifier */
    NULL, /* i Where statement (optional) */
    &count, /* io Column count in lplColumnIds */
    NULL, /* i Columns to fetch (NULL - all) */
    0 /* i Flags (AADMSLDSF_XXX) */
    );
    
    if (rowCount <= 0)
    return -1;
    
    for (int colIndex= 0; colIndex
    {
    message += aaApi_GetLinkDataColumnStringProperty (LINKDATA_PROP_COLUMN_NAME, colIndex);
    message += ": ";
    message += aaApi_GetLinkDataColumnValue (0, colIndex);
    message +="\n";
    }// end for
    
    _tcscpy ((TCHAR*)(*AttributeData), message);
    }
    return SUCCESS;
    }

     

    Looking at the MicroStation VBA Code

    PWDocuments

    PW_Attributes.mvba is made up of two modules and a form. The first module, PWDocuments, wraps around the VbaHelper.dll by simplifying and effectively hiding the implementation. This module has private functions and members that should only be manipulated through the public member function calls. Below is a list of the public functions and members available currently in the module.

     

    Function

    Description

    Initialize

    Initializes the PWDocument module

    GetDocumentID

    Extracts a document's document ID from ProjectWise

    GetProjectID

    Extracts the project ID for the document checked out of ProjectWise

    GetAttributes

    Extracts the current documents attributes from ProjectWise

    GetDocumentName

    Returns the name of a document

     

    Public Members

    Description

    IsInitialized

    Booleanmember that indicates if the call to PWDocument was successfully initialized

    PWErrorNo

    An error code number most recently returned by ProjectWise

    PWErrorDescription

    A description of the most recently returned error code by ProjectWise

     

    Note that each function will return a status. If the status does not equal SUCCESS then the application should take the appropriate action and alert the user with information contained in the PWErrorNo and PWErrorDescription.

    GetAttributes

    GetAttributes, located in the Main subroutine, is the starting point of the PW_Attributes example. If the current document is one that is checked out from the ProjectWise database by the user the main module will proceed to open the PWAttribute_Form. The form is then populated with the document's attribute data by the functionality provided in the PWDocuments module.

    Running the Example

    Note: To run this example you will need to ensure that you have installed the ProjectWise SDK and Microsoft Visual C++, or Developer Studio to compile an executable dll.

    Open the VbaHelper.dsw workspace and compile the VbaHelper.dll
    Copy the VbaHelper.dll to the ..\Bentley\ProjectWise\bin directory
    Create a blank MicroStation VBA project
    Import the GetAttributes.bas, PWattribute_Form.frm, and PWDocuments.bas into the new MicroStation VBA project
    Save the project to a directory with a file name of your choice
    Start ProjectWise and open a MicroStation design file currently checked out from ProjectWise
    Start the MicroStation VBA Project Manager, load and run your project

    See Also

    Using The ProjectWise API In VBA

    Client Server Archive

    MicroStation Desktop TechNotes and FAQs

    Comments or Corrections?

    Bentley's Technical Support Group requests that you please confine any comments you have on this Wiki entry to this "Comments or Corrections?" section. THANK YOU!

     

    • Archived Client Server
    • client server
    • client server 2003
    • Share
    • History
    • More
    • Cancel
    • Elisa McGraw Created by Elisa McGraw
    • When: Wed, Jul 15 2009 2:21 PM
    • Robert Hook Last revision by Bentley Colleague Robert Hook
    • When: Thu, Dec 8 2016 11:17 AM
    • Revisions: 22
    • Comments: 1
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2022 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies