AutoCAD P&ID General Discussion

AutoCAD P&ID General Discussion

Reply
Contributor
jbrumbau
Posts: 16
Registered: ‎07-05-2012
Message 1 of 6 (444 Views)

PnPID, rowid, and DataLinksManager.SetProperties function

444 Views, 5 Replies
07-16-2012 02:46 PM

Quick question:

How do you get <int rowid> from <int PnPId>?

 

Basically, I want to update field values for specified PnPId's but I don't know if this is right:

PlantProject proj = PlantApplication.CurrentProject;
ProjectPartCollection projParts = proj.ProjectParts;
PnIdProject pnidProj = (PnIdProject)projParts["PnId"];
DataLinksManager dlm = pnidProj.DataLinksManager;
PnPDatabase db = dlm.GetPnPDatabase();
int pnpid; //From gray PnPID column in Data Manager

StringCollection pvals = new StringCollection();
StringCollection pnames = new StringCollection();

//...After code that populates pnpid, pvals, and pnames...//
db.StartTransaction();
dlm.SetProperties(pnpid, pnames, pvals); //Function parameters are (int rowid, StringCollection pnames, StringCollection pvals)
db.CommitTransaction();

 If PnPID is not the same as rowid, then how would I get it knowing the PnPID?

Also, how would I check if a specific PnPID doesn't exist (i.e. deleted)?

 

Thanks.

Contributor
jbrumbau
Posts: 16
Registered: ‎07-05-2012
Message 2 of 6 (405 Views)

Re: PnPID, rowid, and DataLinksManager.SetProperties function

08-02-2012 11:30 AM in reply to: jbrumbau

After formally testing this code it was only partially working. Though changes would be set, they would be forgotten after closing the module. Here are the additional calls I had to include:

//Code to populate StringCollection pnames (field names) inserted here
try
{
	db.BeginEdits();
	while (wsReader.Read()) //Excel worksheet OleDBConnection
	{
		//Code to populate StringCollection pvals (field values) inserted here
		try
		{
			pnpid = Convert.ToInt32(wsReader.GetDouble(pnpidCol[i]));
			if (pnpid > 0)
			{
				db.StartTransaction();
				dlm.SetProperties(pnpid, pnames, pvals);
				db.CommitTransaction();
			}
		}
		catch (System.Exception ex)
		{
			//Handle error
		}
	}
	dlm.AcceptChanges();
	db.AcceptChanges();
	db.EndEdits();
}
catch (System.Exception ex)
{
	try
	{
		dlm.RejectChanges();
		db.RejectChanges();
		db.CancelEdits();
	}
	catch
	{
	}
}

 Then in the destructor, I had to add the following code:

if (db != null)
{
	db.Close();
	db.Dispose();
}
if (dlm != null)
{
	dlm.Close();
	dlm.Dispose();
}
if (pnidProj != null)
	pnidProj.Close();
if (projParts != null)
	projParts.Clear();

I also ended up using an error handler to skip PnPIDs that were not in the database. The only thing is that it is incredibly slow when executing this code. It took 31 seconds to read 97 rows! This means that to read 10,000 rows (a full scale project with multiple P&IDs), it would take an entire hour. Is there a way to speed this up? I tried putting db.StartTransaction() before the loop and db.CommitTransation() after the loop but it only trimmed 4 seconds off of the original 31 seconds. Or should I approach this problem differently?

 

Thanks to whoever responds, and I hope this helps somebody out.

*Expert Elite*
Rave.Tam
Posts: 204
Registered: ‎05-19-2011
Message 3 of 6 (398 Views)

Re: PnPID, rowid, and DataLinksManager.SetProperties function

08-02-2012 09:42 PM in reply to: jbrumbau

The only thing that takes the most time is setting the properties. 

 

dlm.SetProperties(pnpid, pnames, pvals);

If my post answers your question, please click the "Accept as Solution" button.

Check out my blog http://lazcad.com
Contributor
jbrumbau
Posts: 16
Registered: ‎07-05-2012
Message 4 of 6 (392 Views)

Re: PnPID, rowid, and DataLinksManager.SetProperties function

08-03-2012 07:58 AM in reply to: Rave.Tam

Hello Rave.Tam,

 

Thanks for identifying the bottleneck. Is there an alternative function that assigns values based on column integer index values, or one that can apply values to more than 1 rowid/pnpid at once? Or is this essentially the best I can do?

 

Thank you,

Jesse.

*Expert Elite*
Rave.Tam
Posts: 204
Registered: ‎05-19-2011
Message 5 of 6 (363 Views)

Re: PnPID, rowid, and DataLinksManager.SetProperties function

08-06-2012 09:58 PM in reply to: jbrumbau

Maybe you can try to compare the value first (using getproperties) before setproperties. And do a benchmark and see if it's faster.

If my post answers your question, please click the "Accept as Solution" button.

Check out my blog http://lazcad.com
Contributor
jbrumbau
Posts: 16
Registered: ‎07-05-2012
Message 6 of 6 (357 Views)

Re: PnPID, rowid, and DataLinksManager.SetProperties function

08-07-2012 07:29 AM in reply to: Rave.Tam

I have made it to where my export changes to excel function only exports records that were modified since the last data import. So, this will help alleviate some of the issues. I was just wondering if you knew of any method that was faster for updating entries in the Process Power database.

 

Thanks.

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.