Thanks for this reply. My final code is as follow:
Function RefClipByFence() As Boolean
Dim fnc As Fence
Dim oView As View
Set oView = CommandState.LastView
Set fnc = ActiveDesignFile.Fence
If fnc.IsDefined = True Then
CadInputQueue.SendCommand "REFERENCE CLIP BOUNDARY"
'the next few lines sets the tool setting window for "Reference Clip Boundary"
'settings to Method = Fence and Use References Dialog List = true
lngTemp = Not 15
lngTemp = GetCExpressionValue("tcb->msToolSettings.refTools.clipMethod", "") And lngTemp
SetCExpressionValue "tcb->msToolSettings.refTools.clipMethod", lngTemp Or 0, ""
SetCExpressionValue "tcb->msToolSettings.refTools.ignoreRefDialog", 0, ""
'send command to clip all reference files
CadInputQueue.SendCommand "REFERENCE CLIP BOUNDARY ALL"
CadInputQueue.SendDataPoint GetLastDataPoint(oView), oView
CommandState.StartDefaultCommand
End If
End Function
'For information
'Function GetLastDataPoint(View As View) As Point3d
'
' Dim Ci As CursorInformation
'
' Set Ci = CursorInformation
' Set View = Ci.CurrentView
'
'
' GetLastDataPoint = CommandState.LastDataPoint
'
'End Function