Retrieving Attributes


 

The process for retrieving attributes runs on three levels. These levels are based on the complexity of the attached attribute. A symbol can contain any number of attributes, each of which can contain any number of labels and values. Therefore, when moving through the drawing database to retrieve attributes, an application should first filter the symbols and then move through each attribute and each label one at a time until all have been retrieved. The process can then continue on to the next symbol in the drawing and repeat the attribute search.

 

C++ VB.NET VBScript
// C++ to Retrieve Attributes
//   lines starting with a // are comments
void WINAPI RetrieveAtb(charszDllCommandLine)
{
    //  required parameter but unused by this function
    //  circumvent the unreferenced formal parameter warning
    UNUSED_PARAMETER(szDllCommandLine);
 
    //  used for error returns from the API
    short iError;
 
    //  used for messages
    char sz[1024];
    charszLabel;
    charszValue;
 
    //  parse through the entire database:
    //  start at the first entity
    short iKind;
    VCFirstEntity(&iError, &iKind);
 
    //  loop through entities
    while (iError == 0)
    {
        //  process only symbols
        if (iKind == SYMBOL2D)
        {
            //  Retrieve the number of attribute definitions 
            //  attached:
            //      A symbol can have an unlimited number of 
            //      attributes attached.  These attribute 
            //      definitions contain labels and values 
            //      defining the definition.  This step should be
            //      used to determine the number so a proper loop 
            //      can be set up to parse through all the 
            //      attributes.  The following code retrieves the 
            //      number of attributes and sets up a loop 
            //      structure to begin parsing the attributes:
 
            short iAtbCount;
            iAtbCount = VCGetCurEntAtbCount(&iError);
 
            for (short iAtbIndex = 0; iAtbIndex < iAtbCountiAtbIndex++)
            {
                //  Retrieve the number of labels in the current 
                //  attribute definition:
                //      Similar to the step above but this sets 
                //      up a loop structure for parsing the 
                //      current attribute.  The following example 
                //      sets up a loop structure to parse the 
                //      current attribute definition:
 
                short iRecCount;
                iRecCount = VCGetCurEntAtbRecCount(&iErroriAtbIndex);
                {
                    //  Retrieve the label from the definition:
                    //      Once inside the attribute definition, 
                    //      the program can then retrieve the 
                    //      label and value.  The label 
                    //      represents the name or tag for the 
                    //      attribute.  For example, if the 
                    //      attribute read MANUFACTURER: TRITOOLS 
                    //      then MANUFACTURER represents the 
                    //      label and TRITOOLS represents the 
                    //      value.  The following code retrieves 
                    //      the label and value at the current 
                    //      loop index:
 
                    for (short iRecIndex = 0; iRecIndex < iRecCountiRecIndex++)
                    {
                        short iLen;
                        iLen = VCGetCurEntAtbRecLabel(&iErroriAtbIndexiRecIndexNULL);
                        szLabel = new char[iLen + 1];
                        VCGetCurEntAtbRecLabel(&iErroriAtbIndexiRecIndexszLabel);
 
                        iLen = VCGetCurEntAtbRecValue(&iErroriAtbIndexiRecIndexNULL);
                        szValue = new char[iLen + 1];
                        VCGetCurEntAtbRecValue(&iErroriAtbIndexiRecIndexszValue);
 
                        sprintf_s(szsizeof(sz), 
                            "Label: %s  Value: %s", 
                            szLabelszValue);
                        MessageBox(NULLsz"API Help Sample"NULL);
 
                        delete [] szLabel;
                        delete [] szValue;
                    }
                }
            }
        }
 
        VCNextEntity(&iError, &iKind);
    }
}
' VB.NET to Retrieve Attributes
'   lines starting with an apostrophe are comments
Public Class RetrieveAtb
 
    ' create Visual CADD object
    Shared WithEvents vcadd As New VCadd32.Automation
 
    Public Shared Function Run(ByVal str As StringAs Integer
 
        '   used for messages
        Dim sz As String
        Dim szLabel As String
        Dim szValue As String
 
        '   parse through the entire database:
        '   start at the first entity
        Dim iKind As Short
        iKind = vcadd.FirstEntity()
 
        '   loop through entities
        Do While (vcadd.GetErrorCode() = 0)
 
            '   process only symbols
            If (iKind = SYMBOL2D) Then
                '   Retrieve the number of attribute definitions 
                '   attached:
                '       A symbol can have an unlimited number of 
                '       attributes attached.  These attribute 
                '       definitions contain labels and values 
                '       defining the definition.  This step should be
                '       used to determine the number so a proper loop 
                '       can be set up to parse through all the 
                '       attributes.  The following code retrieves the 
                '       number of attributes and sets up a loop 
                '       structure to begin parsing the attributes:
 
                Dim iAtbCount As Short
                iAtbCount = vcadd.GetCurEntAtbCount()
 
                For iAtbIndex = 0 To iAtbCount - 1
 
                    '   Retrieve the number of labels in the current 
                    '   attribute definition:
                    '       Similar to the step above but this sets 
                    '       up a loop structure for parsing the 
                    '       current attribute.  The following example 
                    '       sets up a loop structure to parse the 
                    '       current attribute definition:
 
                    Dim iRecCount As Short
                    iRecCount = vcadd.GetCurEntAtbRecCount(iAtbIndex)
 
                    '   Retrieve the label from the definition:
                    '       Once inside the attribute definition, 
                    '       the program can then retrieve the 
                    '       label and value.  The label 
                    '       represents the name or tag for the 
                    '       attribute.  For example, if the 
                    '       attribute read MANUFACTURER: TRITOOLS 
                    '       then MANUFACTURER represents the 
                    '       label and TRITOOLS represents the 
                    '       value.  The following code retrieves 
                    '       the label and value at the current 
                    '       loop index:
 
                    For iRecIndex = 0 To iRecCount - 1
 
                        szLabel = vcadd.GetCurEntAtbRecLabel(iAtbIndex, iRecIndex)
                        szValue = vcadd.GetCurEntAtbRecValue(iAtbIndex, iRecIndex)
 
                        sz = "Label: " + szLabel + "  Value: " + szValue
                        MsgBox(sz, MsgBoxStyle.Information, "API Help Sample")
                    Next
                Next
            End If
 
            vcadd.NextEntity()
        Loop
 
        ' return
        Return (True)
 
    End Function
 
End Class
' VBScript to Retrieve Attributes
'   lines starting with an apostrophe are comments
 
Public Const SYMBOL2D = 7
 
' create Visual CADD object
set vcadd = CreateObject("VisualCADD.Application.9")
 
'   used for messages
Dim sz
Dim szLabel 
Dim szValue 
 
'   parse through the entire database:
'   start at the first entity
Dim iKind 
iKind = vcadd.FirstEntity()
 
'   loop through entities
Do While (vcadd.GetErrorCode() = 0)
 
    '   process only symbols
    If (iKind = SYMBOL2D) Then
        '   Retrieve the number of attribute definitions 
        '   attached:
        '       A symbol can have an unlimited number of 
        '       attributes attached.  These attribute 
        '       definitions contain labels and values 
        '       defining the definition.  This step should be
        '       used to determine the number so a proper loop 
        '       can be set up to parse through all the 
        '       attributes.  The following code retrieves the 
        '       number of attributes and sets up a loop 
        '       structure to begin parsing the attributes:
 
        Dim iAtbCount
        iAtbCount = vcadd.GetCurEntAtbCount()
 
        For iAtbIndex = 0 To iAtbCount - 1
 
            '   Retrieve the number of labels in the current 
            '   attribute definition:
            '       Similar to the step above but this sets 
            '       up a loop structure for parsing the 
            '       current attribute.  The following example 
            '       sets up a loop structure to parse the 
            '       current attribute definition:
 
            Dim iRecCount
            iRecCount = vcadd.GetCurEntAtbRecCount(iAtbIndex)
 
            '   Retrieve the label from the definition:
            '       Once inside the attribute definition, 
            '       the program can then retrieve the 
            '       label and value.  The label 
            '       represents the name or tag for the 
            '       attribute.  For example, if the 
            '       attribute read MANUFACTURER: TRITOOLS 
            '       then MANUFACTURER represents the 
            '       label and TRITOOLS represents the 
            '       value.  The following code retrieves 
            '       the label and value at the current 
            '       loop index:
 
            For iRecIndex = 0 To iRecCount - 1
 
                szLabel = vcadd.GetCurEntAtbRecLabel(iAtbIndex, iRecIndex)
                szValue = vcadd.GetCurEntAtbRecValue(iAtbIndex, iRecIndex)
 
                sz = "Label: " + szLabel + "  Value: " + szValue
                MsgBox sz, vbInformation, "API Help Sample"
            Next
        Next
    End If
 
    vcadd.NextEntity()
Loop
 
' release Visual CADD object
set vcadd = Nothing

 

See Also:

VCFirstEntity, VCGetCurEntAtbCount, VCGetCurEntAtbRecCount, VCGetCurEntAtbRecLabel, VCGetCurEntAtbRecValue, VCNextEntity