.NET

.NET

Reply
*Expert Elite*
dave.wolfe
Posts: 676
Registered: ‎12-04-2009
Message 1 of 2 (197 Views)

Add Property to .Net Project - PnPDatabaseMode

197 Views, 1 Replies
08-30-2012 01:59 PM

I'm using the following code to add a property to a table.

 

var prj = PlantApplication.CurrentProject.ProjectParts["Piping"];
                PnPDatabaseMode prevMode = prj.Mode;
                prj.Mode = PnPDatabaseMode.Exclusive;
                using (PnPDatabase db = PnPDatabase.Open(prj.DataCacheFile))
                {
                    PnPTable enginitems = db.Tables["EngineeringItems"];
                    if (enginitems.Columns.Contains(projectcolum))
                        return;
                    PnPColumn col = new PnPColumn(projectcolum, typeof(string), PnPDatabase.DefaultStringValueLength);
                    enginitems.Columns.Add(col);
                    db.AcceptChanges();
                }
                prj.Mode = prevMode;

However, I get an error in the Datalinksmanager when I try to set the PnPDatabaseMode to Exclusive.  Any ideas?

 

The PnPDatabaseMode was shared, but the error says it's already opened exclusive.

Dave Wolfe
Isaiah 57:15

ECAD, Inc.
Tips and Tricks on our blog: Process Design, from the Outside

A P3D Authorized Reseller
ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 2 (154 Views)

Re: Add Property to .Net Project - PnPDatabaseMode

09-05-2012 01:03 PM in reply to: dave.wolfe

The database is already opened in the project so trying to go exclusive on another instance of PnPDatabase will always fail.

 

Try changing the code to this:

 

        [CommandMethod("PNPADDCOL", CommandFlags.Modal)]

        public static void PnPAddCol()

        {

            var prj = PlantApplication.CurrentProject.ProjectParts["Piping"];

            PnPDatabaseMode prevMode = prj.Mode;

            prj.Mode = PnPDatabaseMode.Exclusive;

 

// commented out wrong code

 

            var db = prj.DataLinksManager.GetPnPDatabase();

 

 

            //using (PnPDatabase db = PnPDatabase.Open(prj.DataCacheFile))

            //{

                PnPTable enginitems = db.Tables["EngineeringItems"];

                if (enginitems.Columns.Contains("TestNewCol"))

                    return;

                PnPColumn col = new PnPColumn("TestNewCol", typeof(string), PnPDatabase.DefaultStringValueLength);

                enginitems.Columns.Add(col);

                db.AcceptChanges();

            //}

 

            prj.Mode = prevMode;

        }





Fenton Webb

Developer Technical Services

Autodesk Developer Network


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 or visit the Installation and Licensing Forum to get help installing your software.