namespace FindPosition
{
public class PointPositionInList
{
//AutoCad 2012 commandline//VS2010Express//NetVersion 4.
//Usage - (PtPos 3dPointToFind listof3dPts) //list of 3d points in Autolisp.
//thanks to CGabriel @ theswamp.org
[LispFunction("PtPos")]
public static int GetListInDWG(ResultBuffer args)
{
Point3d pt
= new Point3d
(); List
<Point3d
> ptlst
= new List
<Point3d
>(); int pos = -1;
if (parseArguments(args))
try
{
TypedValue[] tvArr = args.AsArray();
for (int i = 0; i < tvArr.Length; i++)
{
if(tvArr[i].TypeCode == RT3DPOINT)
{
ptlst.Add((Point3d)tvArr[i].Value);
}
}
pt = (Point3d)tvArr[0].Value; //input point to find index of.
ptlst.RemoveAt(0); //remove input pt from start of list.
pos = ptlst.IndexOf(pt); //find index of point in remaining list.
}
catch (System.Exception e)
{
MessageBox.Show("\n Error ::: " + e.StackTrace);
}
return pos;
}
public static bool parseArguments(ResultBuffer args)
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
if (args == null)
return notEnoughArguments(ed);
ResultBufferEnumerator iter = args.GetEnumerator();
iter.MoveNext();
if (iter.Current.TypeCode != (int)LispDataType.Point3d) //first item in ResultBuffer is input point.
return wrongArguments(ed);
if (iter.MoveNext() == false)
return notEnoughArguments(ed);
if (iter.Current.TypeCode != (int)LispDataType.ListBegin) //follwed by list of 3dPoints.
return wrongArguments(ed);
return true;
}
public static bool notEnoughArguments(Editor ed)
{
ed.WriteMessage("\nToo few arguments.");
return false;
}
public static bool wrongArguments(Editor ed)
{
ed.WriteMessage("\nPoint & list of 3DPoints expected.");
return false;
}
/// <summary>
///Thanks to Alexander Rivilis @ AutoDesk .NET forum.
/// </summary>
///
const int RTNONE = 5000; /* No result */
const int RTREAL = 5001; /*Real number */
const int RTPOINT = 5002; /* 2D point X and Y only */
const int RTSHORT = 5003; /* Short integer */
const int RTANG = 5004; /* Angle */
const int RTSTR = 5005; /* String */
const int RTENAME = 5006; /* Entity name */
const int RTPICKS = 5007; /* Pick set */
const int RTORINT = 5008; /* Orientation */
const int RT3DPOINT = 5009; /* 3D point - X, Y, and Z */
const int RTLONG = 5010; /* Long integer */
const int RTVOID = 5014; /* Blank symbol */
const int RTLB = 5016; /* list begin */
const int RTLE = 5017; /* list end */
const int RTDOTE = 5018; /* dotted pair */
const int RTNIL = 5019; /* nil */
const int RTDXF0 = 5020; /* DXF code 0 for ads_buildlist only */
const int RTT = 5021; /* T atom */
const int RTRESBUF = 5023; /* resbuf */
const int RTMODELESS = 5027; /* interrupted by modeless dialog */
}
}
[code/]