The two ways I see to use the function in an If...Then Statement is to check if it's true or check if it's false. Basically, if it exists, do something to it, or if it doesn't exist, make it, then do something to it, is what you would do for a true test. If you just wanted to ensure that the layer exists in the drawing, testing for false would be easier.
For these, I am simply going with a layer name as type in on the command line.Sub Test1()
'this sub will test for true and do things accordingly
Dim strLayName as String
strLayName = ThisDrawing.Utility.Getstring(1,"Type layer name to check: ")
'on the above line, the 1 in the first field in parenthesis tells the GetString method to allow spaces
if DoesLayerExist(strLayName) = True then
'Do things to the layer if it exists
Else
'The layer doesn't exist. Make the layer, then do things to it
End if
end sub
I went the long way with my If. DoesLayerExist(DLE) is a Boolean. That means that that it has two states. True/False is one way to think of it, the other way is that it either is or it isn't. Think of a light in your house as a boolean. If the light is on (True) there is light. If the light is off(false) there is no light. So there either is light or there isn't light. The following code works exactly the same way but instead of checking to see if DLE is true, I am just checking to see if DLE is.
Sub Test2()
'this sub will test for true and do things accordingly
Dim strLayName as String
strLayName = ThisDrawing.Utility.Getstring(1,"Type layer name to check: ")
'on the above line, the 1 in the first field in parenthesis tells the GetString method to allow spaces
[b]if DoesLayerExist(strLayName) then[/b]
'Do things to the layer if it exists
Else
'The layer doesn't exist. Make the layer, then do things to it
End if
end sub
Now if all we want to do is make sure that the layer exists, and if it doesn't, make it, then we really don't care about the true case. We could do
Sub Test3()
Dim strLayName as String
strLayName = ThisDrawing.Utility.Getstring(1,"Type layer name to check: ")
if DoesLayerExist(strLayName) then
'Nothing here because we aren't doing anything to an existing layer
Else
thisDrawing.Layers.Add(strLayName)
End if
end sub
But the whole wasted true field just takes up space, memory, and time. Instead I'm going to check to see if DLE is false which I could do with "If DoesLayerExist(strLayName)=False Then" but prefer to do it by just checking to see if DLE is like this
Sub Test4()
Dim strLayName as String
strLayName = ThisDrawing.Utility.Getstring(1,"Type layer name to check: ")
If [b]Not[/b] DoesLayerExist(strLayName) Then
ThisDrawing.Layers.Add(strLayName)
End if
End Sub
I tried to explain my methods and my thought process so Duh wouldn't have to but as I have a tough time following my thought processes most times, myself, if you don't understand what I am saying or doing, ask.