| Author |
Message |
Arnaud Lesauvage
Guest
|
Posted:
Tue Mar 22, 2005 4:01 pm Post subject:
The object disconnected from its clients ! |
|
|
Hi all !
This error raises in Autocad VBA (Autodesk Map 5 SP1) when I call:
Set oAcadLWPolyLine = oAcadEntity.Copy
It does NOT happen if I call "Thisrawing.PurgeAll" before !
Let me first explain what the VBA macro is doing :
The user selects an item in a listbox on a form. The drawing
(opened from a dwt), is "SavedAs" with a name that depends on the
users choice.
There are then 2 queries (Map queries) being run, which draw
entities on the drawing.
This is where I call ThisDrawing.PurgeAll.
Then, I open a selection Set with :
gpCode(0) = 8 : gpValue(0) = myLayer
oSelSet.Select acSelectionSetAll, , , gpCode, gpValue
I then loop through the SelectionSet and do things depending on
the entity's type :
For Each oAcadEntity In oSelSet
Select Case True
Case TypeOf oAcadEntity Is AcadLWPolyline
Set oAcadLWPolyline = oAcadEntity.Copy <- ERROR!!!
Case TypeOf oAcadEntity Is AcadPolyline
Set oAcadPolyline = oAcadEntity.Copy
Case Else
etc ....
End Select
Next oAcadEntity
I ran the macro step by step : oAcadLWPolyline is defined and
equals to nothing (the error raises on the first loop). The
SelectionSet is defined and filled with entities (lwpolylines and
lines, that's good). oAcadEntity's type is AcadLWPolyline.
I really don't understand what's going wrong here !
I need to remove the "PurgeAll", because there are a lot of empty
layers and unused text styles that I need to keep in the drawing.
Can someone help me on this ?
Thanks a lot !
Arnaud Lesauvage
|
|
| Back to top |
|
 |
Joe Sutphin
Guest
|
Posted:
Tue Mar 22, 2005 4:36 pm Post subject:
Re: The object disconnected from its clients ! |
|
|
You cannot execute the Copy method while iterating through a collection.
Joe
--
"Arnaud Lesauvage" <thewild_nospam@freesurf.nospam.fr> wrote in message
news:423ffb0d_1@newsprd01...
| Quote: | Hi all !
This error raises in Autocad VBA (Autodesk Map 5 SP1) when I call:
Set oAcadLWPolyLine = oAcadEntity.Copy
It does NOT happen if I call "Thisrawing.PurgeAll" before !
Let me first explain what the VBA macro is doing :
The user selects an item in a listbox on a form. The drawing (opened from
a dwt), is "SavedAs" with a name that depends on the users choice.
There are then 2 queries (Map queries) being run, which draw entities on
the drawing.
This is where I call ThisDrawing.PurgeAll.
Then, I open a selection Set with :
gpCode(0) = 8 : gpValue(0) = myLayer
oSelSet.Select acSelectionSetAll, , , gpCode, gpValue
I then loop through the SelectionSet and do things depending on the
entity's type :
For Each oAcadEntity In oSelSet
Select Case True
Case TypeOf oAcadEntity Is AcadLWPolyline
Set oAcadLWPolyline = oAcadEntity.Copy <- ERROR!!!
Case TypeOf oAcadEntity Is AcadPolyline
Set oAcadPolyline = oAcadEntity.Copy
Case Else
etc ....
End Select
Next oAcadEntity
I ran the macro step by step : oAcadLWPolyline is defined and equals to
nothing (the error raises on the first loop). The SelectionSet is defined
and filled with entities (lwpolylines and lines, that's good).
oAcadEntity's type is AcadLWPolyline.
I really don't understand what's going wrong here !
I need to remove the "PurgeAll", because there are a lot of empty layers
and unused text styles that I need to keep in the drawing.
Can someone help me on this ?
Thanks a lot !
Arnaud Lesauvage |
|
|
| Back to top |
|
 |
Arnaud Lesauvage
Guest
|
Posted:
Tue Mar 22, 2005 4:45 pm Post subject:
Re: The object disconnected from its clients ! |
|
|
Joe Sutphin wrote:
| Quote: | You cannot execute the Copy method while iterating through a collection.
|
Thanks for your answer Joe.
Why does it work when I purge the drawing ?
|
|
| Back to top |
|
 |
Joe Sutphin
Guest
|
Posted:
Tue Mar 22, 2005 5:35 pm Post subject:
Re: The object disconnected from its clients ! |
|
|
I don't know. Does the routine work the first time through or the second?
Can you post the entire routine?
Joe
--
"Arnaud Lesauvage" <thewild_nospam@freesurf.nospam.fr> wrote in message
news:42400554_1@newsprd01...
| Quote: | Joe Sutphin wrote:
You cannot execute the Copy method while iterating through a collection.
Thanks for your answer Joe.
Why does it work when I purge the drawing ? |
|
|
| Back to top |
|
 |
Arnaud Lesauvage
Guest
|
Posted:
Tue Mar 22, 2005 5:51 pm Post subject:
Re: The object disconnected from its clients ! |
|
|
Joe Sutphin wrote:
| Quote: | I don't know. Does the routine work the first time through or the second?
|
It's a "one shot" routine : it starts in a new drawing and inserts
everything that is needed. The PurgeAll is useless, but it makes
it works...
| Quote: | Can you post the entire routine?
|
I can, but it's kind of huge... I'll post if you want to check for
yourself though !
For the moment, I worked around the problem by removing the
oAcadEntity.Copy as you suggested and by replacing it with
ThisDrawing.ModelSpace.AddLightWeightPolyline(oAcadEntity.Coordinates).
It works fine, but I am still very curious ! |
|
| Back to top |
|
 |
Nathan Taylor
Guest
|
Posted:
Wed Mar 23, 2005 2:55 am Post subject:
Re: The object disconnected from its clients ! |
|
|
I found it odd as to why as Joe pointed out "You cannot execute the Copy method while iterating through a collection.".
This is the full help explanation "NOTE You cannot execute this method while simultaneously iterating through a collection. An iteration will open the work space for a read-only operation, while this method attempts to perform a read-write operation. Complete any iteration before you call this method.".
I would suggest you may be able to iterate the collection adding the items to an array of entities and then process the array. If that doesn't work either you may be able to iterate the collection adding the items handles to an array and then process the array using the HandleToObject method.
Regards - Nathan |
|
| Back to top |
|
 |
James Belshan
Guest
|
Posted:
Wed Mar 23, 2005 3:32 am Post subject:
Re: The object disconnected from its clients ! |
|
|
You wouldn't have to go to the extreme of using handles. I can't replicate
your error on my setup, but I think all you would have to do would be to
replace your "For Each" with a "For i = 0 to ModelSpace.Count-1" type of
loop. This way, when new objects are added to ModelSpace, they will have
higher indices than the original count and won't get reprocessed by the
loop. With a "For Each" loop that makes copies, every time you think you're
getting one item closer to the end of ModelSpace, you're adding another
item... you're on a ModelSpace treadmill.
James
"Nathan Taylor" <nospam@address.withheld> wrote in message
news:26415995.1111528541000.JavaMail.jive@jiveforum1.autodesk.com...
| Quote: | I found it odd as to why as Joe pointed out "You cannot execute the Copy
method while iterating through a collection.".
This is the full help explanation "NOTE You cannot execute this method
while simultaneously iterating through a collection. An iteration will open |
the work space for a read-only operation, while this method attempts to
perform a read-write operation. Complete any iteration before you call this
method.".
| Quote: | I would suggest you may be able to iterate the collection adding the items
to an array of entities and then process the array. If that doesn't work |
either you may be able to iterate the collection adding the items handles to
an array and then process the array using the HandleToObject method.
|
|
| Back to top |
|
 |
Frank Oquendo
Guest
|
Posted:
Wed Mar 23, 2005 3:46 am Post subject:
Re: The object disconnected from its clients ! |
|
|
James Belshan wrote:
| Quote: | replace your "For Each" with a "For i = 0 to ModelSpace.Count-1" type of
loop. This way, when new objects are added to ModelSpace, they will have
higher indices than the original count and won't get reprocessed by the
loop.
|
The Count property will be queried on each iteration so the new objects
will be processed. Either assign the current value of the property to a
variable or use a different collection for the iterating; a selection
set or collection object, for example. |
|
| Back to top |
|
 |
Nathan Taylor
Guest
|
Posted:
Wed Mar 23, 2005 7:00 am Post subject:
Re: The object disconnected from its clients ! |
|
|
Arnaud is actually using a selection set. I think the note in the help may be referring to what your talking about in iterating the modelspace collection. In which case I don't think his problem is to do with the note from the help file.
Regards - Nathan |
|
| Back to top |
|
 |
Jeff Mishler
Guest
|
Posted:
Wed Mar 23, 2005 7:29 am Post subject:
Re: The object disconnected from its clients ! |
|
|
I think that the problem stems from this line:
Set oAcadLWPolyline = oAcadEntity.Copy
since the former is dimensioned as a AcadLWPolyline and the latter is
dimensioned as a AcadEntity, and the copy returns the same object as the
original.
Using this, with the oCopyEntity dimensioned as an AcadEntity works for
me....
Set oCopyEntity = oAcadEntity.Copy
Set oAcadLWPolyline = oCopyEntity
--
Jeff
"Arnaud Lesauvage" <thewild_nospam@freesurf.nospam.fr> wrote in message
news:423ffb0d_1@newsprd01...
| Quote: | Hi all !
This error raises in Autocad VBA (Autodesk Map 5 SP1) when I call:
Set oAcadLWPolyLine = oAcadEntity.Copy
It does NOT happen if I call "Thisrawing.PurgeAll" before !
Let me first explain what the VBA macro is doing :
The user selects an item in a listbox on a form. The drawing (opened from
a dwt), is "SavedAs" with a name that depends on the users choice.
There are then 2 queries (Map queries) being run, which draw entities on
the drawing.
This is where I call ThisDrawing.PurgeAll.
Then, I open a selection Set with :
gpCode(0) = 8 : gpValue(0) = myLayer
oSelSet.Select acSelectionSetAll, , , gpCode, gpValue
I then loop through the SelectionSet and do things depending on the
entity's type :
For Each oAcadEntity In oSelSet
Select Case True
Case TypeOf oAcadEntity Is AcadLWPolyline
Set oAcadLWPolyline = oAcadEntity.Copy <- ERROR!!!
Case TypeOf oAcadEntity Is AcadPolyline
Set oAcadPolyline = oAcadEntity.Copy
Case Else
etc ....
End Select
Next oAcadEntity
I ran the macro step by step : oAcadLWPolyline is defined and equals to
nothing (the error raises on the first loop). The SelectionSet is defined
and filled with entities (lwpolylines and lines, that's good).
oAcadEntity's type is AcadLWPolyline.
I really don't understand what's going wrong here !
I need to remove the "PurgeAll", because there are a lot of empty layers
and unused text styles that I need to keep in the drawing.
Can someone help me on this ?
Thanks a lot !
Arnaud Lesauvage |
|
|
| Back to top |
|
 |
Arnaud Lesauvage
Guest
|
Posted:
Wed Mar 23, 2005 3:24 pm Post subject:
Re: The object disconnected from its clients ! |
|
|
Jeff Mishler wrote:
| Quote: | Using this, with the oCopyEntity dimensioned as an AcadEntity works for
me....
Set oCopyEntity = oAcadEntity.Copy
Set oAcadLWPolyline = oCopyEntity
|
Hi Jeff,
Did he original code raise an error ?
(Set oAcadLWPolyline = oAcadEntity.Copy) |
|
| Back to top |
|
 |
Arnaud Lesauvage
Guest
|
Posted:
Wed Mar 23, 2005 3:29 pm Post subject:
Re: The object disconnected from its clients ! |
|
|
Nathan Taylor wrote:
| Quote: | Arnaud is actually using a selection set. I think the note in the help may be referring to what your talking about in iterating the modelspace collection. In which case I don't think his problem is to do with the note from the help file.
Regards - Nathan
|
Indeed, I am using a Selection Set.
The NOTE in the documentation actually states that what I was
doing was wrong (i.e. using the "copy" method), but the error
message was really surprising !
A "good" error message could have stated that a write operation
could not be performed, for instance.
And furthermore, why can I write to the workspace (if I understand
the meaning of this word) using
ThisDrawing.ModelSpace.AddSomeKindOfEntity(), and not using
oAcadEntity.Copy ?
Arnaud |
|
| Back to top |
|
 |
|
|
|
|