.NET

.NET

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

Add Property to .Net Project - PnPDatabaseMode

206 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
Plant 3d Wish list: https://plant3d.uservoice.com/
ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 2 (163 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


Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.