What I want:
I have a drawing, in this drawing it has 1-n Xref.
In the xref it has 3dPoly, 2dPoly, lines and arcs.
Also in the drawing it has 3dpoly, 2dpoly, lines and arcs.
I have a function that returns all ObjectIds of entities that are on top of each other.
These can also be entities that are in Xref.
What I need is a function that tells me which entity is on top.
e.g.
Current drawing has 2 polylines on top of each other.
The drawing has 2 xrefs, each of which also has 2 polylines on top of each other.
So I have 6 entities that are on top of each other.
The function has to return the entity that is on top.
Is that even possible?
First - Thank you for you repley
Ok and how I'm doing that?
any definitions/method for doing that
PS: I but my code
At row 197 start the function where I need, to evaluete the top entity
internal class CadClass1
{
[CommandMethod("NCv")]
public static void ncv()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
var ed = doc.Editor;
var ptr = ed.GetPoint("\nPick point");
if (ptr.Status == PromptStatus.OK)
{
var pt = ptr.Value;
ObjectNear objnear = new ObjectNear() { Id = ObjectId.Null, Z = -100 };
using (DocumentLock lk = doc.LockDocument())
{
using (var tr = db.TransactionManager.StartTransaction())
{
var cspace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
objnear = FindNearPoint(cspace, pt, objnear, tr);
}
}
ed.WriteMessage("Top curve Id: " + objnear.Id.ToString() + ", and Z:" + objnear.Z.ToString());
}
}
/// <summary>
/// class to save ObjectId and MaxZ
/// </summary>
internal class ObjectNear
{
public ObjectId Id { get; set; }
public double Z { get; set; }
}
/// <summary>
/// Check distance from point3d to curve on XY plane < 0.01
/// </summary>
/// <param name="cv"></param>
/// <param name="pt"></param>
/// <returns></returns>
private static bool IsPointNearCurve(Curve cv, Point3d pt)
{
var pc = cv.GetClosestPointTo(pt, false);
return pt.Convert2d(new Plane()).GetDistanceTo(pc.Convert2d(new Plane())) < 0.01;
}
/// <summary>
/// Get Elevation of pickpoint on curve
/// </summary>
/// <param name="cv"></param>
/// <param name="pickpoint"></param>
/// <returns></returns>
private static double GetZpoint(Curve cv, Point3d pickpoint) => cv.GetClosestPointTo(pickpoint, false).Z;
/// <summary>
/// Find curve near a point from BTR currentspace
/// </summary>
/// <param name="btr"></param>
/// <param name="pickpoint"></param>
/// <param name="objnear"></param>
/// <param name="tr"></param>
/// <returns></returns>
private static ObjectNear FindNearPoint(BlockTableRecord btr, Point3d pickpoint, ObjectNear objnear, Transaction tr)
{
foreach (ObjectId item in btr)
{
var ent = tr.GetObject(item, OpenMode.ForRead) as Entity;
if (ent is Curve cv)
{
if (IsPointNearCurve(cv, pickpoint) && objnear.Z <= GetZpoint(cv, pickpoint))
{
objnear.Id = cv.Id;
objnear.Z = GetZpoint(cv, pickpoint);
}
}
else if (ent is BlockReference br )
{
var matrix = br.BlockTransform;
var newpt = pickpoint.TransformBy(matrix);
var btrblock = tr.GetObject(br.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
objnear = FindNearPoint(btrblock, newpt, objnear, tr);
}
}
return objnear;
}
}
Can't find what you're looking for? Ask the community or share your knowledge.