AutoCAD P&ID General Discussion

AutoCAD P&ID General Discussion

Reply
Contributor
jbrumbau
Posts: 16
Registered: ‎07-05-2012
Message 21 of 24 (405 Views)

Re: Reference to Project Database, DLM, PnPDatabase

07-06-2012 02:18 PM in reply to: jbrumbau

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.

 

Employee
lopezjo
Posts: 102
Registered: ‎07-26-2007
Message 22 of 24 (402 Views)

Re: Reference to Project Database, DLM, PnPDatabase

07-06-2012 02:36 PM in reply to: jbrumbau

First method looks correct.



Jorge Lopez
Software Architect
Autodesk Plant Solutions
Autodesk, Inc.

Contributor
jbrumbau
Posts: 16
Registered: ‎07-05-2012
Message 23 of 24 (392 Views)

Re: Reference to Project Database, DLM, PnPDatabase

07-09-2012 01:47 PM in reply to: lopezjo

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-database-tables-with-AutoCAD-PNID-2011/td-p/3166198

 

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();
}	//Works

Is 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.

Employee
lopezjo
Posts: 102
Registered: ‎07-26-2007
Message 24 of 24 (314 Views)

Re: Reference to Project Database, DLM, PnPDatabase

11-16-2012 10:16 AM in reply to: jbrumbau

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.

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.