Hi
I am reading SHP file with NetTopologySuite
Here I get error Operation is not valid due to the current state of the object
>> Dim ms = CType(tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite), BlockTableRecord)
can anyone help how i can fix this Please
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance)
Dim factory As GeometryFactory = New GeometryFactory()
Dim shapeFileDataReader As ShapefileDataReader = New ShapefileDataReader(slod, factory)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Layer_name = Trim(Layer_name)
Using tr As Transaction = db.TransactionManager.StartTransaction()
Try
While shapeFileDataReader.Read
Dim ptColl As Point3dCollection = New Point3dCollection()
Dim plineLst As List(Of Polyline) = New List(Of Polyline)()
For i As Integer = 0 To shapeFileDataReader.Geometry.NumGeometries - 1
Dim coors As Point2dCollection = New Point2dCollection()
For Each coord As Coordinate In shapeFileDataReader.Geometry.GetGeometryN(i).Coordinates
Dim pt As Point2d = New Point2d(coord.X, coord.Y)
coors.Add(pt)
Next
If coors.Count > 1 Then
Dim pline As Polyline = New Polyline()
Dim id As Integer = 0
For Each pt As Point2d In coors
pline.AddVertexAt(id, pt, 0, 0, 0)
id = id + 1
Next
plineLst.Add(pline)
End If
Next
If plineLst.Count > 0 Then
Dim ms = CType(tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite), BlockTableRecord)
For Each pline As Polyline In plineLst
' pline.Layer = Layer_name
ms.AppendEntity(pline)
tr.AddNewlyCreatedDBObject(pline, True)
Next
tr.Commit()
End If
End While
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(ex.Message)
Finally
End Try
End Using