<?xml encoding=”UTF-8″>By Augusto Goncalves
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.
[<span>CommandMethod</span>(<span>"changeLineGroupData"</span>)]<br><span>public</span> <span>void</span> CmdChangeP3dLineGroupData()<br>{<br> <span>// First, select a Plant 3D pipe</span><br> <span>Editor</span> ed = <span>Application</span>.DocumentManager.MdiActiveDocument.Editor;<br> <span>PromptEntityOptions</span> peo = <span>new</span> <span>PromptEntityOptions</span>(<br> <span>"Select pipe to obtain properties : "</span>);<br> peo.SetRejectMessage(<span>"Only Plant 3D Pipes"</span>);<br> peo.AddAllowedClass(<span>typeof</span>(<span>Pipe</span>), <span>true</span>);<br> <span>PromptEntityResult</span> per = ed.GetEntity(peo);<br> <span>if</span> (per.Status != <span>PromptStatus</span>.OK) <span>return</span>;<br> <br> ObjectId pipeId = per.ObjectId;<br> <br> <span>// Get plant 3D project part</span><br> <span>PlantProject</span> currentProj = <span>PlantApplication</span>.CurrentProject;<br> <span>PipingProject</span> pipeProj = (<span>PipingProject</span>)currentProj.ProjectParts[<span>"Piping"</span>];<br> <span>DataLinksManager</span> dlm = pipeProj.DataLinksManager;<br> <br> <span>// Convert the pipe ObjectId to RowId (used on P3D database</span><br> <span>int</span> rowId = dlm.FindAcPpRowId(pipeId);<br> <br> <span>// Get the P3dLineGroup table of the database</span><br> <span>PnPDatabase</span> db = dlm.GetPnPDatabase();<br> <span>PnPTable</span> tbl = db.Tables[<span>"P3dLineGroup"</span>];<br> <br> <span>// Find the relaship between the pipe RowId</span><br> <span>// This row registry contains the P3dLineGroup</span><br> <span>PnPRowIdArray</span> lineGroupId = dlm.GetRelatedRowIds(<br> <span>"P3dLineGroupPartRelationship"</span>, <span>"Part"</span>, rowId, <span>"LineGroup"</span>);<br> <span>if</span> (lineGroupId == <span>null</span> || lineGroupId.Count == 0) <span>return</span>;<br> <span>int</span> lineGroupRowId = lineGroupId.First.Value;<br> <br> <span>// Now select using this lineGroupRowId</span><br> <span>string</span> sStatement = <span>"PnPID="</span> + lineGroupRowId;<br> <span>PnPRow</span>[] rows = tbl.Select(sStatement);<br> <span>if</span> (rows.Length > 0) <span>// should be just 1</span><br> {<br> <span>foreach</span> (<span>PnPRow</span> Row <span>in</span> rows)<br> {<br> <span>// now do something here...</span><br> }<br> }<br>}


Leave a Reply