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.
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:
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.
Dan WilliamsSolution ConsultantBentley Systems, IncorporatedPortland, OR, USA (Pacific Time UTC-08:00)
Thanks for your reply. I would consider the course but realistically that's not going to happen any time soon. We have projectWise setup by another department and they have talked me through basic Admin setup etc so they and I are happy with that side of it.
I can understand the functions and what they do/return etc (mostly) but don't know how to access that in vb.net. Even if I have to write a function to wrap each PW function I want to use in VB.NET then initially I am happy to do that to get going.
Like I said in my example I am using the DLLIMPORT which I have seen used in other posts on these forums. Is the dmsgen.dll the correct one to be referencing in the case to access functions you mentioned etc.
Is this even the right way to go about it?
I am more interested in the AutoCAD to PW interface initially rather than customising PW using the API and would like to avoid C++ if possible.
The functions you are accessing were written in C++ and are not .NET so you will need to marshal the information accross to your .NET app. This is true of C# as well. The term for doing this type of call is P/Invoke or Platform Invoke. There is alot of help on the web for this. I know C# and not VB.NET too well, but I just googled it and there are lots of pages for VB.NET on this topic. There is no simple answer. Many times there are multiple ways to marshal the same data. If you have a specific question during your discovery, please post it here and we can all benifit.