VB.NET AutoCAD using PW API

Hi

I am very new to Bentley products and am trying to use the ProjectWise API within an AutoCAD environment. I have been programming in VB.NET only for AutoCAD and have no experience with C++ and C#. Any C# code I have needed I translated online.

We have PW V8i S3 installed on the company server which our section is piggybacking off. I am trying to do some simple information retieval from the PW database in AutoCAD. Initially I just want to get attribute information for drawing that is currently open.

I have read as much as I can about this but it all seems to not add up to me yet.

I have tried using DLLIMPORT to make the C++ function available to use in VB.NET. Example is here.

    <DllImport("dmsgen.dll", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode, entrypoint:="aaApi_CountAllEnvAttrDefs")> _
    Public Function aaApi_CountAllEnvAttrDefs() As Long
    End Function

This is returning an error. I only used this as I thought I didn't have to pass any information to the function. Is this how I access the functions in general.

Ideally I would like to get a list of the attributes for current drawing and be able to pick the ones I want and retrieve their values.

Any help or code would be greatly appreciated.

Parents
  • al99,

    I would recommend that you consider taking the ProjectWise SDK course, not just because I am one of the instructors but because there's quite a bit of material in the ProjectWise SDK and is a bit difficult just to "jump into it".  First of all, since you are "new to Bentley products", let me recommend that you learn as much about ProjectWise before you attempt to customize it, ideally by taking the ProjectWise User and Administrator courses if you haven’t done so already, as well as some “hands on” time.  Sometimes some built in features and their purposes are not necessarily obvious at first, or not implemented in a particular datasource or system.  Best to not re-invent the wheel of course!

    Now of course, plenty of people learn how to use the PW SDK without taking the course, but it will take you longer to start being productive without it and using a language other than C or C++ makes things a bit more complicated but not impossible.

    As for your particular questions and "issues", accessing and manipulating the user attributes of documents is not really “intuitive” unless you understand what’s going on behind the scenes.  In the current version of the course guide, some time is spent on this so that when looking at the available API functions, it makes a bit more sense why things are done the way they are.

    If your goal is to examine the user attributes for a particular document, you really should first check to see if there is an environment associated with the project (folder/project) that the document is located in.  A folder/project in ProjectWise isn't required to have an environment and even if you “know” that they all do, it is good practice to construct your code to deal with the possibility that a folder might not have an environment.  You can easily get the information that you will need with this call:

    aaApi_GetEnvTableInfoByProject()

    This will return to you the IDs of the environment, table and the column number that you will need (a_attrno) for other functions that you may chose to use.

    You can select all the rows (“sheets”) for your document by a number of ways, but you will probably need to know which columns (user attributes) you are interested in and what their column id are.  You can do that in a number of ways as well of course. 

    You can select the rows for a particular document in a straight forward way with aaApi_SelectLinks() passing the project and document IDs for your document.

    You can then loop through the rows and columns using the information returned by the "links" function and examine them or change them.

    If you plan on manipulating those rows, make sure that you use the APIs provided and not attempt to do it with calls to SQL, particularly if you are attempting to create or delete rows.

    Take a look at some of the samples provided such as DOCPROP, ENVIRONMENT and COPYMOVEDOCATTR.

    In particular, review the functions under “Link Functions” and “Link Data Functions” in the “ProjectWise DMS API” module.  The “link” functions in general tell you about what’s in the dms_link table and the “link data” functions are more about what’s actually in the environment table.

    HTHs

     

Reply
  • al99,

    I would recommend that you consider taking the ProjectWise SDK course, not just because I am one of the instructors but because there's quite a bit of material in the ProjectWise SDK and is a bit difficult just to "jump into it".  First of all, since you are "new to Bentley products", let me recommend that you learn as much about ProjectWise before you attempt to customize it, ideally by taking the ProjectWise User and Administrator courses if you haven’t done so already, as well as some “hands on” time.  Sometimes some built in features and their purposes are not necessarily obvious at first, or not implemented in a particular datasource or system.  Best to not re-invent the wheel of course!

    Now of course, plenty of people learn how to use the PW SDK without taking the course, but it will take you longer to start being productive without it and using a language other than C or C++ makes things a bit more complicated but not impossible.

    As for your particular questions and "issues", accessing and manipulating the user attributes of documents is not really “intuitive” unless you understand what’s going on behind the scenes.  In the current version of the course guide, some time is spent on this so that when looking at the available API functions, it makes a bit more sense why things are done the way they are.

    If your goal is to examine the user attributes for a particular document, you really should first check to see if there is an environment associated with the project (folder/project) that the document is located in.  A folder/project in ProjectWise isn't required to have an environment and even if you “know” that they all do, it is good practice to construct your code to deal with the possibility that a folder might not have an environment.  You can easily get the information that you will need with this call:

    aaApi_GetEnvTableInfoByProject()

    This will return to you the IDs of the environment, table and the column number that you will need (a_attrno) for other functions that you may chose to use.

    You can select all the rows (“sheets”) for your document by a number of ways, but you will probably need to know which columns (user attributes) you are interested in and what their column id are.  You can do that in a number of ways as well of course. 

    You can select the rows for a particular document in a straight forward way with aaApi_SelectLinks() passing the project and document IDs for your document.

    You can then loop through the rows and columns using the information returned by the "links" function and examine them or change them.

    If you plan on manipulating those rows, make sure that you use the APIs provided and not attempt to do it with calls to SQL, particularly if you are attempting to create or delete rows.

    Take a look at some of the samples provided such as DOCPROP, ENVIRONMENT and COPYMOVEDOCATTR.

    In particular, review the functions under “Link Functions” and “Link Data Functions” in the “ProjectWise DMS API” module.  The “link” functions in general tell you about what’s in the dms_link table and the “link data” functions are more about what’s actually in the environment table.

    HTHs

     

Children