OK, got SharpDevelop downloaded, got the ObjectARX SDK downloaded and the help linked into SharpDevelop and figured out how to compile and debug projects, scanned through the C# language synopsis, and rooted through various other documentation, and came up with the following.
The way it sits right now, it creates points on all parcels in all sites in the drawing, just like I wanted. I'd like to modify this so that it asks the user to select the site(s). But it works well if there's only one site in the drawing, and it puts one COGO Point on each lot corner. The points are created in a rather chaotic order, but it can't get any simpler for the tech.
This being my first C# program and all, I'm sure there's some things I should do differently. I copied-and-pasted some of this code, and I notice the C3D invocation in partiular doesn't seem to work quite right (at least it gets confused if C3D is already open, and I try starting the program from SharpDevelop). So let me know if you see obvious ways to improve the C#.
/*
* Created by SharpDevelop.
* User: Sinc
* Date: 2/17/2007
* Time: 1:38 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AECC.Interop.Land;
using Autodesk.AECC.Interop.UiLand;
namespace LotCorner
{
/// <summary>
/// Description of MyClass.
/// </summary>
public class LotCornerApp
{
private Autodesk.AutoCAD.Interop.IAcadApplication m_oAcadApp = null;
private Autodesk.AECC.Interop.UiLand.IAeccApplication m_oAeccApp = null;
private Autodesk.AECC.Interop.UiLand.IAeccDocument m_oAeccDoc = null;
private IAeccDatabase m_oAeccDb = null;
string m_sAcadProdID = "AutoCAD.Application";
string m_sAeccAppProgId = "AeccXUiLand.AeccApplication";
private string m_sMessage="";
[CommandMethod("LOTCORNERS")]
public void LotCorners()
{
//Start Civil-3D, or get it if it's already running
try
{
m_oAcadApp = (Autodesk.AutoCAD.Interop.IAcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(m_sAcadProdID);
}
catch (System.Exception /*ex*/)
{
System.Type AcadProg = System.Type.GetTypeFromProgID(m_sAcadProdID);
m_oAcadApp = (Autodesk.AutoCAD.Interop.IAcadApplication)System.Activator.CreateInstance(AcadProg, true);
//Instead above two lines of code, simply use following new ().
//However, this always creates an instance of the
//AutoCAD even if it is already running.
//m_oAcadApp = new Autodesk.AutoCAD.Interop.AcadApplicationClass();
}
if (m_oAcadApp != null)
{
m_oAcadApp.Visible = true;
m_oAeccApp = (IAeccApplication)m_oAcadApp.GetInterfaceObject(m_sAeccAppProgId);
m_oAeccDoc = (IAeccDocument)m_oAeccApp.ActiveDocument;
// get the Database object via a late bind
m_oAeccDb = (IAeccDatabase)m_oAeccDoc.GetType().GetProperty("Database").GetValue(m_oAeccDoc, null);
IAeccPoints cogoPoints = m_oAeccDb.Points;
IAeccPoint cogoPoint = null;
long siteCount = m_oAeccDb.Sites.Count;
m_sMessage += "Number of Sites = " + siteCount.ToString() + "\n\n";
foreach (IAeccSite site in m_oAeccDb.Sites) {
m_sMessage += "-- " + site.DisplayName + "\n\n";
foreach (IAeccParcelSegment parcelSegment in site.ParcelSegments) {
foreach (IAeccParcelSegmentElement parcelSegmentElement in parcelSegment) {
double[] coords = {parcelSegmentElement.StartX, parcelSegmentElement.StartY, 0.0};
cogoPoint = cogoPoints.Add(coords);
cogoPoint.RawDescription = "LOTCORNER";
}
}
}
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage(m_sMessage);
m_sMessage="";
}
}
}
}