TopOffset Example

AEC Auto

TopOffset Example

Sub Example_TopOffset()

    ' This example modifies the top offset of the selected object
    ' in relation to its anchor point on the grid assembly. It
    ' prompts the user to select the object to be modified,
    ' and then it prompts the user to specify the number of inches
    ' to adjust the offset by. The number can be either positive
    ' or negative.
    
    ' 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
    Dim offset_adjust As Double
         
    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, "TopOffset 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, "TopOffset Example"
        ElseIf Not TypeOf anchor Is AecAnchorEntToGridAssembly Then
            MsgBox "Object is anchored, but not to a grid assembly.", vbExclamation, "TopOffset Example"
        Else
            ' AdjustSizing must be set to True in order for offset change to take effect.
            anchor.AdjustSizing = True
            MsgBox "Top offset of object was: " & anchor.TopOffset, vbInformation, "TopOffset Example"
            
            ' Prompt user to specify amount to adjust offset by.
            offset_adjust = ThisDrawing.Utility.GetReal("Enter the number of inches to adjust top offset by: ")
            
            ' Change offset by specified amount.
            anchor.TopOffset = anchor.TopOffset + offset_adjust
            ThisDrawing.Regen (acActiveViewport)
            MsgBox "New top offset is: " & anchor.TopOffset, vbInformation, "TopOffset Example"
        End If
    Else
        MsgBox "Object selected is not an AEC entity.", vbInformation, "TopOffset Example"
    End If

End Sub