.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add Property to .Net Project - PnPDatabaseMode

1 REPLY 1
Reply
Message 1 of 2
dave.wolfe
530 Views, 1 Reply

Add Property to .Net Project - PnPDatabaseMode

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



Tips and Tricks on our blog: ASTI blog
EXPERT ELITE MEMBER
Plant 3D Wish list
1 REPLY 1
Message 2 of 2
fenton.webb
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
AutoCAD Engineering
Autodesk

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost