'obejct was open for read' Please help

'obejct was open for read' Please help

Anonymous
Not applicable
790 Views
18 Replies
Message 1 of 19

'obejct was open for read' Please help

Anonymous
Not applicable
hi

i have a routine that attaches xdata to a block. i also have a
'acadobject_modified' event that if i move the block is supposed to update
that xdata with the new block position, the problem is that when i go to
'setXdata' an error msg is displayed with 'object was open for read'....
firstly, what does this mean? secondly, is there a way around this???

thanks in advance

cheers

mark
0 Likes
791 Views
18 Replies
Replies (18)
Message 2 of 19

Anonymous
Not applicable
It means that you are receiving the 'acadobject_modified' notification while
the block reference is in the process of being updated (moved). Therefore
the object (block reference) is not able to be modified at that moment.

You can probably accomplish what you are after by recording the ObjectId of
the block reference in a global variable in the 'acadobject_modified' event.
Then, in the 'end_command' event, you could use
ThisDrawing.ObjectIDToObject() on the stored ObjectId to get a reference to
the block reference and update the xdata.


"Mark Dubbelaar" wrote in message
news:6660E2963421F87FDB79CE6DB68CF921@in.WebX.maYIadrTaRb...
> hi
>
> i have a routine that attaches xdata to a block. i also have a
> 'acadobject_modified' event that if i move the block is supposed to update
> that xdata with the new block position, the problem is that when i go to
> 'setXdata' an error msg is displayed with 'object was open for read'....
> firstly, what does this mean? secondly, is there a way around this???
>
> thanks in advance
>
> cheers
>
> mark
>
>
0 Likes
Message 3 of 19

Anonymous
Not applicable
Not easily. You might try using an extension dictionary
with an XRecord, since that's a separate object that
can be opened from its owner's ObjectModified event
handler.

"Mark Dubbelaar" wrote in message news:6660E2963421F87FDB79CE6DB68CF921@in.WebX.maYIadrTaRb...
> hi
>
> i have a routine that attaches xdata to a block. i also have a
> 'acadobject_modified' event that if i move the block is supposed to update
> that xdata with the new block position, the problem is that when i go to
> 'setXdata' an error msg is displayed with 'object was open for read'....
> firstly, what does this mean? secondly, is there a way around this???
>
> thanks in advance
>
> cheers
>
> mark
>
>
0 Likes
Message 4 of 19

Anonymous
Not applicable
Can you not use dxf-code 1011, which is World Space Position?

--
R. Robert Bell, MCSE
www.AcadX.com


"Mark Dubbelaar" wrote in message
news:6660E2963421F87FDB79CE6DB68CF921@in.WebX.maYIadrTaRb...
| hi
|
| i have a routine that attaches xdata to a block. i also have a
| 'acadobject_modified' event that if i move the block is supposed to update
| that xdata with the new block position, the problem is that when i go to
| 'setXdata' an error msg is displayed with 'object was open for read'....
| firstly, what does this mean? secondly, is there a way around this???
|
| thanks in advance
|
| cheers
|
| mark
|
|
0 Likes
Message 5 of 19

