You are currently reviewing an older revision of this page.
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.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 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.
PWGetDocumentIDsPWGetDocumentIDs 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 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
| 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, /* i
Reference Item type */
ProjectID, /* i First item
identifier */
DocumentID, /* i Second item
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)
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;
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
IsInitialized
Booleanmember that indicates if the call to PWDocument was successfully initialized
PWErrorNo
An error code number most recently returned by ProjectWise
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, 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.
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.dllCopy the VbaHelper.dll to the ..\Bentley\ProjectWise\bin directoryCreate a blank MicroStation VBA projectImport the GetAttributes.bas, PWattribute_Form.frm, and PWDocuments.bas into the new MicroStation VBA projectSave the project to a directory with a file name of your choiceStart ProjectWise and open a MicroStation design file currently checked out from ProjectWiseStart the MicroStation VBA Project Manager, load and run your project
Client Server Archive
MicroStation Desktop TechNotes and FAQs
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!