• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    AutoCAD P&ID

    Reply
    Contributor
    Posts: 16
    Registered: ‎07-05-2012

    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.

     

    Please use plain text.
    Employee
    Posts: 100
    Registered: ‎07-26-2007

    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.

    Please use plain text.
    Contributor
    Posts: 16
    Registered: ‎07-05-2012

    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.

    Please use plain text.
    Employee
    Posts: 100
    Registered: ‎07-26-2007

    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.

    Please use plain text.