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

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« on: July 12, 2005, 03:07:07 PM »
Ok, Lets load some layers.  Any idea how to load 2 layers, not worrying about color and linetype just yet?  I'll start us off with
Code: [Select]

Public Sub LLayer()

End Sub


Its going to use the ThisDrawing methods again, so lets see what people come up with.

Extra Credit:Create a function that checks to see if the Layer exists, therefore not re-creating it.  This will be important when we begin assiging color and linetypes to layers.
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

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« Reply #1 on: July 12, 2005, 03:09:26 PM »
Layer names should be 'Yellow' and 'White' for 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

Mark

  • Custom Title
  • Seagull
  • Posts: 28725
New Project Step 2 Layers
« Reply #2 on: July 12, 2005, 03:21:30 PM »
For now ...
Code: [Select]

Public Sub LLayer()
   
    Dim Ylayer As AcadLayer
    Set Ylayer = ThisDrawing.Layers.Add("Yellow")
   
    Dim Wlayer As AcadLayer
    Set Wlayer = ThisDrawing.Layers.Add("White")
   
End Sub
TheSwamp.org  (serving the CAD community since 2003)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« Reply #3 on: July 12, 2005, 03:23:28 PM »
Excellent, now how about assigning the respective colors to the layers.  Any 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

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« Reply #4 on: July 12, 2005, 06:22:37 PM »
I am interested in what you think should be done to assign the colors.  If you try something, post what you tried.  Even if it doesn't work, post it so others can see what has been tried.
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

TR

  • Guest
New Project Step 2 Layers
« Reply #5 on: July 12, 2005, 09:01:23 PM »
Just a note: Anytime you use 'Set' you should set it to Nothing at the end of the sub.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« Reply #6 on: July 13, 2005, 09:08:15 PM »
Quote from: Tim Riley
Anytime you use 'Set' you should set it to Nothing at the end of the sub.

Tim makes an excellent point, so lets add that
Code: [Select]

Public Sub LLayer()
   
    Dim Ylayer As AcadLayer
    Set Ylayer = ThisDrawing.Layers.Add("Yellow")
    Set Ylayer = Nothing
    Dim Wlayer As AcadLayer
    Set Wlayer = ThisDrawing.Layers.Add("White")
    Set Wlayer = Nothing
End Sub
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

TR

  • Guest
New Project Step 2 Layers
« Reply #7 on: July 13, 2005, 11:36:21 PM »
IMHO you should have an On Error Goto ErrorH statment and that should set everything to nothing. That way regardless of the situation the sub cleans itself.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« Reply #8 on: July 14, 2005, 10:13:16 AM »
Im thinking Tim means something like this
Code: [Select]
Public Sub LLayer()
    On Error GoTo Error_Handler
    Dim Ylayer As AcadLayer
    Set Ylayer = ThisDrawing.Layers.Add("Yellow")

    Set Ylayer = Nothing
    Dim Wlayer As AcadLayer
    Set Wlayer = ThisDrawing.Layers.Add("White")

    Set Wlayer = Nothing
    Exit Sub
Error_Handler:
    Err.Clear
    Set Wlayer = Nothing
    Set Ylayer = Nothing
End Sub


Now we still need to change the colors of those newly created layers.  Any 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

Birdy

  • Guest
New Project Step 2 Layers
« Reply #9 on: July 16, 2005, 08:07:47 PM »
I'm messing with this:
Code: [Select]
Public Sub LLayer()
    On Error GoTo Error_Handler
    Dim Ylayer As AcadLayer
    Set Ylayer = ThisDrawing.Layers.Add("Yellow")
    Dim Ycolor As ACAD_COLOR
    Set Object.Ycolor = ThisDrawing.Layers.TrueColor("Yellow")
    Set Ylayer = Nothing
   
    Dim Wlayer As AcadLayer
    Set Wlayer = ThisDrawing.Layers.Add("White")
    Set Object.Wcolor = ThisDrawing.Layers.TrueColor("White")
    Set Wlayer = Nothing
    Exit Sub
Error_Handler:
    Err.Clear
    Set Wlayer = Nothing
    Set Ylayer = Nothing
End Sub

But it ain't working. <shooting blanks in the dark here, Huh?>

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
New Project Step 2 Layers
« Reply #10 on: July 16, 2005, 09:39:18 PM »
Birdy, How about something like this ??

Remember, you can Use the Locals window to see variable values when Stepping through <F8> code.

ps: I'm not a VB'er, so this may not be 100%
Code: [Select]

Option Explicit
'
' Test Routine for Demo Only.
'
Public Sub CLLayer()

    On Error GoTo CLLayer_Error

    Dim Ylayer As AcadLayer
    Set Ylayer = ThisDrawing.Layers.Add("Yellow")
    Dim ColorProperty As Integer

    ColorProperty = acYellow
    Ylayer.color = ColorProperty

    ' Could have used :
    ' Ylayer.color = acYellow
    ' to save the declaration and assignment
    '
    ' Next Option
    '
    Dim Glayer As AcadLayer
    Dim TrueColor As New AcadAcCmColor
    Call TrueColor.SetRGB(0, 255, 0)

    Set Glayer = ThisDrawing.Layers.Add("Green")
    Glayer.TrueColor = TrueColor

    '
    '
    ' Next Option
    '
    Dim Newlayer As AcadLayer
    Set Newlayer = ThisDrawing.Layers.Add("FourtyOne")
    Newlayer.color = 41

    '
    ' Added for fun
    '
    Dim aacColor As AcadAcCmColor
    Set aacColor = Newlayer.TrueColor

    Dim strColor As String
    strColor = "Red = " & aacColor.Red & vbCrLf & _
               "Green = " & aacColor.Green & vbCrLf & _
               "Blue = " & aacColor.Blue


    MsgBox strColor



    On Error GoTo 0
    GoTo Set_To_Nothing

CLLayer_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & _
           ") in procedure CLLayer of Module TestLayer"

Set_To_Nothing:
    Set Glayer = Nothing
    Set Ylayer = Nothing
    Set Newlayer = Nothing
    Set aacColor = Nothing
End Sub
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« Reply #11 on: July 21, 2005, 09:28:24 AM »
Excellent example KWB!  This example has multiple ways to color a layer.  Did everyone look at the different ways to do this?  Most people (Myself included) will probable only think of acad colors as 1-255, but there are other colors you might need.
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

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Update to this
« Reply #12 on: July 21, 2005, 10:31:50 AM »
Question - Is everyone familiar with the concept of passing a Sub/Function an Argument?  I ask because I want us to reduce the amount of typing that went into our code.
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

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
New Project Step 2 Layers
« Reply #13 on: July 21, 2005, 02:27:15 PM »
^ Need a show of hands to move on.
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

jonesy

  • SuperMod
  • Seagull
  • Posts: 15567
New Project Step 2 Layers
« Reply #14 on: July 21, 2005, 04:27:32 PM »
Getting there
Thanks for explaining the word "many" to me, it means a lot.