Inside Plant P&ID we can Validate, via ribbon Home>Validate>Run Validation or right-click on a drawing and select “Validate”. More details here.
Using APIs there is a ValidationSingleton object that has a ValidateDrawings or ValidareProject method. After run this, the Errors property will contain a list of validation errors. Actually there is one class for each type, so you’ll need to cast or, like in the sample below, simply get the error name.
Important: this API method will *only* show the validation errors after you run it via built-in command.
[CommandMethod("validateDrawings")]
public static void CmdValidateDrawings()
{
Editor ed = Application.DocumentManager.
MdiActiveDocument.Editor;
// Validation manager
AcPpValidationManager vmgr = ValidationSingleton.Manager;
// prepare a list of drawings
AcPpValidationAllOpenedDrawingManager dsd =
new AcPpValidationAllOpenedDrawingManager();
foreach (Document doc in Application.DocumentManager)
{
dsd.Add(doc.Database);
}
// clear the list of error
// (in case you're running several times)
vmgr.Errors.Clear();
// the actual validation occurs here
vmgr.ValidateProject(dsd);
// now check the list of errors
if (vmgr.Errors.Count > 0)
{
AcPpValidationErrorCollection errorList = vmgr.Errors;
foreach (IAcPpValidationError item1 in errorList)
{
// can be classes from namespace
// Autodesk.ProcessPower.PnIDDwgValidation
// for now, let's write the error class name
ed.WriteMessage("\n{0}",
item1.GetType().Name.PascalCaseToText());
}
}
}
// nice sample Regular expression from here.
public static string PascalCaseToText(this string text)
{
return System.Text.RegularExpressions.Regex.Replace(
text, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ");
}