List names of BlkRefs selected.

List names of BlkRefs selected.

Anonymous
Not applicable
938 Views
20 Replies
Message 1 of 21

List names of BlkRefs selected.

Anonymous
Not applicable
After typing all this i was begining to think it was long-winded so I'll trying to simplify here. I have an string array that contains block.names some of these substrings are the same. I want to filter this array so there's only one of each substring.

I think I found a function to help me:
Filter(sourcesrray, match[, include[, compare]])
but I'm unsure on how to implement it.

Long Version:
First I'll explain the "work-around" I have implemented so maybe you can see what i'm trying to do.

I have this tool that skips through blocks of the same name, zooming into each one individualy. The user can select which block he/she wants from a ComboBox that contains a list of blocks defined.

I get this list by iterating throught the Blocks collection, which shows blocks defined in the WHOLE drawing, and add Block.Names to a string array ONLY if there is a reference to it on the ActiveLayout. which means I have to make a SelectionSet of EVERY block defined in the drawing, filter that SelectionSet, and then if the SelSet.Count <> 0, I add that Block Name to the array. In a drawing with 150+ different blocks defined this is very inefficient and sloppy, but it's working.

Now I have the time and want to spruce this thing up a bit and I've come to a roadblock.

Instead of using the Blocks Collection i'm letting the user select the block refs to list. So the user makes this SelSet containing mutiple copies of, say, ten different block defintions. So I have this potential list but some blocks are listed many times. I need to widdle this down to one Block.Name string for each block in this array and then I can add it to the ComboBox.
0 Likes
939 Views
20 Replies
Replies (20)
Message 2 of 21

Anonymous
Not applicable
Well, don't use an array.

If you use a scripting dictionary, you can On Error Resume Next on the error
when attempting to add an item that already exists, and then use the Keys
method to feed the ComboBox. Obviously create a function to attempt the Add,
due to the On Error.



--
R. Robert Bell


wrote in message news:5417239@discussion.autodesk.com...
After typing all this i was begining to think it was long-winded so I'll
trying to simplify here. I have an string array that contains block.names
some of these substrings are the same. I want to filter this array so
there's only one of each substring.

I think I found a function to help me:
Filter(sourcesrray, match[, include[, compare]])
but I'm unsure on how to implement it.

Long Version:
First I'll explain the "work-around" I have implemented so maybe you can see
what i'm trying to do.

I have this tool that skips through blocks of the same name, zooming into
each one individualy. The user can select which block he/she wants from a
ComboBox that contains a list of blocks defined.

I get this list by iterating throught the Blocks collection, which shows
blocks defined in the WHOLE drawing, and add Block.Names to a string array
ONLY if there is a reference to it on the ActiveLayout. which means I have
to make a SelectionSet of EVERY block defined in the drawing, filter that
SelectionSet, and then if the SelSet.Count <> 0, I add that Block Name to
the array. In a drawing with 150+ different blocks defined this is very
inefficient and sloppy, but it's working.

Now I have the time and want to spruce this thing up a bit and I've come to
a roadblock.

Instead of using the Blocks Collection i'm letting the user select the block
refs to list. So the user makes this SelSet containing mutiple copies of,
say, ten different block defintions. So I have this potential list but some
blocks are listed many times. I need to widdle this down to one Block.Name
string for each block in this array and then I can add it to the ComboBox.
0 Likes
Message 3 of 21

Anonymous
Not applicable
I was afraid this might happen. I don't know what a scripting dictionary is. I wouldn't say I'm absolute beginner when it comes to VBA customization, but I not exactly a pro. Basically I've learned to get a round using Help. And according to Help, ComboBox doesn't have a Keys method.

Would you bother to tell me if I'm on the right track with the Filter function?
0 Likes
Message 4 of 21

Anonymous
Not applicable
Sorry I missed the part about not using an array. Ok, what's a scripting dictionary?
0 Likes
Message 5 of 21

Anonymous
Not applicable
It is the Dictionary object that is part of Microsoft's Scripting Runtime.

You add a reference to your project for the runtime, and then you can create
and use the Dictionary. It has the Keys method, which returns an array of
the keys (index) for the items stored in the dictionary.

See attached sample (assumes 2007).

--
R. Robert Bell


wrote in message news:5417325@discussion.autodesk.com...
Sorry I missed the part about not using an array. Ok, what's a scripting
dictionary?
0 Likes
Message 6 of 21

Anonymous
Not applicable
I get an runtime error(see attached), I think this is because ComboBox.List is expecting a variant array.
0 Likes
Message 7 of 21