Anonymous
Not applicable
Hi Mark,
I had in the past considered keeping some data with a block and at first was
thinking to include the position in the list of xdata also.
Then I realized the block already carries all it's "self information"
including it's position in it's own entity list, and since I would have
needed to get that entity list to get it's xdata anyway, I decided I was
overcomplicating what I wanted to do...
Don't know what your plans are or if that makes any sense to you in the
context of your routine or not, but just thought I'd share my
thoughts...(for what it's probably *not* worth!)

other Mark

"Mark Dubbelaar" wrote in message
news:6660E2963421F87FDB79CE6DB68CF921@in.WebX.maYIadrTaRb...
> hi
>
if i move the block is supposed to update
> that xdata with the new block position,
0 Likes
Message 6 of 19

Anonymous
Not applicable
Mark,
1. There should really be no need to store xdata regarding the
block's position since it is relatively easy to access the insertion
point (DXF code 10)
2. There should be no need to update xdata relating to the postion
of the block since if you store the xdata under the code that Robert Bell
mentioned it is updated automatically.
3. If you really want to do this, the error comes from the fact
that you can not modify an object during the object modified event.
You must set a flag and then use another reactor (such as the
command ended reactor) to make the xdata change. The command_ended
reactor should set a flag that can be read by your object modified reactor
so that it ignores the xdata change.


"Mark Dubbelaar" wrote in message
news:6660E2963421F87FDB79CE6DB68CF921@in.WebX.maYIadrTaRb...
> hi
>
> i have a routine that attaches xdata to a block. i also have a
> 'acadobject_modified' event that if i move the block is supposed to update
> that xdata with the new block position, the problem is that when i go to
> 'setXdata' an error msg is displayed with 'object was open for read'....
> firstly, what does this mean? secondly, is there a way around this???
>
> thanks in advance
>
> cheers
>
> mark
>
>
0 Likes
Message 7 of 19

Anonymous
Not applicable
not to sure who i should reply too.....

what i am trying to achieve is a block which is 'attached' to a viewport...
by this i mean that when the user moves the viewport i won't the block to
move in a relative position, so what i am trying to do, is save the relative
position (distance, angle) to the viewport centre and then when the object
modified event is triggered, get the new viewport centre and move the block
accordingly...
the 'object was open for read' happens when i move the block instead of the
viewport, and using the object modified event again, save the new relative
location in the xdata of the block....

i have another question regarding the 'object_modified' event... if i zoom /
pan in the viewport the object_modified event is not triggered.... i'm
assuming you can use the endcommand event to trap this, but i was wondering
why the object_modified event is not triggered???

cheers, and thanks for the advice

mark

"Doug Broad" wrote in message
news:9DB683FF48BE98DC54A60C64EC5BFD29@in.WebX.maYIadrTaRb...
> Mark,
> 1. There should really be no need to store xdata regarding the
> block's position since it is relatively easy to access the insertion
> point (DXF code 10)
> 2. There should be no need to update xdata relating to the postion
> of the block since if you store the xdata under the code that Robert Bell
> mentioned it is updated automatically.
> 3. If you really want to do this, the error comes from the fact
> that you can not modify an object during the object modified event.
> You must set a flag and then use another reactor (such as the
> command ended reactor) to make the xdata change. The command_ended
> reactor should set a flag that can be read by your object modified reactor
> so that it ignores the xdata change.
>
>
> "Mark Dubbelaar" wrote in message
> news:6660E2963421F87FDB79CE6DB68CF921@in.WebX.maYIadrTaRb...
> > hi
> >
> > i have a routine that attaches xdata to a block. i also have a
> > 'acadobject_modified' event that if i move the block is supposed to
update
> > that xdata with the new block position, the problem is that when i go to
> > 'setXdata' an error msg is displayed with 'object was open for read'....
> > firstly, what does this mean? secondly, is there a way around this???
> >
> > thanks in advance
> >
> > cheers
> >
> > mark
> >
> >
>
>
0 Likes
Message 8 of 19

Anonymous
Not applicable
I've never done any Event programming in ACAD, but to me it seems like you
need to separate your data a little so that when you move the block, you
change data on the VPORT object, and vice versa. The way I would do that
(and I think save you from having to do distance / angle calc's) would be to
store the current VPORT center in the block object's data. That way, if you
move the block, nothing happens (the VPORT has not moved). If you move the
VPORT, in the Modified event that fires AFTER the move is done, move the
block by the vector
old X, Y, Z stored in block data --> new X, Y, Z taken from Viewport
object
and in the same event, store the new VPORT X, Y, Z in the block's data (i.e.
new XYZ becomes old XYZ).

In code it would be something like:
Dim oBlock as AcadBlock 'module level
dim oVP as AcadViewport 'module level

Sub Object_Modified (obj as Object):
if obj = oVP
oBlock.Move ...
oblock.SetXData ...
endif
end sub

Sub Drawing_Initialize ' or whatever runs when you open a drawing
Set oBlock = ...
Set oVP = ...
end sub

If the module-level objects won't stay in memory between event calls, you
might be able to make them Static variables within the event (again... no
ACAD event programming experience here, just thoughts). The key is to give
the viewport some way to remember which block it's supposed to be
reading/writing to.

In a nutshell, the whole point of my post is to avoid having an object
modify itself... hope this helps.

James
0 Likes
Message 9 of 19

Anonymous
Not applicable
Hi Mark,

I'm not an AutoCAD guy, but aren't there things called AutoCAD groups which
allow you to move objects as a group ?

In that case all you need do is create a group of your block and the Vport
and move the group.

--


Laurie Comerford
CADApps
www.cadapps.com.au

"Mark Dubbelaar" wrote in message
news:156EAFAC382FBCCCB65121E84B4DD4B7@in.WebX.maYIadrTaRb...
> not to sure who i should reply too.....
>
> what i am trying to achieve is a block which is 'attached' to a
viewport...
> by this i mean that when the user moves the viewport i won't the block to
> move in a relative position, so what i am trying to do, is save the
relative
> position (distance, angle) to the viewport centre and then when the object
> modified event is triggered, get the new viewport centre and move the
block
> accordingly...
> the 'object was open for read' happens when i move the block instead of
the
> viewport, and using the object modified event again, save the new relative
> location in the xdata of the block....
>
> i have another question regarding the 'object_modified' event... if i zoom
/
> pan in the viewport the object_modified event is not triggered.... i'm
> assuming you can use the endcommand event to trap this, but i was
wondering
> why the object_modified event is not triggered???
>
> cheers, and thanks for the advice
>
> mark
>
> "Doug Broad" wrote in message
> news:9DB683FF48BE98DC54A60C64EC5BFD29@in.WebX.maYIadrTaRb...
> > Mark,
> > 1. There should really be no need to store xdata regarding the
> > block's position since it is relatively easy to access the insertion
> > point (DXF code 10)
> > 2. There should be no need to update xdata relating to the postion
> > of the block since if you store the xdata under the code that Robert
Bell
> > mentioned it is updated automatically.
> > 3. If you really want to do this, the error comes from the fact
> > that you can not modify an object during the object modified event.
> > You must set a flag and then use another reactor (such as the
> > command ended reactor) to make the xdata change. The command_ended
> > reactor should set a flag that can be read by your object modified
reactor
> > so that it ignores the xdata change.
> >
> >
> > "Mark Dubbelaar" wrote in message
> > news:6660E2963421F87FDB79CE6DB68CF921@in.WebX.maYIadrTaRb...
> > > hi
> > >
> > > i have a routine that attaches xdata to a block. i also have a
> > > 'acadobject_modified' event that if i move the block is supposed to
> update
> > > that xdata with the new block position, the problem is that when i go
to
> > > 'setXdata' an error msg is displayed with 'object was open for
read'....
> > > firstly, what does this mean? secondly, is there a way around this???
> > >
> > > thanks in advance
> > >
> > > cheers
> > >
> > > mark
> > >
> > >
> >
> >
>
>
0 Likes
Message 10 of 19

arcticad
Advisor
Advisor
This is a General Program for modifying Objects that have been modified, It Creates an array of all the Handles then acts on those objects in endcommand

Dim Gvar As Variant
Dim Gcheck As Boolean

Private Sub AcadDocument_ObjectModified(ByVal object As Object)
If Gcheck = True Then Exit Sub
Gvar = code.inc(Gvar)
Gvar(UBound(Gvar)) = object.handle
End Sub

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
Dim handle As Variant
On Error GoTo theend
Gcheck = True
For Each handle In Gvar
Set object = ThisDrawing.HandleToObject(handle)
'do stuff to the object
Next
theend:
Gcheck = False
Set Gvar = Nothing
End Sub

Function inc(myarray As Variant) As Variant
Dim temparray() As Variant
If isArrayValid(myarray) Then
ReDim Preserve myarray(UBound(myarray) + 1)
Else
ReDim myarray(0)
End If
inc = myarray
End Function

Function isArrayValid(myarray As Variant) As Boolean
On Error GoTo theend
Dim item As Variant
For Each item In myarray
isArrayValid = True
Exit Function
Next
theend:
isArrayValid = False
End Function
---------------------------



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

Anonymous
Not applicable
Based on the subject line "Object was open for read" and the code you have
shown in the event handler(s) it appears that you may be trying to modify
the object that triggered the event.


AutoCAD 2004 Developer Help > Use Events > Guidelines for Event Handlers

You can write data to any object in the database, except the object that
issued the event.

Obviously, any object causing an event to be triggered could still be open
for use with
AutoCAD and the operation currently in progress. Therefore, avoid writing
any information
to an object from an event handler for the same object.


If you put the snip below in the "ObjectModified" event it will give the
error you see. It violates the rule (above) and trys to modify the object
that has triggered the event.

Private Sub AcadDocument_ObjectModified(ByVal Object As Object)

Object.color = acRed

End Sub

You will have to make whatever modification you are attempting after you
exit the event handler(s)

HTH,

Gary




wrote in message news:4849483@discussion.autodesk.com...
This is a General Program for modifying Objects that have been modified, It
Creates an array of all the Handles then acts on those objects in endcommand

Dim Gvar As Variant
Dim Gcheck As Boolean

Private Sub AcadDocument_ObjectModified(ByVal object As Object)
If Gcheck = True Then Exit Sub
Gvar = code.inc(Gvar)
Gvar(UBound(Gvar)) = object.handle
End Sub

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
Dim handle As Variant
On Error GoTo theend
Gcheck = True
For Each handle In Gvar
Set object = ThisDrawing.HandleToObject(handle)
'do stuff to the object
Next
theend:
Gcheck = False
Set Gvar = Nothing
End Sub

Function inc(myarray As Variant) As Variant
Dim temparray() As Variant
If isArrayValid(myarray) Then
ReDim Preserve myarray(UBound(myarray) + 1)
Else
ReDim myarray(0)
End If
inc = myarray
End Function

Function isArrayValid(myarray As Variant) As Boolean
On Error GoTo theend
Dim item As Variant
For Each item In myarray
isArrayValid = True
Exit Function
Next
theend:
isArrayValid = False
End Function
0 Likes
Message 12 of 19

arcticad
Advisor
Advisor
The Program just gathers up the information from the modified event.

It doesn't try to change anything.

The Handles are stored in a Global Variable Array.

Then the EndCommand Event Gets the List and Makes the Changes.

This doesn't violate anything.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 13 of 19

Anonymous
Not applicable
I hope I didn't mislead you.

Your comment " 'do stuff to the object" in the EndCommand event suggested
that you were attempting modification.

Gary
0 Likes
Message 14 of 19

Anonymous
Not applicable
>>Then the EndCommand Event Gets the List and Makes the Changes.

The above assumes that the events occur as one would be led to believe:

Begin_Command
Object_Modified
End_Command

Not always true.

(Same help section cited previously:)

Do not rely on the sequence of events.

Gary
0 Likes
Message 15 of 19

arcticad
Advisor
Advisor
Yes I Agree that the documentation says you can not rely on the sequence of events. However I have never seen a time when object modified event was triggered after the command finished.

If you can give me a way to show this i would be very interested.

Thank you.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 16 of 19

Anonymous
Not applicable
Object Modified could be getting triggered before the End Command but hasn't
finished modifying the object. Thus the error "object was open for read".

I don't know how you could prove it other than passing your array to a sub
outside of the event handler to see if the problem goes away. If you are
doing extensive mods to the object maybe you could temporarily change it to
something simple to see if the problem goes away.

Gary



wrote in message news:4854763@discussion.autodesk.com...
Yes I Agree that the documentation says you can not rely on the sequence of
events. However I have never seen a time when object modified event was
triggered after the command finished.

If you can give me a way to show this i would be very interested.

Thank you.
0 Likes
Message 17 of 19

Anonymous
Not applicable
I am recieving this same error message 'object was open for read' in AutoCAD 2008 when using annotative objects.

I'm not using any lisp routines of any kind when encountering this problem.

Its also inconsistent, in other words it only happens sometimes, so there has to be something that either I am doing, or the program is doing that is affecting my objects in such a way that its giving me this problem.

as I said, its annotative objects that are giving me the problem. I am unable to move them, rotate them, edit them, or even erase them. they behave almost exactly like an object on a locked layer, except that the layer isn't locked.

So my question here is twofold I suppose:

first off, how do I 'release the lock' for lack of a better term, and secondly, what is causing it to happen.

Thanks for any help you can give.
0 Likes
Message 18 of 19

Anonymous
Not applicable
Can you post some sample code?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5813954@discussion.autodesk.com...
I am recieving this same error message 'object was open for read' in AutoCAD 2008 when using annotative objects.

I'm not using any lisp routines of any kind when encountering this problem.

Its also inconsistent, in other words it only happens sometimes, so there has to be something that either I am doing, or the program is doing that is affecting my objects in such a way that its giving me this problem.

as I said, its annotative objects that are giving me the problem. I am unable to move them, rotate them, edit them, or even erase them. they behave almost exactly like an object on a locked layer, except that the layer isn't locked.

So my question here is twofold I suppose:

first off, how do I 'release the lock' for lack of a better term, and secondly, what is causing it to happen.

Thanks for any help you can give.
0 Likes
Message 19 of 19

Anonymous
Not applicable
Anyone have an answer yet? Annotative is great untill OPEN FOR READ pops up. The only solution I have found is to save and reopen and wait for it to happen again.
0 Likes