View Full Version : VB.Net/ VBA: Reading Coordinates of Lines drawn in AutoCAD 2005
ayrus
14th Oct 2010, 09:02 am
Hi,
I am wondering if it is possible to read the start and point of all the lines drawn in a autocad file using VBA or VB.Net
thanks
Kerry Brown
14th Oct 2010, 11:29 am
Yes, it is.
ayrus
14th Oct 2010, 11:41 am
hi Kerry,
Wondering if you have any sample code...
Yes, it is.
Jeff H
14th Oct 2010, 07:43 pm
This will print them out to the command line
This techinally does not get all lines in the drawing just the ones in model space
but you could loop through the blocktable and check if IsLayout to get model and paper spaces
<CommandMethod("ReadAllLinesStartPoint")> _
Public Sub ReadAllLinesStartPoint()
Dim doc As Document = DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
Dim btr As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode .ForRead)
For Each objId As ObjectId In btr
Dim ent As Entity = objId.GetObject(OpenMode.ForRead)
If TypeOf ent Is Line Then
Dim l As Line = TryCast(ent, Line)
ed.WriteMessage(vbCrLf & l.StartPoint.ToString())
End If
Next
tr.Commit()
End Using
End Sub
ayrus
18th Oct 2010, 08:07 am
Hi jeff,
Thanks you for your response.
Not sure on how I could convert this to VBA in AutoCAD.
Please could you help..
This will print them out to the command line
This techinally does not get all lines in the drawing just the ones in model space
but you could loop through the blocktable and check if IsLayout to get model and paper spaces
<CommandMethod("ReadAllLinesStartPoint")> _
Public Sub ReadAllLinesStartPoint()
Dim doc As Document = DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
Dim btr As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode .ForRead)
For Each objId As ObjectId In btr
Dim ent As Entity = objId.GetObject(OpenMode.ForRead)
If TypeOf ent Is Line Then
Dim l As Line = TryCast(ent, Line)
ed.WriteMessage(vbCrLf & l.StartPoint.ToString())
End If
Next
tr.Commit()
End Using
End Sub
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.