Where do the PnPTagFormat definitions get stored?

Where do the PnPTagFormat definitions get stored?

louwill
Enthusiast Enthusiast
1,017 Views
4 Replies
Message 1 of 5

Where do the PnPTagFormat definitions get stored?

louwill
Enthusiast
Enthusiast

Within my project, I have a custom tag format defined for the P&ID HandValve table.  Where do these format definitions get stored?  Are they in the P&ID database?  Project config file?  I can't seem to find this information anywhere.  Programmatically, how can I retrieve the individual subparts that make up a tag format definition?  

 

2019-01-24 10_26_25-Tag Format Setup.png

0 Likes
1,018 Views
4 Replies
Replies (4)
Message 2 of 5

jabowabo
Mentor
Mentor

EDIT: Below is how to get the formats for Plant 3D, I'm not sure about P&ID.

----------------------------------------------------------------------------------------

You can retrieve the tag formats with:

Autodesk.ProcessPower.PnP3dTagUtil.PnP3dTagFormat.getTagFormatString(int <rowId>)

or

Autodesk.ProcessPower.PnP3dTagUtil.PnP3dTagFormat.getTagFormatString(string <className>)

 

Message 3 of 5

louwill
Enthusiast
Enthusiast

Jason, thanks for the reply.  However, that method appears to be only looking at Plant 3D classes; I need the P&ID equivalent.  I found Autodesk.ProcessPower.TagFormats, but haven't figured out how it's used yet (or if that's even the correct class).  Any additional help would be greatly appreciated.

 

Will

0 Likes
Message 4 of 5

jabowabo
Mentor
Mentor

Our PnID app is home-brewed so I don't delve into that side of it much. This looks promising but I haven't tested:

Autodesk.ProcessPower.ProjectManager.PnIdProject.GetTagFormats(string, bool)

public override System.Collections.Specialized.StringCollection GetTagFormats(string strClassName, bool bIncludeInherited)
Member of Autodesk.ProcessPower.ProjectManager.PnIdProject

0 Likes
Message 5 of 5

louwill
Enthusiast
Enthusiast

@jabowabo wrote:

Our PnID app is home-brewed so I don't delve into that side of it much. This looks promising but I haven't tested:

Autodesk.ProcessPower.ProjectManager.PnIdProject.GetTagFormats(string, bool)

public override System.Collections.Specialized.StringCollection GetTagFormats(string strClassName, bool bIncludeInherited)
Member of Autodesk.ProcessPower.ProjectManager.PnIdProject


Jason,

 

Thank you.  I was able to get it working.  In the end it required disassembling PnPProjectManagerMgd.dll, but you pointed me in the right direction.

 

For future reference, here's how anyone can retrieve the tag format for a given P&ID class and build a new tag based on an updated tag format.  Note the loop doesn't limit to a single or set of P&ID drawings, but this could be done easily by looking at the data links for a given drawing.

 

// get pnid project
var pnidProject = PlantApplication.CurrentProject.ProjectParts.FirstOrDefault(p => p is PnIdProject) as PnIdProject;
if (pnidProject == null)
    return;

// get pnid database
var pnpDatabase = pnidProject.DataLinksManager.GetPnPDatabase();

// get tag format name
var tagFormatName = pnpDatabase.Tables["HandValves"].GetTableAttributeValue("TagFormatName");

// get tag format (value = format definition defined in the class definition via project settings)
var tagFormat = pnidProject.GetTagFormat(tagFormatName, out var value, out var baseClass);

// get formattoolsutil instance (used to rebuild tags if desired)
var formatToolsUtil = new FormatToolsUtil();

// loop through hand valves
var pnpHandValves = pnpDatabase.Tables["HandValves"].Select().ToList();
foreach (var pnpHandValve in pnpHand)
{
    // get old tag
    var oldTag = pnpHandValve["Tag"];

    // get new tag
    var newTag = formatToolsUtil.RebuildTagValue(value, "", pnpHandValve.RowId, pnidProject.DataLinksManager);
}