Author Topic: BLockDef Table and Layers  (Read 5346 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Re: BLockDef Table and Layers
« Reply #15 on: February 13, 2008, 12:19:31 PM »

Hey Guys!

Thanks again! Thanks Bry for the explanation.

I'm just pinging back in to the discussion:

I am definitely more accustom to programming with arrays and that was the method that I started out using before I finally folded and decided to post for a bit of help.

If, you had just coded with an array initially, I likely would have said thanks Bry and moved on.
It was the fact that you used the collection that peaked my interest.

Recently, I saw someone bring in data from a stored procedure from SQL and assign that data to a New Collection and I just thought, that was the coolest thing.
So while I have been at VBA for a few years, there are certainly methods I have not touched yet; like New Collections, Class Modules and so on.

I guess that is one of the beauties of programming, there is always more to learn.

I will definitely examine you code closer and see if I can not apply that method with another example.

Now, after The Collection is created, you could then create properties and methods as well to those objects, couldn't you?

Thanks!

Mark


ML

  • Guest
Re: BLockDef Table and Layers
« Reply #16 on: February 13, 2008, 03:46:28 PM »

Bry

I now have (with some help from CM) a Do Until Loop in the code
However, I am not sure how to handle clearing The Laycol after each loop cycle?
As a result, I am picking my first block, it is printing out the proper layer info but after I pick the next block, it is printing out the layers from the last block picked, plus the new layers.

Any suggestions?

Thanks again!
Mark

ML

  • Guest
Re: BLockDef Table and Layers
« Reply #17 on: February 13, 2008, 05:26:32 PM »

OK, here is the code that Bry posted only it will now loop through and keep prompting the user for the next block until the user escapes; removing and recreating The LayCol with each loop.
Also, I want to thank CM for his help to advance the code to this point.

Code: [Select]
Sub BlocklayersLoop() 'This Sub will keep prompting for the next block until user escapes.
      Dim B As AcadBlock
      Dim Ent As AcadEntity
      Dim P
      Dim LayerCol As New Collection
      Dim slayer As String
      Dim Picked As Boolean
      Dim i As Integer
     
      Do
       On Error Resume Next
       ThisDrawing.Utility.GetEntity Ent, P, "Pick a blockref"
       If Not TypeOf Ent Is AcadBlockReference Then
        Picked = False
        GoTo ExitOut
       Else
        Picked = True
       End If
       If Ent Is Nothing Then
        Picked = False
        GoTo ExitOut
       Else
        Picked = True
       End If
       
       Set B = ThisDrawing.Blocks(Ent.Name)
       Debug.Print "The block " & B.Name & " uses the following layers:"
       
       For Each Ent In B
        slayer = Ent.Layer
        For i = 1 To LayerCol.Count
         If LayerCol(i) = slayer Then GoTo skip
        Next
        LayerCol.Add slayer
skip:
        Next
        For i = 1 To LayerCol.Count
         Debug.Print LayerCol(i)
        Next
ExitOut:
        Dim Num As Integer
         For Num = 1 To LayerCol.Count
          LayerCol.Remove 1   
         Next
        Loop Until Picked = False
        Exit Sub
End Sub

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: BLockDef Table and Layers
« Reply #18 on: February 14, 2008, 11:01:54 AM »
Your welcome, glad I could help
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)

ML

  • Guest
Re: BLockDef Table and Layers
« Reply #19 on: February 14, 2008, 11:04:09 AM »

Yes sir!

That's what it is all about

Helping each other!

Forums Kick A*s! :)

Mark