LeftOffset Example

AEC Auto

LeftOffset Example

Sub Example_LeftOffset()

    ' This example returns the left offset of the selected object
    ' to the 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 offset 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, "LeftOffset 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, "LeftOffset Example"
        ElseIf Not TypeOf anchor Is AecAnchorEntToGridAssembly Then
            MsgBox "Object is anchored, but not to a grid assembly.", vbExclamation, "LeftOffset Example"
        Else
            MsgBox "Left offset of object: " & anchor.LeftOffset, vbInformation, "LeftOffset Example"
        End If
    Else
        MsgBox "Object selected is not an AEC entity.", vbInformation, "LeftOffset Example"
    End If
    
End Sub