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
LVL 11
BillPowellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

norrin_raddCommented:
hey bill,
I looked at this a little bit. Did you try:
Dim obj as Acadpoint ?
You might be able to get rid of the if statement, if you dont need it to be an acadobject, try that and see if it does anything. I did try some different coding too,although I didnt try to get the coords to a database I did get them to a msgbox. I think if you get the points into a selection set it may fix your problem if the other doesnt help. here is what I tried:

Sub test3()
Dim pnt As AcadPoint
' Create the new selection set
    Dim ssetObj As AcadSelectionSet
    Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SELECTIONSETp")

    ' Iterate through the model space collection.
    ' Collect the objects found into an array of objects
    ' to be added to the selection set.
    ReDim ssobjs(0 To ThisDrawing.ModelSpace.count - 1) As AcadEntity
    Dim I As Integer
    For I = 0 To ThisDrawing.ModelSpace.count - 1
        Set ssobjs(I) = ThisDrawing.ModelSpace.Item(I)
    Next
   
    ' Add the array of objects to the selection set
    ssetObj.AddItems ssobjs


For Each pnt In ssetObj
MsgBox "" & pnt.Coordinates(0) & "," & pnt.Coordinates(1) & "," & pnt.Coordinates(2)
Next pnt

ssetObj.Delete

End Sub

********
Try that on a dwg with just a few points. I couldnt get that last bit to delete the selectionset (notice the lowercase letter at the end of the sset name ;)), not sure why but I've had issues with that before and forget how I fix it you may be able to work that out.
Also it would help if you could get it to iterate through model space and just get the points, I just copied that from the examples. Not sure if you already know how to that, I dont right off hand but could look into it if you need it.
Anyhow just thought I'd throw something out there maybe to stir up some ideas maybe that'll help untill somebody with a little more programing experience chimes in.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BillPowellAuthor Commented:
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
0
norrin_raddCommented:
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 ;)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

BillPowellAuthor Commented:
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?
0
norrin_raddCommented:
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?
0
BillPowellAuthor Commented:
<<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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CAD/Architecture Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.