YAlignment Example

AEC Auto

YAlignment Example

Sub Example_YAlignment()

    ' This example looks at the way a selected object is anchored
    ' in relation to the baseline of a grid assembly.
    
    ' Use this example with a drawing that contains a window
    ' assembly and one or more AEC objects attached to the
    ' assembly.
    
    Dim ent As AcadEntity
    Dim geo As AecGeo
    Dim anchor As AecAnchor
    
    Dim alignment As String
         
    On Error Resume Next           ' Handle errors in code.
    
    ' Prompt user to select an object.
    ThisDrawing.Utility.GetEntity ent, pt, "Select object anchored to window assembly:"
    
    ' Make sure user selected an AEC object, and that the object
    ' is anchored to a grid assembly.
    
    If ent Is Nothing Then
        MsgBox "Nothing was selected.", vbExclamation, "YAlignment Example"
    ElseIf TypeOf ent Is AecGeo Then
        Set geo = ent
        
        ' Get the anchor the object is attached to.
        Set anchor = geo.GetAnchor
        On Error GoTo 0
        If anchor Is Nothing Then
            MsgBox "Selected object is not anchored.", vbExclamation, "YAlignment Example"
        ElseIf Not TypeOf anchor Is AecAnchorEntToGridAssembly Then
            MsgBox "Object is anchored, but not to a grid assembly.", vbExclamation, "YAlignment Example"
        Else
            Select Case anchor.YAlignment
                Case aecInfillAlignCentered
                   alignment = "Centered."
                Case aecInfillAlignFrontFlush
                   alignment = "In front of the baseline."
                Case aecInfillAlignBackFlush
                   alignment = "In back of the baseline."
                Case Else
                   alignment = "Unknown"
             End Select
                
            MsgBox "Y Alignment of object: " & alignment, vbInformation, "YAlignment Example"
        End If
    Else
        MsgBox "Object selected is not an AEC entity.", vbInformation, "YAlignment Example"
    End If

End Sub