Jump to content

VB.Net/ VBA: Reading Coordinates of Lines drawn in AutoCAD 2005


ayrus

Recommended Posts

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

 

_

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

Link to comment
Share on other sites

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

 

_

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...