Link to home
Start Free TrialLog in
Avatar of BillPowell
BillPowell

asked on

Loop through drawing, extract coordinates

Should be easy but I cant seem to crack it.  All I want to do is loop through all points in a drawing, read the x,y,z values and insert them into an already existing table.  Somewhere I dont reference the points correctly.  Take a look please:

Public Sub ExportAllPoints()
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim obj As AcadObject
Set cnn = New ADODB.Connection
cnn.Open cnnPoints
rst.Open "Select Easting, Northing, Elevation From Points Where 1 = 0", cnnPoints, adOpenDynamic, adLockOptimistic
For Each obj In ThisDrawing.ModelSpace
If TypeName(obj) = "IAcadPoint" Then
  rst.AddNew
  With rst
    .Fields(0) = obj.Coordinates(0)
    .Fields(1) = obj.Coordinates(1)
    .Fields(2) = obj.Coordinates(2)
    .Update
  End With
End If
Next obj
End Sub
ASKER CERTIFIED SOLUTION
Avatar of norrin_radd
norrin_radd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BillPowell
BillPowell

ASKER

Hey Norrin Radd,

I actually got an answer from the autodesk forums.  Ive posted the solution below.  Your solution should work too, so the points are yours.  I thought I would wait till the beginning of the month to post in case you needed the points to keep up the subscription.

Cheers

Public Sub ExportAllPoints()
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim obj As AcadEntity
Dim pnt As Variant
Set cnn = New ADODB.Connection
cnn.Open cnnPoints
rst.Open "Select Easting, Northing, Elevation From Points Where 1 = 0", cnnPoints, adOpenDynamic, adLockOptimistic
For Each obj In ThisDrawing.ModelSpace
If TypeOf obj Is AcadPoint Then
rst.AddNew
pnt = obj.Coordinates
With rst
.Fields("Easting") = pnt(0)
.Fields("Northing") = pnt(1)
.Fields("Elevation") = pnt(2)
.Update
End With
End If
Next obj
End Sub
hey bill,
glad you got an answer. was the " If TypeName(obj) = "IAcadPoint" Then" the part that was holding you up?
Thanks for the points and the consideration ;)
Actually it was the referencing of the point values directly.  For some reason it has to be thrown into a array variant before you can access the elements.
Hey, did you install Map 2007 yet?
nah, not yet. i flipped through that book that came with though. this is the first release that i havent been chomping at the bit to load for some reason ;/  I'm still in the learning curve for 2006 i guess.
think I'm going to see if i can get a new pc first.
to be honest I havent tapped into 5% of what map can do (mapbooks, features ,topographies and such), so busy all the time hard to explore it. mainly just use it to query stuff in and try to place it geospatially.

are you an augi member?
<<are you an augi member?>>
Yep

I installed 2007.  I havent played with it that much but from the documentation Ive read, it seems like a giant leap ahead, particularily in the areas of viewing DEMs in 3D and the new spatial data format.  The only downside was the removal of the Civil 3D toolbar.  I used to use it to make TIN's, but it seemed to choke on very large datasets.