Author Topic: Simple BlockCounter won't count..  (Read 2706 times)

0 Members and 1 Guest are viewing this topic.

hardwired

  • Guest
Simple BlockCounter won't count..
« on: April 17, 2008, 09:02:16 AM »
Hi,

After trauling through some old folders at work, i found a Block Count program that i was obvioulsy working on at some point a few years ago, and thought i'd test it..

It does everything it should except for actually displaying the number of block the user selects, which it should display in the label caption on the form..

Any ideas why the SelectionSet count might be 0?

I can't see for the life of me / and my limited VBA knowledge, lol, what could be amiss..

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Simple BlockCounter won't count..
« Reply #1 on: April 17, 2008, 10:07:59 AM »
I'll give it a look
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)

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Simple BlockCounter won't count..
« Reply #2 on: April 17, 2008, 10:10:18 AM »
The selection set part.
FilterType and FilterData must an orderd pair.
After you fix that, you'll find that you need an exit for in the For Each ssBlockZ In ThisDrawing.SelectionSets part
It would help you to learn to step through code using f8, then you can test values as you run your program. When you find something that isn't working you try to isolate the problem and then work on just that part. As far as getting help, I would rather look at some code in a post than mess around with a dvb.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Simple BlockCounter won't count..
« Reply #3 on: April 17, 2008, 10:23:35 AM »
Here is the corrected code
Code: [Select]
Option Explicit
Dim blockZ As AcadBlock  'ThisDrawing.Blocks..
Dim getBlock As AcadEntity  'Select a block to count..
Dim no_of_blocksX As Integer  'Number of blocks (selected)..
Dim allBlocks As Integer  'Number of block (in entire drawing)..
Dim basex As Variant  'Pick point for block selection..
Dim Lblockname As String, Lblockname2 As String  'Left character in the blockname (to filter out unwanted blocks from the list)..
Dim checkname As Integer  'Compares actual block names with combobox block names..
Dim SSet As AcadSelectionSet  'Selection set for blocks..
Dim blockname As String  'Name of block picked..
Dim response As Integer 'Yes / No..

' Update the block count each time the combobox text is changed..
Private Sub BlockNameCMBO_Change()
For Each SSet In ThisDrawing.SelectionSets
    If SSet.Name = "GetBlocks" Then
        SSet.Delete
    End If
Next SSet

blockname = BlockNameCMBO.Text

Dim FilterType(0 To 1) As Integer  'Selection Set - Filter type..
Dim FilterData(0 To 1) As Variant  'Selection Set - Filter data..

' Create a selection set..
Set SSet = ThisDrawing.SelectionSets.Add("GetBlocks")

FilterType(0) = 0: FilterData(0) = "INSERT"

FilterType(1) = 2: FilterData(1) = blockname
SSet.Select acSelectionSetAll, , , FilterType, FilterData


no_of_blocksX = SSet.Count
lblTotal.Caption = no_of_blocksX
End Sub

' Select a block..
Private Sub PickBlockBTN_Click()
blockcountform.Hide

On Error Resume Next
TryAgain:
ThisDrawing.Utility.GetEntity getBlock, basex, vbCr & "Select a block to count.. "

ErrHndlr:
    If Err.Number <> 0 Then
        Err.Clear
        GoTo TryAgain
    End If
    On Error GoTo ErrHndlr
   
BlockNameCMBO.Text = getBlock.Name  'Show the selected block name in the combobox..

blockcountform.Show
End Sub

'********************************************
'*************** FORM LOAD ****************
'********************************************
Private Sub UserForm_Initialize()
For Each blockZ In ThisDrawing.Blocks
    Lblockname = Left(blockZ.Name, 1): Lblockname2 = Left(blockZ.Name, 2)
        If Lblockname <> "_" And Lblockname <> "*" And Lblockname2 <> "A$" Then
            With BlockNameCMBO
            .AddItem (blockZ.Name)
        End With
    End If
Next
End Sub
'********************************************
'*************** FORM LOAD ****************
'********************************************

'********************************************
'*************** FORM UNLOAD ****************
'********************************************
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
response = MsgBox("Are you sure you've finished with the 'Block Counter program?..", vbQuestion + vbYesNo, "End the Program..")
    If response = vbNo Then
    Cancel = 1
    End If
    If response = vbYes Then
        Unload Me
    End If
End Sub
'********************************************
'************* END FORM UNLOAD **************
'********************************************

Like Bryco said, your filter pairs were off a little, but I fixed it.  I also changed the names of some of your vars because it was way too confusing using a var with a sset of the same name
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)

hardwired

  • Guest
Re: Simple BlockCounter won't count..
« Reply #4 on: April 17, 2008, 10:27:12 AM »
Thanks guys,

Thats the fella, i couldn't see that for looking, but its obvious when you pointed it, but runs as i want it now, thanks..

Oh and yeah thats cool, i only uploaded the whole dvb as it had a userform and thought it would be quicker for ppl to test that way, but yeah you're right..


Thanks both of you..

Joro--

  • Guest
Re: Simple BlockCounter won't count..
« Reply #5 on: April 18, 2008, 04:07:30 PM »
Can someone tell me where can I see how to use FilterCode and FilterData as in the code attached to this post. I seem to understand the main idea but how can i use this approach to generate a sellection of objects based on Layers or ObjectNames or other... Thanks.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Simple BlockCounter won't count..
« Reply #6 on: April 18, 2008, 05:35:19 PM »
Have a read through DXF Reference in the developer documentation in help and you'll find out a bit about dxf codes.
Vba gives allows a limited access to these codes using FilterCodes and FilterData.
They must always be in pairs, one code and one data.
Someone with a bit more time may give you a better explanation.
I think CmdrDuh wrote some good pieces on this subject.

Joro--

  • Guest
Re: Simple BlockCounter won't count..
« Reply #7 on: April 19, 2008, 02:39:08 AM »
Thanks Btyco,

I found some sample code. Byt is there any way the SelectionSet to remain selected after the end of the procedure so I can perform other operations on it manually?

Fatty

  • Guest
Re: Simple BlockCounter won't count..
« Reply #8 on: April 19, 2008, 08:27:13 AM »
You can take a look at this page (this is a site of my friend):
http://www.cadforyou.spb.ru/index.php?current_section=section_programs_page

search for CountBlocks project, scroll down about
half of the page

~'J'~