VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Object open for read only/remove lock?

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
299 Views, 3 Replies

Object open for read only/remove lock?

I've got this message a few times now in my VBA programs, and I think I have figured out what the problem is. For me it occurs whenever I my programs error/crash in the middle of editing object data (AutoCAD Map 2000i), and I am trying to figure out a way to remove the lock so I can get in and change a object's property. Anyone know how to remove an erroneous object lock?
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

"doormat" wrote in message
news:f089f7d.-1@WebX.maYIadrTaRb...
>> I've got this message a few times now in my VBA programs,
>> and I think I have figured out what the problem is. For me it
>> occurs whenever I my programs error/crash in the middle
>> of editing object data (AutoCAD Map 2000i), and I am trying
>> to figure out a way to remove the lock so I can get in and
>> change a object's property. Anyone know how to remove
>> an erroneous object lock?

Hi,

It's tough to tell if the "lock" you're describing is
a Map object lock or if you're seeing some sort
of an ARX error.

Could you describe the exact scenario and
results or show us some example code? Also,
Is the entity in question already in the Map
saveset?

Cheers-

rdh.
Message 3 of 4
Anonymous
in reply to: Anonymous

I dont believe it is a Map Save Set lock. I have had this error occur without a discernable patern, but I have also replicated it in a controlled environment. For now, I'll focus on the controlled environment, although I would eventually like to figure out what is causing the seemingly random occurances. Basically, what I do is a use the following code to iterate through an object's Object Data records for a particular table..

Public Sub test()

Dim AcadApp, AcadMap, acadmapproject, ODTables1
Dim AcadObj
Dim ODT_pipeline As ODtable
Dim BadObj As Boolean
Dim RecordIterator, ODRec, counter, CurTable, CurRecord
Dim Uid As Long

Set AcadApp = ThisDrawing.Application
Set AcadMap = AcadApp.GetInterfaceObject("AutoCADMap.Application")
Set acadmapobject = AcadMap.Projects(ThisDrawing)
Set ODTables1 = acadmapobject.ODTables

For Each selset In ThisDrawing.SelectionSets
If selset.name = "Chkproj" Then Exit For Else Set selset = Nothing
Next
If selset Is Nothing Then Set selset = ThisDrawing.SelectionSets.Add("Chkproj")

selset.Clear
selset.Select acSelectionSetAll

Set ODT_pipeline = ODTables1.item("Pipe")

For Each AcadObj In selset
If AcadObj.layer = "PIPE" Then
Set RecordIterator = ODT_pipeline.GetODRecords
RecordIterator.init AcadObj, False, False
If RecordIterator.IsDone Then BadObj = True 'flag object as bad
Do Until RecordIterator.IsDone
Set ODrecord = RecordIterator.Record
For counter = 0 To ODrecord.Count - 1
Set CurTable = ODT_pipeline.ODFieldDefs.item(counter)
Set CurRecord = ODrecord.item(counter)
If LCase(CurTable.name) = "idfeature" Then Uid = Val(CurRecord.Value)
Next
RecordIterator.Next
Loop
'Set RecordIterator = Nothing 'release the RecordIterator lock on objects
If BadObj = True Or Uid = 0 Then AcadObj.Color = acRed
End If
Next

End Sub

Now here is the thing.. if I stop the VBA code while its iterating through the set, or if I comment out the Set Rec.. = nothing line of code, then there is a lock placed on the object, and when I try to go and edit that object, say change its color or layer from VBA, I get the object open for read error. But yet, I can still go into AutoCAD and change the color of the object "by hand" as it were. My question is there any way that I can remove this lock so if i get an 'object was open for read' error, I can handle the error. I have attached the DWG file that I used to replicate the problem with the code above. Thank you for all your help.

Anthony Fiti
Las Vegas Valley Water District
Message 4 of 4
Anonymous
in reply to: Anonymous

"doormat" wrote in message
news:f089f7d.1@WebX.maYIadrTaRb...
> I dont believe it is a Map Save Set lock. I have had this error occur
without a discernable
> patern, but I have also replicated it in a controlled environment. For
now, I'll focus on the
> controlled environment, although I would eventually like to figure out
what is causing the
> seemingly random occurances. Basically, what I do is a use the following
code to iterate
> through an object's Object Data records for a particular table..
> ...
> selset.Clear
> selset.Select acSelectionSetAll
> Set ODT_pipeline = ODTables1.item("Pipe")
> For Each AcadObj In selset
> If AcadObj.layer = "PIPE" Then
> Set RecordIterator = ODT_pipeline.GetODRecords
> RecordIterator.init AcadObj, False, False
> If RecordIterator.IsDone Then BadObj = True 'flag object as bad
> Do Until RecordIterator.IsDone
> Set ODrecord = RecordIterator.Record
> For counter = 0 To ODrecord.Count - 1
> Set CurTable = ODT_pipeline.ODFieldDefs.item(counter)
> Set CurRecord = ODrecord.item(counter)
> If LCase(CurTable.name) = "idfeature" Then Uid =
Val(CurRecord.Value)
> Next
> RecordIterator.Next
> Loop
> 'Set RecordIterator = Nothing 'release the RecordIterator lock on
objects
> If BadObj = True Or Uid = 0 Then AcadObj.Color = acRed
> End If
> Next
> End Sub
> Now here is the thing.. if I stop the VBA code while its iterating through
the set, or if I
> comment out the Set Rec.. = nothing line of code, then there is a lock
placed on the
> object, and when I try to go and edit that object, say change its color or
layer from VBA,
> I get the object open for read error. But yet, I can still go into AutoCAD
and change the
> color of the object "by hand" as it were. My question is there any way
that I can remove
> this lock so if i get an 'object was open for read' error, I can handle
the error. I have
> attached the DWG file that I used to replicate the problem with the code
above. Thank
> you for all your help.

Hello Anthony,

Thanks for the isolated example.

Your diagnosis is correct. The ODRecordIterator holds an object
open (in either read or write mode) until it is released. During this
period no other object writes are possible without incurring the
exception you note.

It's frustrating, I know. We may consider reworking this area for
our next revision of this API to relax some of these requirements.
In the meantime your only option is to release the iterator prior
to any other object access. This is trivial in your example, but
give me some specifics if you're having trouble in a real app.
I may be able to help.

As to seeing the exception in more general cases - I haven't heard
of a more systemic problem (and believe me, I see most of the
defects on the Map APIs). If you see it again try and break into
your code and figure out what was generally going on. Shoot me
another note with any of your findings so that we can try and replicate
the scenario.

Cheers-

rdh.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost