Message 1 of 4
eNotOpenForWrite error adding a layer
Not applicable
10-23-2009
08:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
After opening btr for write (~line 23), btr.AppendEntity(rect) (~line 37) throws an error in AutoCAD: eNotOpenForWrite. Why would this happen and how can I fix it?
Code:
Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Insert.Click
'should be similar to cmdOK_Click()
myDWG = Application.DocumentManager.MdiActiveDocument
myDB = myDWG.Database
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction
Dim point As Point3d, point1 As Point3d, point2 As Point3d, point3 As Point3d, point4 As Point3d, verts As New Point3dCollection, rect As Polyline2d
Me.Hide()
point = myDWG.Editor.GetPoint("INSERTION POINT IS THE LOWER LEFT CORNER OF THE FRAME").Value
If FramingOpts.SelectedIndex > -1 Then
If FramingOpts.SelectedItem.ToString <> "no frame" Then
Select Case FramingOpts.SelectedItem.ToString
Case "4x8"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 96, point1.Y, 0)
point3 = New Point3d(point1.X + 96, point1.Y + 48, 0)
point4 = New Point3d(point1.X, point1.Y + 48, 0)
Case "4x10"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 120, point1.Y, 0)
point3 = New Point3d(point1.X + 120, point1.Y + 48, 0)
point4 = New Point3d(point1.X, point1.Y + 48, 0)
Case "4x12"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 144, point1.Y, 0)
point3 = New Point3d(point1.X + 144, point1.Y + 48, 0)
point4 = New Point3d(point1.X, point1.Y + 48, 0)
Case "5x5"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 60, point1.Y, 0)
point3 = New Point3d(point1.X + 60, point1.Y + 60, 0)
point4 = New Point3d(point1.X, point1.Y + 60, 0)
Case "5x8"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 96, point1.Y, 0)
point3 = New Point3d(point1.X + 96, point1.Y + 60, 0)
point4 = New Point3d(point1.X, point1.Y + 60, 0)
Case "5x10"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 120, point1.Y, 0)
point3 = New Point3d(point1.X + 120, point1.Y + 60, 0)
point4 = New Point3d(point1.X, point1.Y + 60, 0)
End Select
verts.Add(point1)
verts.Add(point2)
verts.Add(point3)
verts.Add(point4)
rect = New Polyline2d(Poly2dType.SimplePoly, verts, 0, False, 0, 0, Nothing)
rect.Closed = True
Dim check As Boolean
check = False
Dim myLT As LayerTable
Dim myLTR As LayerTableRecord
Dim mySTE As SymbolTableEnumerator
myLT = myDB.LayerTableId.GetObject(OpenMode.ForWrite)
mySTE = myLT.GetEnumerator
While mySTE.MoveNext
myLTR = mySTE.Current.GetObject(OpenMode.ForRead)
If UCase(myLTR.Name) = "STOCK" Then
check = True
Exit While
End If
End While
If check = True Then
rect.Layer = "STOCK"
Else
Dim bt As BlockTable = myTrans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead)
'myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForWrite)
Dim btrID As ObjectId = bt.Item(BlockTableRecord.ModelSpace)
Dim btr As BlockTableRecord = myTrans.GetObject(btrID, OpenMode.ForWrite)
'myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Dim newlayer As New LayerTableRecord
newlayer.Name = "STOCK"
newlayer.Color = Colors.Color.FromColor(Color.Black)
newlayer.LineWeight = LineWeight.LineWeight005
newlayer.IsOff = True
newlayer.IsFrozen = False
newlayer.IsLocked = True
newlayer.IsPlottable = False
myLT.Add(newlayer)
myTrans.AddNewlyCreatedDBObject(newlayer, True)
myTrans.Commit()
rect.Layer = newlayer.Name
btr.AppendEntity(rect)
myTrans.AddNewlyCreatedDBObject(rect, True)
myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
End If
If ListSelected.Items.Count > 0 Then
Dim point5 As Point3d
If FramingOpts.SelectedItem.ToString = "4x8" Or FramingOpts.SelectedItem.ToString = "4x10" Or FramingOpts.SelectedItem.ToString = "4x12" Then
point5 = New Point3d(point1.X - 92, point1.Y + 48, 0)
Else
point5 = New Point3d(point1.X - 92, point1.Y + 60, 0)
End If
GenerateLayers(point5)
End If
Else
Dim markerblock As BlockReference
myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForWrite)
myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Try
If RoutingButton.Checked Then
myBTR.PathName = "s:\CNC MARKERS\KOMO INSERTION MARKER.dwg"
markerblock = New BlockReference(point, myBTR.Id)
point1 = New Point3d(point.X - 92, point.Y + 48, 0)
Else
myBTR.PathName = "s:\CNC MARKERS\FADAL INSERTION MARKER.dwg"
markerblock = New BlockReference(point, myBTR.Id)
point1 = New Point3d(point.X - 90.5, point.Y, 0)
End If
myBTR.AppendEntity(markerblock)
myTrans.AddNewlyCreatedDBObject(markerblock, True)
myTrans.Commit()
Catch ex As Exception
MessageBox.Show("Cannot create/ insert markerblock: " + ex.ToString)
End Try
myTrans.Dispose()
myTransMan.Dispose()
GenerateLayers(point)
End If
Else
Dim markerblock As BlockReference
myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForWrite)
myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Dim BTR = New BlockTableRecord()
Try
If RoutingButton.Checked Then
BTR.PathName = "s:\CNC MARKERS\KOMO INSERTION MARKER.dwg"
markerblock = New BlockReference(point, BTR.Id)
point1 = New Point3d(point.X - 92, point.Y + 48, 0)
Else
BTR.PathName = "s:\CNC MARKERS\FADAL INSERTION MARKER.dwg"
markerblock = New BlockReference(point, BTR.Id)
point1 = New Point3d(point.X - 90.5, point.Y, 0)
End If
myBTR.AppendEntity(markerblock)
myTrans.AddNewlyCreatedDBObject(markerblock, True)
myTrans.Commit()
Catch ex As Exception
MessageBox.Show("Cannot create/ insert markerblock: " + ex.ToString)
End Try
myTrans.Dispose()
myTransMan.Dispose()
GenerateLayers(point)
End If
End Sub Edited by: vampirefromtheITcave2 on Oct 23, 2009 3:25 PM
Code:
Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Insert.Click
'should be similar to cmdOK_Click()
myDWG = Application.DocumentManager.MdiActiveDocument
myDB = myDWG.Database
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction
Dim point As Point3d, point1 As Point3d, point2 As Point3d, point3 As Point3d, point4 As Point3d, verts As New Point3dCollection, rect As Polyline2d
Me.Hide()
point = myDWG.Editor.GetPoint("INSERTION POINT IS THE LOWER LEFT CORNER OF THE FRAME").Value
If FramingOpts.SelectedIndex > -1 Then
If FramingOpts.SelectedItem.ToString <> "no frame" Then
Select Case FramingOpts.SelectedItem.ToString
Case "4x8"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 96, point1.Y, 0)
point3 = New Point3d(point1.X + 96, point1.Y + 48, 0)
point4 = New Point3d(point1.X, point1.Y + 48, 0)
Case "4x10"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 120, point1.Y, 0)
point3 = New Point3d(point1.X + 120, point1.Y + 48, 0)
point4 = New Point3d(point1.X, point1.Y + 48, 0)
Case "4x12"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 144, point1.Y, 0)
point3 = New Point3d(point1.X + 144, point1.Y + 48, 0)
point4 = New Point3d(point1.X, point1.Y + 48, 0)
Case "5x5"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 60, point1.Y, 0)
point3 = New Point3d(point1.X + 60, point1.Y + 60, 0)
point4 = New Point3d(point1.X, point1.Y + 60, 0)
Case "5x8"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 96, point1.Y, 0)
point3 = New Point3d(point1.X + 96, point1.Y + 60, 0)
point4 = New Point3d(point1.X, point1.Y + 60, 0)
Case "5x10"
point1 = New Point3d(point.X - 0.25, point.Y - 0.25, 0)
point2 = New Point3d(point1.X + 120, point1.Y, 0)
point3 = New Point3d(point1.X + 120, point1.Y + 60, 0)
point4 = New Point3d(point1.X, point1.Y + 60, 0)
End Select
verts.Add(point1)
verts.Add(point2)
verts.Add(point3)
verts.Add(point4)
rect = New Polyline2d(Poly2dType.SimplePoly, verts, 0, False, 0, 0, Nothing)
rect.Closed = True
Dim check As Boolean
check = False
Dim myLT As LayerTable
Dim myLTR As LayerTableRecord
Dim mySTE As SymbolTableEnumerator
myLT = myDB.LayerTableId.GetObject(OpenMode.ForWrite)
mySTE = myLT.GetEnumerator
While mySTE.MoveNext
myLTR = mySTE.Current.GetObject(OpenMode.ForRead)
If UCase(myLTR.Name) = "STOCK" Then
check = True
Exit While
End If
End While
If check = True Then
rect.Layer = "STOCK"
Else
Dim bt As BlockTable = myTrans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead)
'myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForWrite)
Dim btrID As ObjectId = bt.Item(BlockTableRecord.ModelSpace)
Dim btr As BlockTableRecord = myTrans.GetObject(btrID, OpenMode.ForWrite)
'myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Dim newlayer As New LayerTableRecord
newlayer.Name = "STOCK"
newlayer.Color = Colors.Color.FromColor(Color.Black)
newlayer.LineWeight = LineWeight.LineWeight005
newlayer.IsOff = True
newlayer.IsFrozen = False
newlayer.IsLocked = True
newlayer.IsPlottable = False
myLT.Add(newlayer)
myTrans.AddNewlyCreatedDBObject(newlayer, True)
myTrans.Commit()
rect.Layer = newlayer.Name
btr.AppendEntity(rect)
myTrans.AddNewlyCreatedDBObject(rect, True)
myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
End If
If ListSelected.Items.Count > 0 Then
Dim point5 As Point3d
If FramingOpts.SelectedItem.ToString = "4x8" Or FramingOpts.SelectedItem.ToString = "4x10" Or FramingOpts.SelectedItem.ToString = "4x12" Then
point5 = New Point3d(point1.X - 92, point1.Y + 48, 0)
Else
point5 = New Point3d(point1.X - 92, point1.Y + 60, 0)
End If
GenerateLayers(point5)
End If
Else
Dim markerblock As BlockReference
myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForWrite)
myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Try
If RoutingButton.Checked Then
myBTR.PathName = "s:\CNC MARKERS\KOMO INSERTION MARKER.dwg"
markerblock = New BlockReference(point, myBTR.Id)
point1 = New Point3d(point.X - 92, point.Y + 48, 0)
Else
myBTR.PathName = "s:\CNC MARKERS\FADAL INSERTION MARKER.dwg"
markerblock = New BlockReference(point, myBTR.Id)
point1 = New Point3d(point.X - 90.5, point.Y, 0)
End If
myBTR.AppendEntity(markerblock)
myTrans.AddNewlyCreatedDBObject(markerblock, True)
myTrans.Commit()
Catch ex As Exception
MessageBox.Show("Cannot create/ insert markerblock: " + ex.ToString)
End Try
myTrans.Dispose()
myTransMan.Dispose()
GenerateLayers(point)
End If
Else
Dim markerblock As BlockReference
myBT = myDWG.Database.BlockTableId.GetObject(OpenMode.ForWrite)
myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Dim BTR = New BlockTableRecord()
Try
If RoutingButton.Checked Then
BTR.PathName = "s:\CNC MARKERS\KOMO INSERTION MARKER.dwg"
markerblock = New BlockReference(point, BTR.Id)
point1 = New Point3d(point.X - 92, point.Y + 48, 0)
Else
BTR.PathName = "s:\CNC MARKERS\FADAL INSERTION MARKER.dwg"
markerblock = New BlockReference(point, BTR.Id)
point1 = New Point3d(point.X - 90.5, point.Y, 0)
End If
myBTR.AppendEntity(markerblock)
myTrans.AddNewlyCreatedDBObject(markerblock, True)
myTrans.Commit()
Catch ex As Exception
MessageBox.Show("Cannot create/ insert markerblock: " + ex.ToString)
End Try
myTrans.Dispose()
myTransMan.Dispose()
GenerateLayers(point)
End If
End Sub Edited by: vampirefromtheITcave2 on Oct 23, 2009 3:25 PM