• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

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
0
BillPowell
Asked:
BillPowell
  • 3
  • 3
1 Solution
 
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
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now