Author Topic: Aecc Points List  (Read 3970 times)

0 Members and 1 Guest are viewing this topic.

surveyor_randy

  • Guest
Aecc Points List
« on: July 09, 2008, 05:18:46 PM »
I am trying to write a program that will dump a points list in PNEZD (CSV) format into a text file and then display the text file.  The program works but the points aren't in numerical order.  I simply did a "for each Point in Points" loop.  Is there an easy way to sort these?  Or am I going to have to resort to using a list.  And if I did use the list, what would be the simplest way to do this.  Dump all of the points into an array and use the array index matched with the point number in my key-value pair?  I'm open to suggestions.  Thanks in advance!
Code: [Select]
Imports System
Imports Autodesk
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports AcadNET = Autodesk.AutoCAD
Imports AcadCOM = Autodesk.AutoCAD.Interop
Imports AcadNETApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports AeccLandLib = Autodesk.AECC.Interop.Land
Imports AeccUiLandLib = Autodesk.AECC.Interop.UiLand
Imports AecUIBase = Autodesk.AEC.Interop.UIBase

Namespace MyUtils
    Public Class Commands
        Private oAcadApp As AcadCOM.AcadApplication
        Private oAeccApp As AeccUiLandLib.IAeccApplication
        Private oAeccDoc As AeccUiLandLib.IAeccDocument
        Private oAeccDb As AeccLandLib.IAeccDatabase

        <CommandMethod("PTLIST")> _
    Public Sub DisplayPointList()
            Dim ed As Editor = AcadNETApp.DocumentManager.MdiActiveDocument.Editor
            oAcadApp = AcadNETApp.AcadApplication
            oAeccApp = oAcadApp.GetInterfaceObject("AeccXUiLand.AeccApplication.5.0")
            oAeccDoc = oAeccApp.ActiveDocument
            oAeccDb = oAeccApp.ActiveDocument.Database

            Try
                Dim oPoints As AeccLandLib.AeccPoints
                Dim oPoint As AeccLandLib.AeccPoint
                Dim oToFile As System.IO.TextWriter
                oToFile = System.IO.File.CreateText("C:\points.txt")

                oPoints = oAeccDb.Points

                For Each oPoint In oPoints
                    If oPoint.Elevation < -999999 Then oPoint.Elevation = "0"
                    oToFile.WriteLine(oPoint.Number & "," & oPoint.Northing & "," & oPoint.Easting & "," & oPoint.Elevation & "," & oPoint.RawDescription & "")
                Next

                oToFile.Flush()
                oToFile.Close()

                oAcadApp = Nothing
                oAeccApp = Nothing
                oAeccDoc = Nothing
                oAeccDb = Nothing

            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                ed.WriteMessage("Error: ", ex.Message & vbCrLf)
            End Try

            Process.Start("notepad.exe", "C:\points.txt")

        End Sub
    End Class
End Namespace

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Aecc Points List
« Reply #1 on: July 09, 2008, 05:45:30 PM »
Do you know about the ExportPoints method of the Points collection? In my limited testing, this exports in numerical order.


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: Aecc Points List
« Reply #2 on: July 09, 2008, 06:12:15 PM »
You ought to be able to dump your objects to a list like you mentioned, then sort the list using a comparer function.
Pseudo code:

Code: [Select]
  public static int oPointCompare(AeccPoint oPointA, AeccPoint oPointB)
    {
      return oPointA.Number.CompareTo(oPointB.Number);
    }

...

Code: [Select]
      List<AeccPoint> listOPoints = new List<AeccPoint>(AeccLandLib.AeccPoints);
      listOPoints.Sort(oPointCompare);

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Aecc Points List
« Reply #3 on: July 09, 2008, 06:39:54 PM »
Yep, I'm sure it does the sorting for you....
Code: [Select]
    <CommandMethod("TestMe")> _
     Public Sub TestMe()
        Dim m_AcadApp As AcadApplication

        Try
            m_AcadApp = Application.AcadApplication()
            Dim m_oAeccApp As New AeccApplication()
            m_oAeccApp.Init(m_AcadApp)
            Dim m_oAeccDoc As AeccDocument = m_oAeccApp.ActiveDocument
            Dim oPoints As AeccPoints = m_oAeccDoc.Points
            Dim oPtOpts As New AeccPointExportOptions()
            ' use the defaults....
            oPoints.ExportPoints("c:\points.txt", "PNEZD (comma delimited)", oPtOpts)

        Catch
            MsgBox(Err.Description() & Err.Number)
        End Try

    End Sub

surveyor_randy

  • Guest
Re: Aecc Points List
« Reply #4 on: July 10, 2008, 07:28:00 AM »
Thanks for the help guys!  I think that I am going to look into using the exportpoints method that Jeff suggested.  Since I am so new to .NET programing, can anyone comment on anything that looks unorthodox?

Glenn R

  • Guest
Re: Aecc Points List
« Reply #5 on: July 10, 2008, 07:56:48 AM »
Since I am so new to .NET programing, can anyone comment on anything that looks unorthodox?

Yep - VB.NET  :-D

surveyor_randy

  • Guest
Re: Aecc Points List
« Reply #6 on: July 11, 2008, 07:22:43 AM »
Since I am so new to .NET programing, can anyone comment on anything that looks unorthodox?

Yep - VB.NET  :-D

smart ass!  :-)