.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Grabbing pt coordinates from an external file then creating lines from them

2 REPLIES 2
Reply
Message 1 of 3
matt_1ca
472 Views, 2 Replies

Grabbing pt coordinates from an external file then creating lines from them

Wondering if someone might know why I keep getting crashes --
is it something in my code? Or something else?

The code I have in the attachment crashes with an error:

"FATAL ERROR: Unhandled e0434f4dh Exception at 7c812a6bh"
(curious if someone knows a way to force the system to give a meaningful error message?)

How I wish it would give a more meaningful error message
Anyhow my screen is shown in the file "Screenshot Of My Error Message I am seeing and Exact Line of Code Where It Is Coming From.jpg"
from the attachment file "Need Help Crashing.zip"

All I want to do is grab coordinates from a file called csv.csv ... dynamically create points using those coordinates and connect created points with lines.

My code is shown below and also attached to this thread.

'**************************************************
'* *
'* cmdImport IS A COMMAND BUTTON FROM A FORM *
'* *
'**************************************************
Private Sub cmdImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdImport.Click
Dim tsr As System.IO.StreamReader
Dim oarrData As Object, intCount As Integer = 0
Dim clsK As New clsKx
Dim oarrData1 As New Object
ofdSelectCSV.ShowDialog()
tsr = System.IO.File.OpenText(ofdSelectCSV.FileName)
While (tsr.Peek <> -1)
oarrData = Split(tsr.ReadLine, ",")
If intCount = 0 Then
oarrData1 = Split(tsr.ReadLine, ",")
Else
Dim pt2 As New Point3d(CDbl(oarrData(1)), CDbl(oarrData(2)), CDbl(oarrData(3)))
Dim pt1 As New Point3d(CDbl(oarrData1(1)), CDbl(oarrData1(2)), CDbl(oarrData1(3)))

clsK.CreateLineOnALayer(pt1, pt2, "0")
pt1 = pt2
End If
intCount += 1
End While
End Sub
'***************************************
'* *
'* SUBROUTINES BELOW ARE IN CLSK CLASS *
'* *
'***************************************
Public Sub CreateLineOnALayer(ByVal pt1 As Point3d, ByVal pt2 As Point3d, ByVal strNameOfLayer As String)
CreateAlayer(strNameOfLayer)

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim trans As Transaction
Dim transMan As Autodesk.AutoCAD.ApplicationServices.TransactionManager
transMan = db.TransactionManager
trans = transMan.StartTransaction

Dim lne As New Line(pt1, pt2)
Dim bt As BlockTable
Dim btr As BlockTableRecord

bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
btr = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

lne.Layer = strNameOfLayer
btr.AppendEntity(lne)

trans.AddNewlyCreatedDBObject(lne, True)
trans.Commit()
trans.Dispose()
transMan.Dispose()

End Sub

Public Sub CreateAlayer(ByVal strName As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim trans As Transaction
Dim transMan As Autodesk.AutoCAD.ApplicationServices.TransactionManager

transMan = db.TransactionManager
trans = transMan.StartTransaction

Dim lyrT As LayerTable
lyrT = trans.GetObject(db.LayerTableId, OpenMode.ForRead)

If lyrT.Has(strName) = False Then
lyrT.UpgradeOpen()
Dim lyrTr As New LayerTableRecord
lyrTr.Name = strName
lyrT.Add(lyrTr)
trans.AddNewlyCreatedDBObject(lyrTr, True)
trans.Commit()
End If

trans.Dispose()
transMan.Dispose()
End Sub
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: matt_1ca

Your code calls Form.Show() to show your form
modelessly.

In a modeless form, you've got to lock the document
before you can modify it.

Search this newsgroup for 'eLockViolation' for
more on locking the document.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6399965@discussion.autodesk.com...
Wondering if someone might know why I keep getting crashes --
is it something in my code? Or something else?

The code I have in the attachment crashes with an error:

"FATAL ERROR: Unhandled e0434f4dh Exception at 7c812a6bh"
(curious if someone knows a way to force the system to give a meaningful error
message?)

How I wish it would give a more meaningful error message
Anyhow my screen is shown in the file "Screenshot Of My Error Message I am
seeing and Exact Line of Code Where It Is Coming From.jpg"
from the attachment file "Need Help Crashing.zip"

All I want to do is grab coordinates from a file called csv.csv ... dynamically
create points using those coordinates and connect created points with lines.

My code is shown below and also attached to this thread.

'**************************************************
'* *
'* cmdImport IS A COMMAND BUTTON FROM A FORM *
'* *
'**************************************************
Private Sub cmdImport_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdImport.Click
Dim tsr As System.IO.StreamReader
Dim oarrData As Object, intCount As Integer = 0
Dim clsK As New clsKx
Dim oarrData1 As New Object
ofdSelectCSV.ShowDialog()
tsr = System.IO.File.OpenText(ofdSelectCSV.FileName)
While (tsr.Peek <> -1)
oarrData = Split(tsr.ReadLine, ",")
If intCount = 0 Then
oarrData1 = Split(tsr.ReadLine, ",")
Else
Dim pt2 As New Point3d(CDbl(oarrData(1)), CDbl(oarrData(2)),
CDbl(oarrData(3)))
Dim pt1 As New Point3d(CDbl(oarrData1(1)), CDbl(oarrData1(2)),
CDbl(oarrData1(3)))

clsK.CreateLineOnALayer(pt1, pt2, "0")
pt1 = pt2
End If
intCount += 1
End While
End Sub
'***************************************
'* *
'* SUBROUTINES BELOW ARE IN CLSK CLASS *
'* *
'***************************************
Public Sub CreateLineOnALayer(ByVal pt1 As Point3d, ByVal pt2 As Point3d,
ByVal strNameOfLayer As String)
CreateAlayer(strNameOfLayer)

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim trans As Transaction
Dim transMan As Autodesk.AutoCAD.ApplicationServices.TransactionManager
transMan = db.TransactionManager
trans = transMan.StartTransaction

Dim lne As New Line(pt1, pt2)
Dim bt As BlockTable
Dim btr As BlockTableRecord

bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
btr = trans.GetObject(bt(BlockTableRecord.ModelSpace),
OpenMode.ForWrite)

lne.Layer = strNameOfLayer
btr.AppendEntity(lne)

trans.AddNewlyCreatedDBObject(lne, True)
trans.Commit()
trans.Dispose()
transMan.Dispose()

End Sub

Public Sub CreateAlayer(ByVal strName As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim trans As Transaction
Dim transMan As Autodesk.AutoCAD.ApplicationServices.TransactionManager

transMan = db.TransactionManager
trans = transMan.StartTransaction

Dim lyrT As LayerTable
lyrT = trans.GetObject(db.LayerTableId, OpenMode.ForRead)

If lyrT.Has(strName) = False Then
lyrT.UpgradeOpen()
Dim lyrTr As New LayerTableRecord
lyrTr.Name = strName
lyrT.Add(lyrTr)
trans.AddNewlyCreatedDBObject(lyrTr, True)
trans.Commit()
End If

trans.Dispose()
transMan.Dispose()
End Sub
Message 3 of 3
matt_1ca
in reply to: matt_1ca

Nothing has made me happier for the past several days now than to see my code
working, perfectly -- I feel fantastic --- thank you so much Tony locking the document
like you suggested has freed me from so many miserble hours hitting walls

... cheers and have a great weekend.

Gratefully,
Matt

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost