PickfirstSelectionSet problem

PickfirstSelectionSet problem

Anonymous
Not applicable
739 Views
10 Replies
Message 1 of 11

PickfirstSelectionSet problem

Anonymous
Not applicable
Consider the following:

Dim objSS as AcadSelectionSet
Set objSS = Thisdrawing.PickfirstSelectionSet
...rest of code

This runs fine in a drawing. I then open another drawing and run the code in
it, works fine.
Then I go back to the previous drawing and run it again....
I get an error:

Run-time error '2145320949 (8021000b)':
Calling method AddItems of interface IAcadSelectionSet failed

It's as though VBA is getting confused between the 2 open drawings.
Has anyone else encountered this? If so what did you do?
I also get a similar error (something,something... IAcadSelectionSet failed)
sometimes with regular on screen selections too.

TIA,
Chad.
0 Likes
740 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Is the objSS variable local to a function or does it
have module-scope ? What does "...rest of code" do?

I just ran this simple test in multiple documents
(starting the macro using VL-VBARUN as well as with
vla-runmacro), and in both cases I have not seen
any problem like you have.

Public Sub Test()
Dim ss As AcadSelectionSet
Set ss = ThisDrawing.PickfirstSelectionSet
ss.SelectOnScreen
If ss.Count = 0 Then Exit Sub
Dim Ent As AcadEntity
For Each Ent In ss
Ent.Color = acRed
Next Ent
End Sub


What I can tell you, is that you probably should
not keep a global reference to a variable that is
assigned to the PickFirstSelectionSet property of
a document.

"Chad" wrote in message
news:A91DC03E8923A8E2918CC3EE912F3356@in.WebX.maYIadrTaRb...
> Consider the following:
>
> Dim objSS as AcadSelectionSet
> Set objSS = Thisdrawing.PickfirstSelectionSet
> ...rest of code
>
> This runs fine in a drawing. I then open another drawing and run the code
in
> it, works fine.
> Then I go back to the previous drawing and run it again....
> I get an error:
>
> Run-time error '2145320949 (8021000b)':
> Calling method AddItems of interface IAcadSelectionSet failed
>
> It's as though VBA is getting confused between the 2 open drawings.
> Has anyone else encountered this? If so what did you do?
> I also get a similar error (something,something... IAcadSelectionSet
failed)
> sometimes with regular on screen selections too.
>
> TIA,
> Chad.
>
>
0 Likes
Message 3 of 11

Anonymous
Not applicable
Tony,

Thanks for taking the time to give it a go for me.
I ran the code below and still got the same result. I even unloaded all
other custom apps I had running.
I'm trying this on 2002. If at least one other person reading this could
give it a go, it would be appreciated.
If it's just me that's having the problem, I might try re-installing
AutoCAD.

Thanks,
Chad.
0 Likes
Message 4 of 11

Anonymous
Not applicable
ran Tony's code, runs like a top in 2ki

Chad wrote:

> Tony,
>
> Thanks for taking the time to give it a go for me.
> I ran the code below and still got the same result. I even unloaded all
> other custom apps I had running.
> I'm trying this on 2002. If at least one other person reading this could
> give it a go, it would be appreciated.
> If it's just me that's having the problem, I might try re-installing
> AutoCAD.
>
> Thanks,
> Chad.
0 Likes
Message 5 of 11

Anonymous
Not applicable
works here, but just a2ki so maybe 2k2?

"Chad" wrote in message
> I'm trying this on 2002. If at least one other person reading this could
> give it a go, it would be appreciated.
0 Likes
Message 6 of 11

Anonymous
Not applicable
"Chad" wrote in message
news:DE54537D0355ACC659C05AE780777511@in.WebX.maYIadrTaRb...
>
> I ran the code below and still got the same result.

What code is that?
0 Likes
Message 7 of 11

Anonymous
Not applicable
I tried it in 2002 also, and had no problem like this.

Can you tell me how you're starting the macro?

"Chad" wrote in message
news:DE54537D0355ACC659C05AE780777511@in.WebX.maYIadrTaRb...
> Tony,
>
> Thanks for taking the time to give it a go for me.
> I ran the code below and still got the same result. I even unloaded all
> other custom apps I had running.
> I'm trying this on 2002. If at least one other person reading this could
> give it a go, it would be appreciated.
> If it's just me that's having the problem, I might try re-installing
> AutoCAD.
>
> Thanks,
> Chad.
>
>
>
>
0 Likes
Message 8 of 11

Anonymous
Not applicable
don't know if this is related but after trying your (tony's) code several
times on several dwgs, I closed acad and came back in through a shortcut on
my desktop which has a .dvb I've been working on as a startup file - that is
in the Target box I have this: "C:\Program Files\ACAD2000\acad.exe"
"C:\0\vb\pieceticket\rect411.dvb"
Acad tried to start then bombed and I got a ms c++ error - abnormal program
termination(or something like that)
I thought, oh no, what have I done now. I tried it several times and each
time the same thing.
I was getting really worried then tried a shortcut without the dvb start
file and it opened ok.
Then tried the dvb shortie again and still no go, then I took the dvb line
out of the target box and it started okay, then I put the dvb line back in
the target and alls well again.
So how's that for weird???

"Tony Tanzillo" wrote in message
0 Likes
Message 9 of 11

Anonymous
Not applicable
ps, I was running the code from vbaide.
after reading about your using vl-vbarun, i went to acad to make a
toolbutton to call the sub
and while making the toolbar button and setting the macro something happened
and acad crashed---thats why I had to come back into it with the
shortcut...and that's when all hell broke loose...
0 Likes
Message 10 of 11

Anonymous
Not applicable
Whooops, I removed it by mistake.

The code I was referring to was your sample as posted earlier
and I am running it from the Macros run dialog, and still no go.
This is really bizare. I think after everyone elses results I might
re-install.

Thanks,
Chad.

"Tony Tanzillo" wrote in message
news:43F63648140FB99EC7BA41075760F3E3@in.WebX.maYIadrTaRb...
> "Chad" wrote in message
> news:DE54537D0355ACC659C05AE780777511@in.WebX.maYIadrTaRb...
> >
> > I ran the code below and still got the same result.
>
> What code is that?
>
>
>
>
0 Likes
Message 11 of 11

Anonymous
Not applicable
I think I have found a workaround and am curious if this will work in general or just in our specific case.

It appears in my case that having an object selected and then opening a drawing from the file/open menu but then cancelling out of it causes the count field in PickFirstSelectionSet to get corrupted.
So what I did was capture the runtime error that gets thrown when PickFirstSelectionSet gets corrupted and have this in my error handling code.

Dim sSets As AcadSelectionSets
Set sSets = ThisDrawing.SelectionSets
sSets.Item("PICKFIRST").Delete
ThisDrawing.PickFirstSelectionSet

What is weird is that not only does this delete the corrupted PickFirstSelectionSet, but it magically gets recreated immediately with the correct count field and all the correct objects that were in there originally. I am not sure how it can repopulate itself but I guess when it gets deleted and created again it goes through the drawing and repopulates itself with any selected objects.
If you try this let me the result as I am curious if it works on other systems. We are running AC 2007.
Regards,
Paul
0 Likes