This question came from Jens Dorstewitz: how access the P3dLineGroup of a given Plant 3D pipe? To clarify, below is the project properties with the table we’re looking for.
To answer we have a problem: this information is not part of the properties of the pipe, but in fact stored somewhere else. So we need to understand the relationships of Plant 3D database.
There are a few steps: (1) from a Pipe ObjectId, use the Data Links Manager to get the RowId and (2) using the Plant 3D database, open and search at the P3dLineGroupPartRelationship table for a row where Part equals this RowId. With this row, (3) get the LineGroup column that will be the RowId of the line group we need. Finally (4) open the P3dLineGroup table and get the row we need. This row can be edited.
Actually Jens Dorstewitz (thanks again) wrote a sample based on this idea, below is an simplified version of it. Enjoy.
[CommandMethod("changeLineGroupData")]
public void CmdChangeP3dLineGroupData()
{
// First, select a Plant 3D pipe
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions peo = new PromptEntityOptions(
"Select pipe to obtain properties : ");
peo.SetRejectMessage("Only Plant 3D Pipes");
peo.AddAllowedClass(typeof(Pipe), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK) return;
ObjectId pipeId = per.ObjectId;
// Get plant 3D project part
PlantProject currentProj = PlantApplication.CurrentProject;
PipingProject pipeProj = (PipingProject)currentProj.ProjectParts["Piping"];
DataLinksManager dlm = pipeProj.DataLinksManager;
// Convert the pipe ObjectId to RowId (used on P3D database
int rowId = dlm.FindAcPpRowId(pipeId);
// Get the P3dLineGroup table of the database
PnPDatabase db = dlm.GetPnPDatabase();
PnPTable tbl = db.Tables["P3dLineGroup"];
// Find the relaship between the pipe RowId
// This row registry contains the P3dLineGroup
PnPRowIdArray lineGroupId = dlm.GetRelatedRowIds(
"P3dLineGroupPartRelationship", "Part", rowId, "LineGroup");
if (lineGroupId == null || lineGroupId.Count == 0) return;
int lineGroupRowId = lineGroupId.First.Value;
// Now select using this lineGroupRowId
string sStatement = "PnPID=" + lineGroupRowId;
PnPRow[] rows = tbl.Select(sStatement);
if (rows.Length > 0) // should be just 1
{
foreach (PnPRow Row in rows)
{
// now do something here...
}
}
}