In this step, you will use the Label Template Editor to add VB script code to the new label template, REFERENCE_ID_COLOR.LBL, to set the background color based on the dimension color.
Select File | Reporting | Edit | Label Template, and open REFERENCE_ID_COLOR.LBL. The label opens. It contains a GridControlObject with one row and one column. If you double-click on the cell, you will see an expression inside which reads:
=REF_ID:1
This means the label will display the ID of the reference feature.
Right-click on the editor to display the Properties dialog box.
Select GridControlObject1 from the list of objects.
In the Properties dialog box, expand Events.
Click [None] to the right of the EventReportData property. The VBS Mini-Editor appears. You may need to expand the VBS Mini Editor to be wider so that you can see the entire Sub statement toward the top.
You can see that the ReportData object is passed in. This is where PC-DMIS extracts information about passed in dimensions. For additional information on the ReportData object, see the "ReportData Object" topic in the PC-DMIS 2023.1 Object Library documentation. Also, if you need to reference the GridControlObject, you can use "This" as a shortcut to the object.
Insert this code into the VBS Mini-Editor:
Dim I As Integer Dim MaxIndex As Integer Dim MaxDev As Double Dim CurrentDev As Variant Dim Dev As Variant Dim PTol As Variant Dim MTol As Variant Dim iReturn As Boolean ' Initialize Max deviation and Max Index MaxDev = 0.0 MaxIndex = 1 ' Get the number of axes for this dimension ' 132 is the Dtype AXIS Count = ReportData.GetCount(132) ' Loop through to find the largest deviation ' When the loop is complete, MaxIndex is the index to the ' largest deviation For I = 1 to Count ' 340 is the Dtype DIM_DEVIATION CurrentDev = ABS(ReportData.GetValue(340, I)) If CurrentDev > MaxDev Then MaxDev = CurrentDev MaxIndex = I End If Next I ' Using MaxIndex, acquire that axes deviation, + Tol and - Tol ' 167 is Dtype F_PLUS_TOL; 168 is Dtype F_MINUS_TOL Dev = ReportData.GetValue(340, MaxIndex) PTol = ReportData.GetValue(167, MaxIndex) MTol = ReportData.GetValue(168, MaxIndex) ' Use this information to adjust the background color of the grid cell iReturn = This.SetCellBackgroundColor(0, 0, ReportData.GetTolColor(Dev,PTol,MTol))
Once you have added the code, click OK. The Mini-Editor checks for any syntax errors. If you have an error in your code, PC-DMIS displays a message at this time. If there aren't any errors, the VBS Mini-Editor closes.
Select File | Save to save your new copy of REFERENCE_ID_COLOR.LBL.
Select File | Close. This closes the Label Template Editor.