AutoCAD P&ID General Discussion

Reply
Active Contributor
jessaskey
Posts: 38
Registered: ‎10-04-2009
Message 1 of 24 (1,094 Views)

Reference to Project Database, DLM, PnPDatabase

1094 Views, 23 Replies
01-02-2012 08:56 PM

Most examples show getting a reference the Database object via

 

Database oDB = AcadApp.DocumentManager.MdiActiveDocument.Database;

 

That seems to get the database for the current drawing only?

 

However, that leads to issues when I want to do tasks across all drawings in a project without wanting to iterate through each drawing.

 

I found a great AU 2007 document published by Jorge and Sasha titled....

 

PD315-1L      Use the power of AutoCAD P&ID and extend its capabilities to suit your needs by writing custom commands, features, and solutions. This class will cover the basics of how P&ID data is stored, related, retrieved, manipulated, and extended by external databases.

 

in which they use the following code to seemingly get a 'project-wide' database reference..

 

Autodesk.ProcessPower.ProjectManager.Project oPrj = Project.CurrentProjectObject;

DataLinksManager oDLMgr = oPrj.DataLinksManager;

Database db = oDLMgr.GetDatabase()

 

Unfortunately the CurrentProjectObject no longer exists in 2012.

 

Then I have seen code that uses this approach too...

 

Database  oDB = HostApplicationServices.WorkingDatabase;

 

Here is sort of where I am now...

 

DataLinksManager dlm = null;

AcadPM.PlantProject currentProject = PlantApplication.CurrentProject;

if (currentProject != null) {  

    AcadPM.Project pnidProject = currentProject.ProjectParts["PnId"];  

    if (pnidProject != null)  {   

        dlm = pnidProject.DataLinksManager;

    }

 

I am wondering what is the best way to get a reference to the entire PnPDatabase, Database and DataLinksManager for the entire project?

 

I have definitely run into problems when I fetch the various Database, DataLinksManager or PnPDatabase via these different methods. Examples include

 

1. If I use the final code I pasted above to get ObjectsId and then DataLinksMangaer.HasLinks(objectId) will sometimes return false;

 

2. DataLinksManager.GetDatabase() can fail with a DLException in some cases.

 

thank you.... please straighten me out.

 

ja

 

Employee
lopezjo
Posts: 102
Registered: ‎07-26-2007
Message 2 of 24 (1,068 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-04-2012 10:44 AM in reply to: jessaskey

That AU2007 document and presentation is a bit dated now. I have a more recent and complete training kit put together by ADN that I can email to you. What you posted is correct and I don't see anything wrong. There is no DLM or PnPDatabase for the entire project but rather a collection of them (one for each project part).

 

A particular drawing may exist in only a single project part so for a given DWG a single DLM and PnPDatabase is used. If DataLinksManager.HasLinks(objectId) is returning false, then either the object is orphaned or it is not a Plant entity assuming of course the DWG of the objectId is part of the project and opened in the drawing editor. If it is orphaned, running AUDIT (for P&ID) or PLANTAUDIT (for P3D) should clean that up. DataLinksManager.GetDatabase() should not be used in a project environment.

 

Hope this helps.

 

Thanks,

Jorge



Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.

Active Contributor
jessaskey
Posts: 38
Registered: ‎10-04-2009
Message 3 of 24 (1,061 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-04-2012 11:33 AM in reply to: lopezjo

Thank you Jorge, that is a helpful explanation.

 

So if I want to open or gather properties on an object thats drawing is NOT open in the drawing editor, am I out of luck?

 

For example... Lets say I want to trace connectivity between two tanks on seperate drawings and for all intent purposes the drawings are drawn correctly with proper off page connectors etc. The project may contain hundreds of drawings but I know that I want to track inline components between TK-001 and TK-683. I don't know exacly which drawings those are on intially and the data I have is TagValues.

 

Do I need to iterate through every single drawing in order to query the ObjectId's of that drawing, just to see if I can find an Asset or Line Segment that has a matching tag?

 

the reason I was using DataLinksManager.GetDatabase() was that given an objectId, I could then get the DBObject outside of the current drawing. But in order to get the DbObject, I need a TransactionManager and in order to get a TransactionManager I need a Database.

 

So, I was using... (this has null checking removed for ease of reading)

DataLinksManager.GetDatabase().TransactionManager.GetObject(objectID) -> DbObject -> Asset.TagValue

 

Since I come from a datababse background, I assumed (perhaps incorrectly) that I could use the underlying .dcf (or SQL) database rather than needing to rely on individual drawings as the portal to the data?

 

thanks... definitely send me any updated docs you can, I appreciate it.

 

 

 

 

Employee
lopezjo
Posts: 102
Registered: ‎07-26-2007
Message 4 of 24 (1,057 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-04-2012 11:54 AM in reply to: jessaskey
  • So if I want to open or gather properties on an object thats drawing is NOT open in the drawing editor, am I out of luck?

No not out of luck. However, you will not have an objectId in that case and the DataLinksManager will need to be bypassed. You can get the the PnPDatabase from the DataLinksManager and work with it directly. If you know the object's PnPID or DWG handle (this requires a bit of work to get the PnPID, see PnPDataLinks table), then you can get the PnPRow for the object via PnPDatabase.GetRow().

 

  • The project may contain hundreds of drawings but I know that I want to track inline components between TK-001 and TK-683

In P&ID, you cannot walk the inline components in order. The topology is not stored in order in the project database. You can get a list of all the components on the line but not in order. To get the objects in order, you will have to use the line objects iterator (or collection in .NET) from the SLINE entity. In Plant 3D, the full topology is stored in the database.

 

  • Do I need to iterate through every single drawing in order to query the ObjectId's of that drawing, just to see if I can find an Asset or Line Segment that has a matching tag?

All tags are in the project database so the ObjectId should not be needed. However as noted above, for P&ID if order is important then the DWG needs to be opened as the project database cannot be used in this case.

 

  • DataLinksManager.GetDatabase().TransactionManager.​GetObject(objectID) -> DbObject -> Asset.TagValue

ObjectId has a Database property.

 



Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.

*Expert Elite*
Dan.M
Posts: 588
Registered: ‎01-19-2009
Message 5 of 24 (1,028 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-09-2012 01:34 PM in reply to: lopezjo

Hello Jorge,

I work at the reseller in Israel and we have a very important PID customer.

We have big  DB issues as ghost records are created in the data manger but they

are not linked to any object in the drawing. We cant delete them.

Do you know this issue? Can you help?

 Thanks,

Dan

Employee
lopezjo
Posts: 102
Registered: ‎07-26-2007
Message 6 of 24 (1,022 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-09-2012 03:24 PM in reply to: Dan.M

Hi Dan,

 

Have you tried right clicking in Project Manager to run Audit? Also, what version of the product is in use?

 

Thanks,

 



Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.

*Expert Elite*
Dan.M
Posts: 588
Registered: ‎01-19-2009
Message 7 of 24 (1,015 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-10-2012 12:14 AM in reply to: lopezjo

Hi,

Thank you for the reply. The customer has PID 2012 and the DB is connected to full sql 2005.

We tryed to audit the project and compress the DB and then Audit.

We also tryed to copy paste the drawing into a new one but still the ghost records are there.

We have found many bugs and all of them are in development field. The problem is we dont know when a solution will be

found if any and the customer is starting to reject the software. We have a workaround in which we delete the records with sql browser but this is dangerous and unsupported.

 

Thanks,

Dan 

Employee
lopezjo
Posts: 102
Registered: ‎07-26-2007
Message 8 of 24 (1,001 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-11-2012 12:35 PM in reply to: Dan.M

Modifying the database directly can cause problems. Machines keep a local cache that will go out of sync.

 

Can you try running PnPLocalDataCachePurger.exe?

 

If ghost entities still persist, is it possible to send me project for analysis?

 

Thanks,

Jorge



Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.

*Expert Elite*
Dan.M
Posts: 588
Registered: ‎01-19-2009
Message 9 of 24 (995 Views)

Re: Reference to Project Database, DLM, PnPDatabase

01-12-2012 12:18 AM in reply to: lopezjo

Hey ,

I have the entire project but it is about 100 Mb zipped. Can I sent it to you to some email?

The customer is running PnPLocalDataCachePurger.exe every morning or ekse Autocad is not

starting up. :smileyhappy:

Alternate way is to take it from Dan Scales Autodesk support. He opend an ftp site for them.

Anyway please dont forward the files outside AD. this stuff is confidential.

 

Thanks,

Dan

Active Member
innowell
Posts: 7
Registered: ‎06-25-2012
Message 10 of 24 (845 Views)

Re: Reference to Project Database, DLM, PnPDatabase

06-25-2012 03:59 PM in reply to: lopezjo

Hello,

 

this training kit would be helpfull for me to!

Can you send it to me?

 

thank you and regards

Daniel

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

New AutoCAD P&ID Category!

The AutoCAD P&ID forum has moved into it's very own category page, and can no longer be found within the Additional Product Forums.

Ask the Community