Anonymous
Not applicable
No, that error is coming from an attempt to set the list index, i.e.
selecting the first item.

Just remove, or comment out, the line that does that. I suspect you are
running the code on a layout with no blocks inserted.

--
R. Robert Bell


wrote in message news:5418427@discussion.autodesk.com...
I get an runtime error(see attached), I think this is because ComboBox.List
is expecting a variant array.
0 Likes
Message 8 of 21

arcticad
Advisor
Advisor
The value of pBlock.EffectiveName is not valid. Something is a miss.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 9 of 21

Anonymous
Not applicable
Are you running the code in 2007? EffectiveName was part of an interface,
not the BlockReference object, before 2007.

--
R. Robert Bell


wrote in message news:5418877@discussion.autodesk.com...
The value of pBlock.EffectiveName is not valid. Something is a miss.
0 Likes
Message 10 of 21

arcticad
Advisor
Advisor
I'm running in Autocad 2005
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 11 of 21

Anonymous
Not applicable
Then change EffectiveName to just Name. There were no dynamic blocks in
2005, right?

--
R. Robert Bell


wrote in message news:5419449@discussion.autodesk.com...
I'm running in Autocad 2005
0 Likes
Message 12 of 21

Anonymous
Not applicable
Same here. I'm also using 2005.
0 Likes
Message 13 of 21

Anonymous
Not applicable
Again, just change EffectiveName to Name.

And the next time I state that a sample assumes 2007, it would be nice if
you said "there's an error, but I'm running 2005." There just might be a
reason I said the code assumes AutoCAD 2007.

--
R. Robert Bell


wrote in message news:5419723@discussion.autodesk.com...
Same here. I'm also using 2005.
0 Likes
Message 14 of 21

Anonymous
Not applicable
R. Robert Bell wrote:
> Well, don't use an array.
>
> If you use a scripting dictionary, you can On Error Resume Next on the error
> when attempting to add an item that already exists, and then use the Keys
> method to feed the ComboBox. Obviously create a function to attempt the Add,
> due to the On Error.

Instead of using the "tripped up" method of On Error, why not use the
.Exist method that's built in.

If someone's gone to the trouble of programming it, it seems rude not to
use it:

If myBlocks.Exists(aBlock.name) = False Then 'block name not stored

Dave F.
0 Likes
Message 15 of 21

Anonymous
Not applicable
Sounds good to me.

--
R. Robert Bell


"Dave F." wrote in message
news:5420602@discussion.autodesk.com...
R. Robert Bell wrote:

Instead of using the "tripped up" method of On Error, why not use the
.Exist method that's built in.

If someone's gone to the trouble of programming it, it seems rude not to
use it:

If myBlocks.Exists(aBlock.name) = False Then 'block name not stored
0 Likes
Message 16 of 21

Anonymous
Not applicable
Like so...

If Not myBlocks.Exists(aBlock.Name) = False Then
AddBlock myBlocks, aBlock
End If

?
0 Likes
Message 17 of 21

Anonymous
Not applicable
No.

If Not (myBlocks.Exists(aBlock.EffectiveName)) Then _
myBlocks.Add aBlock.EffectiveName, aBlock

or

If Not (myBlocks.Exists(aBlock.EffectiveName)) Then
myBlocks.Add aBlock.EffectiveName, aBlock
End If

--
R. Robert Bell


wrote in message news:5422866@discussion.autodesk.com...
Like so...

If Not myBlocks.Exists(aBlock.Name) = False Then
AddBlock myBlocks, aBlock
End If

?
0 Likes
Message 18 of 21

Anonymous
Not applicable
Of course, change EffectiveName to just Name for AutoCAD 2005.

--
R. Robert Bell


"R. Robert Bell" wrote in message
news:5423098@discussion.autodesk.com...
No.

If Not (myBlocks.Exists(aBlock.EffectiveName)) Then _
myBlocks.Add aBlock.EffectiveName, aBlock

or

If Not (myBlocks.Exists(aBlock.EffectiveName)) Then
myBlocks.Add aBlock.EffectiveName, aBlock
End If
0 Likes
Message 19 of 21

Anonymous
Not applicable
I tryed to incorporated the code into my application, and I get a compile error:
"user-defined type not defined"

with this part of code highlighted:
"myBlocks As New Scripting.Dictionary"
0 Likes
Message 20 of 21

Anonymous
Not applicable
Check your references
you need the scripting runtime

wrote in message news:5423121@discussion.autodesk.com...
I tryed to incorporated the code into my application, and I get a compile
error:
"user-defined type not defined"

with this part of code highlighted:
"myBlocks As New Scripting.Dictionary"
0 Likes