Author Topic: New Project Step 2 Layers  (Read 21880 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
New Project Step 2 Layers
« Reply #60 on: July 27, 2005, 06:22:15 PM »
i have updated our document location with this PDF.  It shows the Sub up to where we are now.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
New Project Step 2 Layers
« Reply #61 on: August 02, 2005, 05:29:56 PM »
Moving on to DoesLayerExist()

Any ideas what we need to do?  

Pseudo code or actual code ideas...
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
New Project Step 2 Layers
« Reply #62 on: August 02, 2005, 05:30:31 PM »
Sub or Function and why...

also, Public or Private, and what effect will it have.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
New Project Step 2 Layers
« Reply #63 on: August 02, 2005, 05:32:53 PM »
Function,

so that :

True or false can be returned < or the objectID >
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
New Project Step 2 Layers
« Reply #64 on: August 02, 2005, 05:36:41 PM »
Yes, Function is what we need.  And True or False is what we are looking for as an answer.  Now, any idea what method we can use for the test?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
New Project Step 2 Layers
« Reply #65 on: August 09, 2005, 12:15:10 PM »
OK, we know we need a function so that we can get a result. True or False, does the layer exist?  How can we search each layer?  We need to iterate through the layer collection to check to see what layers exist in the drawing.  A For Each loop will allow us to search every layer.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
New Project Step 2 Layers
« Reply #66 on: August 09, 2005, 12:18:49 PM »
There are a bunch of different ways to write this, but this is what I put together
Code: [Select]
Private Function DoesLayerExist(ByRef LayerName As String) As Boolean

    Dim objLayer As AcadLayer

    For Each objLayer In ThisDrawing.Layers
        If UCase(objLayer.name) = UCase(LayerName) Then
            DoesLayerExist = True
            Exit Function
        End If
    Next objLayer
    DoesLayerExist = False
End Function


A few things to notice on this function are the argument I'm passing in, by ref, and the fact that I declared the function as Boolean.  This is a hint that Im looking for True or False.  Follow this through and see if it all makes sense.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: New Project Step 2 Layers
« Reply #67 on: September 08, 2005, 09:51:15 PM »
OK, has everyone had a chance to digest that function, does anybody have an idea how to call this routine, from within an 'IF' statement so that our True or False result can be used to our advantage.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bob Wahr

  • Guest
Re: New Project Step 2 Layers
« Reply #68 on: September 09, 2005, 11:26:56 AM »
Sir, yes sir!

Edit: Se7en
Sorry Bob, i needed to try and edit a post to test permissions on this forum. Sorry for the intrusion.
« Last Edit: September 17, 2005, 09:22:16 AM by Se8en »

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: New Project Step 2 Layers
« Reply #69 on: September 19, 2005, 01:41:43 PM »
Code: [Select]
Private Function DoesLayerExist(ByRef LayerName As String) As Boolean

   Dim objLayer As AcadLayer

   For Each objLayer In ThisDrawing.Layers
       If UCase(objLayer.name) = UCase(LayerName) Then
           DoesLayerExist = True
           Exit Function
       End If
   Next objLayer                 <=== you lost me here
   DoesLayerExist = False
End Function


This *seems* to work but that line 'Next objlayer' has got me confused.

Code: [Select]
Private Function DoesLayerExist(ByRef LayerName As String) As Boolean

   Dim objLayer As AcadLayer

   For Each objLayer In ThisDrawing.Layers
       If UCase(objLayer.Name) = UCase(LayerName) Then
           DoesLayerExist = True
           'Exit Function
       Else:
       DoesLayerExist = False
       End If
   Next objLayer
End Function
TheSwamp.org  (serving the CAD community since 2003)

Bob Wahr

  • Guest
Re: New Project Step 2 Layers
« Reply #70 on: September 19, 2005, 01:58:21 PM »
Mark, the 'Next objLayer' line tells the function to continue the loop with the next layer.

For Each objLayer in ThisDrawing.Layers
    tells the function that it's going to iterate through every layer in the drawing to do something
Next objLayer
    tells the function that you are through with that layer and ready for the next


For Each objLayer in ThisDrawing.Layers
' some stuff
Next

Works just as well.  'Next objLayer' primarily helps you, and anyone else looking at your code, which for loop you are nexting.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: New Project Step 2 Layers
« Reply #71 on: September 19, 2005, 02:13:26 PM »
Hi David,

Another Method could be to apply an exception based test
ie ;

Put this in an error trap. If it Spits the dummy, the Layer doesn't exist.

    Dim layerObj As AcadLayer
    Set layerObj = ThisDrawing.Layers.Item("TestLayerName")
 

:edit:
.. but that may be jumping the gun a little ..
« Last Edit: September 19, 2005, 02:18:32 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: New Project Step 2 Layers
« Reply #72 on: September 19, 2005, 02:32:40 PM »
Thanks Bob. A big "DUH" for me.
TheSwamp.org  (serving the CAD community since 2003)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: New Project Step 2 Layers
« Reply #73 on: September 19, 2005, 02:43:18 PM »
Kerry, having never tried that, would you be trapping the failure to set?  If is cant set it, then create it?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: New Project Step 2 Layers
« Reply #74 on: September 19, 2005, 03:32:32 PM »
David,

 .. essentially yes .. .. 

If the .Item on the LayersCollection fails an error is thrown. .. so if no error, the Layer exists, and you could pass back either the LayerObject or the true/false , depending on design.

This may be suitable when attempting to identify one particular item from the Collection.

As I said, this is probably getting ahead of ourselves, and diverts attention from the Collection iteration you were demonstrating.

Regards
Kerry
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.