private static int createUnassignedLineGroup(PipingProject prjpart) { // Create a new line group in project database DataLinksManager dlm = prjpart.DataLinksManager; PnPDatabase db = dlm.GetPnPDatabase(); PnPTable tbl = db.Tables["P3dLineGroup"]; PnPRow row = tbl.NewRow(); tbl.Rows.Add(row); return(row.RowId); }
// 6.8 Create a private void function named getData. // have it take two string parameters. Name one of the // parameters dcfFileName and the other tableName // Note: Put the closing curly brace after step 6.19 private void getData(string dcfFileName, string tableName) { // 6.9 Call the Clear method of the Items // property of the ListBox on the form. (listBox1) listBox1.Items.Clear(); // 6.10 Use the Add method of the Items collection // of the ListBox. (listBox1). to add the string // passed into the function. (tableName) Use a string // similar to this: "Table Name: " + listBox1.Items.Add("Table Name: " + tableName); // 6.11 Declare a variable as a PnPDatabase. Instantiate // it using the Open method of PnPDatabase. Pass in // the dcfFileName string passed into this function. PnPDatabase db = PnPDatabase.Open(dcfFileName); // 6.12 Declare a variable as a PnPTable instantiate it // using the Tables collection of the PnPDatabase from step 6.11 // Pass in the tableName string that was passed into this // function. PnPTable tbl = db.Tables[tableName]; // 6.13 Declare an array of PnPRow. ( PnPRow[]) Name it // rows and make it equal to the Select method of the // PnPTable from step 6.12 PnPRow[] rows = tbl.Select(); // 6.14 use a foreach and iterate through each PnPRow // in the PnPRow array from step 6.13 // Note: Put the closing curly brace after step 6.19 foreach (PnPRow row in rows) { // 6.15. Use another foreach and iterate throuh each PnPColumn // of the PnPRow from the foreach in step 6.14). // (use the Table.Columns collection) // Note: Put the closing curly brace after step 6.17 foreach (PnPColumn col in row.Table.Columns) { // 6.16 Use the Add method of the Items collection // of the ListBox. (listBox1) to add the Name property // of the PnPColumn in the foreach loop. (step 6.15) listBox1.Items.Add("Column Name = " + col.Name); // 6.17 Use the Add method of the Items collection // of the ListBox. (listBox1) to add the text from the row // in this column. Use the row from the foreach in step 6.14 // Use square brackets (row[]) and the Name property of the PnPColumn // from the foreach in step 6.15. (string for the Column) // Use a string similar to this: "Row Value in this column = " + listBox1.Items.Add("Row Value in this column = " + row[col.Name]); } // 6.18 Use the Add method of the Items collection // of the ListBox. (listBox1) to add the an empty string // this will put a blank line between the rows listBox1.Items.Add(" "); // 6.19 Use the Add method of the Items collection // of the ListBox. (listBox1) to add the a string "NEXT ROW" // This will make the text in the list box easier to read listBox1.Items.Add("NEXT ROW "); } }
public void AddProperties() { //file name to save different data string filePath = @"C: \Users\LinP3\source\repos\Plant3DApiTester\Resource\plant_3d_AddProperties.txt"; ///all available drawing type string DwgType_Piping = "Piping"; string DwgType_PnId = "PnId"; //get current drawing Document doc = AcadApp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; ///create a clean file, prepare to write File.WriteAllText(filePath, $"{doc.Name}\n"); //get current project PlantProject mainPrj = PlantApplication.CurrentProject; Project pipingPrj = mainPrj.ProjectParts[DwgType_Piping]; DataLinksManager dlm = pipingPrj.DataLinksManager; //get current drawing type string dwgtype = PnPProjectUtils.GetActiveDocumentType(); if (dwgtype != DwgType_PnId && dwgtype != DwgType_Piping) { //"PnId", "Piping", "Ortho", "Iso" ed.WriteMessage("This drawing is not a P&ID or 3D Model in the current project.\n"); return; } PnPDatabase pDB = dlm.GetPnPDatabase(); PnPTable pTable = pDB.Tables["EngineeringItems"]; string colName = "Api_added_Property1"; bool isInTable = false; if (pTable != null) { ///list all columns in table PnPColumns columns = pTable.AllColumns; foreach (PnPColumn col in columns) { File.AppendAllText(filePath, col.Name + Environment.NewLine); if (colName == col.Name) { isInTable = true; } } ///add new column try { if (isInTable == false) { PnPColumn newCol = new PnPColumn(colName, typeof(string), 256); newCol.DefaultValue = "api default value"; pTable.Columns.Add(newCol); } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage(ex.ToString()); } } }