Message 1 of 5
Layer object behavior
Not applicable
03-06-2003
03:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In the code snippet below, I am wondering why I have to set the objLayer
object to Nothing before I can create the second and third layers, when I
take "Set objLayer = Nothing" out the code never changes the objLayer
variable besides the first time. Shouldn't the "Set objLayer =
ThisDrawing..." lines just overwrite without having to first clear the
variable or is this expected behavior? I am using VBA 6 w/ Acad2002.
Thanks:
On Error Resume Next
Set objLayer = ThisDrawing.Layers("S-GRID")
If objLayer Is Nothing Then
Set objLayer = ThisDrawing.Layers.Add("S-GRID")
If objLayer Is Nothing Then
MsgBox "Unable to Add S-GRID Layer " & vbCr & Err.Description
End If
On Error Resume Next
Set objLinetype = ThisDrawing.Linetypes("Center2")
If objLinetype Is Nothing Then
ThisDrawing.Linetypes.Load "Center2", "C:\Program Files\AutoCAD
2002\Support\acad.lin"
If Err Then
MsgBox "Error loading CENTER2 linetype" & vbCr &
Err.Description
End If
Set objLinetype = ThisDrawing.Linetypes("Center2")
End If
objLayer.Color = 9
objLayer.Linetype = objLinetype
End If
Set objLayer = Nothing
Set objLayer = ThisDrawing.Layers("S-GRID-IDEN")
Debug.Print Err.Description ' take this out later
If objLayer Is Nothing Then
Set objLayer = ThisDrawing.Layers.Add("S-GRID-IDEN")
If objLayer Is Nothing Then
MsgBox "Unable to Add S-GRID-IDEN Layer " & Err.Description
End If
objLayer.Color = acGreen
End If
Set objLayer = Nothing
Set objLayer = ThisDrawing.Layers("S-GRID-IDEN-TEXT")
Debug.Print Err.Description ' take this out later too
If objLayer Is Nothing Then
Set objLayer = ThisDrawing.Layers.Add("S-GRID-IDEN-TEXT")
If objLayer Is Nothing Then
MsgBox "Unable to Add S-GRID-IDEN-TEXT Layer " & Err.Description
End If
objLayer.Color = acWhite
End If
--
matthew g.
object to Nothing before I can create the second and third layers, when I
take "Set objLayer = Nothing" out the code never changes the objLayer
variable besides the first time. Shouldn't the "Set objLayer =
ThisDrawing..." lines just overwrite without having to first clear the
variable or is this expected behavior? I am using VBA 6 w/ Acad2002.
Thanks:
On Error Resume Next
Set objLayer = ThisDrawing.Layers("S-GRID")
If objLayer Is Nothing Then
Set objLayer = ThisDrawing.Layers.Add("S-GRID")
If objLayer Is Nothing Then
MsgBox "Unable to Add S-GRID Layer " & vbCr & Err.Description
End If
On Error Resume Next
Set objLinetype = ThisDrawing.Linetypes("Center2")
If objLinetype Is Nothing Then
ThisDrawing.Linetypes.Load "Center2", "C:\Program Files\AutoCAD
2002\Support\acad.lin"
If Err Then
MsgBox "Error loading CENTER2 linetype" & vbCr &
Err.Description
End If
Set objLinetype = ThisDrawing.Linetypes("Center2")
End If
objLayer.Color = 9
objLayer.Linetype = objLinetype
End If
Set objLayer = Nothing
Set objLayer = ThisDrawing.Layers("S-GRID-IDEN")
Debug.Print Err.Description ' take this out later
If objLayer Is Nothing Then
Set objLayer = ThisDrawing.Layers.Add("S-GRID-IDEN")
If objLayer Is Nothing Then
MsgBox "Unable to Add S-GRID-IDEN Layer " & Err.Description
End If
objLayer.Color = acGreen
End If
Set objLayer = Nothing
Set objLayer = ThisDrawing.Layers("S-GRID-IDEN-TEXT")
Debug.Print Err.Description ' take this out later too
If objLayer Is Nothing Then
Set objLayer = ThisDrawing.Layers.Add("S-GRID-IDEN-TEXT")
If objLayer Is Nothing Then
MsgBox "Unable to Add S-GRID-IDEN-TEXT Layer " & Err.Description
End If
objLayer.Color = acWhite
End If
--
matthew g.