Access draworder via VBA after command has run

Access draworder via VBA after command has run

Anonymous
Not applicable
712 Views
1 Reply
Message 1 of 2

Access draworder via VBA after command has run

Anonymous
Not applicable
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
0 Likes
713 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
What version of AutoCAD? Later versions have the AcadSortentsTable for draw
order, so there is no need to use SendCommand. Search this newsgroup, as I
helped some others on this topic in the last year.

--
R. Robert Bell


"Chris Boyd" wrote in message
news:5088038@discussion.autodesk.com...
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
0 Likes