Track value change on Plant 3D Database

<?xml encoding=”UTF-8″>By Augusto Goncalves

On AutoCAD entities we cannot track changes, although we can simulate some sort of tracking mechanism, see this blog post. So if you need to track geometric properties, like position, you’ll probably need something as described.

Now on Plant 3D there is a actual database storing information: the PnPDatabase, which includes a list of tables (PnPTable), that represent the classes. And there are some interesting events, such as ColumnChanged event.

Below is a sample that uses this event to track changes on database values (in this case, the Manufacturer) of EngineeringItems.

[<span>CommandMethod</span>(<span>"trackTableChanges"</span>)]<br><span>public</span> <span>static</span> <span>void</span> CmdTrackChanges()<br>{<br>  TrackDBTableChanges(<br>    <span>"EngineeringItems"</span>,<br>    <span>new</span> <span>string</span>[] { <span>"Manufacturer"</span> });<br>}<br> <br><span>private</span> <span>static</span> <span>void</span> TrackDBTableChanges(<br>  <span>string</span> tableName, <span>string</span>[] columns)<br>{<br>  <span>PlantProject</span> currentProj =<br>    <span>PlantApplication</span>.CurrentProject;<br>  <span>PipingProject</span> pipeProj =<br>    (<span>PipingProject</span>)currentProj.ProjectParts[<span>"Piping"</span>];<br>  <span>DataLinksManager</span> dlm = pipeProj.DataLinksManager;<br>  <span>PnPDatabase</span> db = dlm.GetPnPDatabase();<br> <br>  <span>// the table we want to track</span><br>  <span>PnPTable</span> engItemsTable = db.Tables[tableName];<br> <br>  <span>// just the columns we want to track</span><br>  _collunsToTrack = <span>new</span> <span>List</span><<span>string</span>>(columns);<br> <br>  <span>// start tracking</span><br>  engItemsTable.ColumnChanged +=<br>    engItemsTable_ColumnChanged;<br>}<br> <br><span>private</span> <span>static</span> <span>List</span><<span>string</span>> _collunsToTrack = <span>null</span>;<br> <br><span>static</span> <span>void</span> engItemsTable_ColumnChanged<br>  (<span>object</span> sender, <span>PnPColumnChangeEventArgs</span> e)<br>{<br>  <span>// filter by column name</span><br>  <span>if</span> (!(_collunsToTrack.Contains(e.Column.Name))) <span>return</span>;<br> <br>  <span>// simple output</span><br>  <span>Application</span>.DocumentManager.MdiActiveDocument.<br>    Editor.WriteMessage(<br>    <span>"{0} of item {1} changed from {2} to {3}"</span>,<br>    e.Column.Name, e.Row.RowId,<br>    e.CurrentValue, e.ProposedValue);<br>}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading