Access P3dLineGroup of a Plant 3D Pipe

<?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.

Plant 3D project setup dialog

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>}

Comments

2 responses to “Access P3dLineGroup of a Plant 3D Pipe”

  1. Pavel Lopata Avatar
    Pavel Lopata

    Hi,
    I’m beginner with programing and I have little problem with my small module.
    I want reade parametr KKS from Support and write this parametr to SteelMember and Plate. I didn’t get over strB. Didn’t read this parametr.
    Sub namePOK()
    Dim strA As String
    Dim strB As String
    Dim objSS As AcadSelectionSet
    Set objSS = ThisDrawing.SelectionSets.Add(Now)
    objSS.SelectOnScreen
    Dim dblTotal As Double
    Dim objSupport As PnP3dCOMLib.AcPnP3dSupport
    Dim objMember As PnP3dCOMLib.AcPnP3dStructureMember
    Dim objPlate As PnP3dCOMLib.AcPnP3dStructurePlate
    For Each objSupport In objSS
    ‘ strA = objSupport.KKS
    strB = objSupport.KKS
    objMember.BQ1 = strB
    objPlate.BQ1 = strB
    Next
    objSS.Update
    objSS.Delete
    End Sub

  2. Can you please tell me how do i get the “visible in object view” check box values which is in the P3dLineGroup UI window?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading