.NET

Reply
Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 1 of 3 (167 Views)

Extract co-ordinates from TEXT file and draw object in those (x,y,z) points

167 Views, 2 Replies
12-09-2012 11:21 AM

HI All,

 

I want extract a (x,y,z) point from a text file and want to put marker to that point in a dwg file. how can I accomplish that? Can anybody give me a hint or same code in VB.

 

Thanks in advance.

 

Regards

Zakir

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 3 (143 Views)

Re: Extract co-ordinates from TEXT file and draw object in those (x,y,z) points

12-09-2012 11:28 PM in reply to: mzakiralam

This very basic code hope it will get you started,

add properties to our suit

		<CommandMethod("ptsRead")> _
		Public Sub testReadCSV()
			Dim filePath As String = "C:\Test\points.txt"
			If Not File.Exists(filePath) Then
				MessageBox.Show("File does not exist")
				Return
			End If
			Dim sep As String = ";"
			Dim pts As New Point3dCollection()
			Using reader As New System.IO.StreamReader(filePath)
				While Not reader.EndOfStream
					
					Dim textLine As String = reader.ReadLine()
					Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbLf & "{0}", textLine)
					Dim tmp As String() = textLine.Split(New String() {sep}, StringSplitOptions.RemoveEmptyEntries)
					If tmp.Length <> 0 Then
						Dim pt As New Point3d(Convert.ToDouble(tmp(0)), Convert.ToDouble(tmp(1)), Convert.ToDouble(tmp(2)))
						pts.Add(pt)
					End If
				End While
			End Using

			If pts Is Nothing Then
				MessageBox.Show("Cant parse this file")
				Return
			End If
			Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

			Dim db As Database = doc.Database

			Dim ed As Editor = doc.Editor

			Using tr As Transaction = db.TransactionManager.StartTransaction()
				Dim btr As BlockTableRecord = TryCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

				For Each pnt As Point3d In pts
					Dim pt As New DBPoint(pnt)

					pt.SetDatabaseDefaults()

					pt.ColorIndex = 121
					' <-- set any color of point
					btr.AppendEntity(pt)

					Dim txt As New DBText()

					tr.AddNewlyCreatedDBObject(pt, True)

					txt.SetDatabaseDefaults()

					txt.Position = pt.Position

					txt.TextString = txt.Position.ToString()
					'<-- add any textstring to suit
					txt.Justify = AttachmentPoint.BaseLeft

					' txt.AlignmentPoint = pt.Position;

					txt.AdjustAlignment(db)

					btr.AppendEntity(txt)

					tr.AddNewlyCreatedDBObject(txt, True)
				Next
				tr.Commit()
			End Using
		End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 3 of 3 (140 Views)

Re: Extract co-ordinates from TEXT file and draw object in those (x,y,z) points

12-10-2012 12:21 AM in reply to: Hallex

Hi Hallex,

 

Thanks for your response. I will try it and let you know about the status.

 

Regards

Zakir

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community