AutoCAD P&ID
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Reference to Project Database, DLM, PnPDatabas e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Ok, big problem with the PnPTables. I used txtFeedback on my .NET form for debugging purposes. All PnPTables come back with Rows.Count == 0. What am I doing wrong?
ProjectPartCollection projParts = PlantApplication.CurrentProject.ProjectParts; Project oPrj = projParts["PnId"]; DataLinksManager dlm = oPrj.DataLinksManager; PnPDatabase db = dlm.GetPnPDatabase(); PnPTables tbls = db.Tables; foreach (PnPTable aTbl in tbls) txtFeedback.Text += Environment.NewLine + "Name = " + aTbl.Name + Environment.NewLine + "Rows = " + aTbl.Rows.Count;
I then tried an alternative method:
StringCollection dlmNames = DataLinksManager.GetLinkManagerNames(); DataLinksManager dlm2 = DataLinksManager.GetManager(dlmNames[0]); //ProcessPower.dcf PnPDatabase db2 = dlm2.GetPnPDatabase(); txtFeedback.Text += db2.Name; //CRASH PnPTables tbls = db2.Tables; //CRASH
When I try to access PnPDatabase with this 2nd method, it crashes every time.
I'm running out of options here and I really need this to work. Please help.
Re: Reference to Project Database, DLM, PnPDatabas e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
First method looks correct.

Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.
Re: Reference to Project Database, DLM, PnPDatabas e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Ok, so I finally got it to work. The 1st method I mentioned above does not work as all rows have .Count=0. After lots of searching I finally found something that works:
http://forums.autodesk.com/t5/NET/Accessing-databa
Apparently the rows and any other database items are empty due to a caching issue. To get around the issue, the rows should be obtained using aTbl.Select();
/*
foreach (PnPTable aTbl in tbls)
txtFeedback.Text += Environment.NewLine + "Name = " + aTbl.Name + Environment.NewLine + "Rows = " + aTbl.Rows.Count;
*/ //Does not work (due to caching issue?)
foreach (PnPTable aTbl in tbls)
{
PnPRow[] rows = aTbl.Select();
txtFeedback.Text += Environment.NewLine + "Table = " + aTbl.Name + ", Row count = " + rows.Length.ToString();
} //WorksIs there a line of code I can add to "cache" the tables properly? I know in Microsoft Access, if you do a RecordCount command on a query, on rare occasions it doesn't show everything and the sure fire method is to do a MoveLast command right before RecordCount. Is something similar going on here? These sorts of issues are programming nightmares, when functions don't behave as expected as it can take forever to figure out the problem.
Thanks for your help Jorge.
Re: Reference to Project Database, DLM, PnPDatabas e
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Sorry I didn't catch the missing aTbl.Select() call when I initially responded. Our table objects only keep changed and new rows in memory for scalability reasons. Unmodified rows are fetched on demand from either a local cache or the project database depending on your environment.
The proper way to ensure you have a current list of rows is to always call Select() on a table.

Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.



