Message 1 of 2
Access draworder via VBA after command has run

Not applicable
02-16-2006
06:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some code to try and handle xref insertions into our company
drawings. The first part of the code works as expected, waits for a command
to be issued, checks for layer, sets it if the layer exists, creates it if
not. What I am then trying to do is use the sendcommand function to attempt
to send the newly attached xref to the back via draworder. I know this code
won't work as it will attempt to do this before the xref is attached and
will send the last object added to the back. But I am unsure of how to issue
the command after xref command has been completed.
Any help would be greatfully appreciated.
p.s I am a novice at this stuff so be gentle with the programming lingo...
Chris
Option Explicit
' set the public object current Layer to be an AutoCAD Layer
Public objCurrentLayer As AcadLayer
' set the public object Previous Layer to be an AutoCAD Layer
Public objPreviousLayer As AcadLayer
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
' Save the current / active AutoCAD layer
Set objPreviousLayer = ThisDrawing.ActiveLayer
' Check for the folowing cases of the AutoCAD command.
Select Case CommandName
' check for AutoCAD Xref commands..
Case "XREF"
If Not ThisDrawing.ActiveLayer.Name = "0" Then
Set objCurrentLayer = ThisDrawing.Layers.Add("0")
objCurrentLayer.color = acWhite
objCurrentLayer.LayerOn = True
objCurrentLayer.Freeze = False
objCurrentLayer.Lock = False
ThisDrawing.ActiveLayer = objCurrentLayer
ThisDrawing.SendCommand "draworder" & vbCr & "l" & vbCr & vbCr & "back" &
vbCr
' end of if checking for 0 being the current layer.
End If
End Select
End Sub
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
' Check for the folowing cases of the AutoCAD command that has just ended.
Select Case CommandName
' check for a match on the following AutoCAD commands
Case "XREF"
' make the current active AutoCAD layer the previously saved layer.
ThisDrawing.ActiveLayer = objPreviousLayer
' clear the objCurrentLayer
Set objPreviousLayer = Nothing
End Select
' clear the objCurrentLayer
Set objCurrentLayer = Nothing
' end Private Sub AcadDocument_EndCommand
End Sub
--
Chris Boyd
Cameron Taylor
www.camerontaylor.co.uk
drawings. The first part of the code works as expected, waits for a command
to be issued, checks for layer, sets it if the layer exists, creates it if
not. What I am then trying to do is use the sendcommand function to attempt
to send the newly attached xref to the back via draworder. I know this code
won't work as it will attempt to do this before the xref is attached and
will send the last object added to the back. But I am unsure of how to issue
the command after xref command has been completed.
Any help would be greatfully appreciated.
p.s I am a novice at this stuff so be gentle with the programming lingo...
Chris
Option Explicit
' set the public object current Layer to be an AutoCAD Layer
Public objCurrentLayer As AcadLayer
' set the public object Previous Layer to be an AutoCAD Layer
Public objPreviousLayer As AcadLayer
Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
' Save the current / active AutoCAD layer
Set objPreviousLayer = ThisDrawing.ActiveLayer
' Check for the folowing cases of the AutoCAD command.
Select Case CommandName
' check for AutoCAD Xref commands..
Case "XREF"
If Not ThisDrawing.ActiveLayer.Name = "0" Then
Set objCurrentLayer = ThisDrawing.Layers.Add("0")
objCurrentLayer.color = acWhite
objCurrentLayer.LayerOn = True
objCurrentLayer.Freeze = False
objCurrentLayer.Lock = False
ThisDrawing.ActiveLayer = objCurrentLayer
ThisDrawing.SendCommand "draworder" & vbCr & "l" & vbCr & vbCr & "back" &
vbCr
' end of if checking for 0 being the current layer.
End If
End Select
End Sub
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
' Check for the folowing cases of the AutoCAD command that has just ended.
Select Case CommandName
' check for a match on the following AutoCAD commands
Case "XREF"
' make the current active AutoCAD layer the previously saved layer.
ThisDrawing.ActiveLayer = objPreviousLayer
' clear the objCurrentLayer
Set objPreviousLayer = Nothing
End Select
' clear the objCurrentLayer
Set objCurrentLayer = Nothing
' end Private Sub AcadDocument_EndCommand
End Sub
--
Chris Boyd
Cameron Taylor
www.camerontaylor.co.uk