- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to check if there is any MText below my current MText, as i have an exported drawing from Revit which explode every MText into single-line Mtext. So i have used this code:
private static bool IsTextBelow(Editor ed, MText entityabove, MText entitybelow )
{
Polyline pl = new Polyline();
int[] VerticesX = new int[4] { 0, 1, 1, 0 };
int[] VerticesY = new int[4] { 0, 0, -1, -1 };
for(int i = 0; i == VerticesX.Length - 1 ;i++)
{
Point2d pnt = new Point2d(entityabove.Location.X + entityabove.ActualWidth * VerticesX[i], entityabove.Location.Y + (entityabove.ActualHeight + entityabove.TextHeight) * VerticesY[i]);
pl.AddVertexAt(i, pnt, 0, 0, 0);
}
Polyline plaux = new Polyline();
for (int i = 0; i == VerticesX.Length - 1; i++)
{
Point2d pnt = new Point2d(entitybelow.Location.X + entitybelow.ActualWidth * VerticesX[i], entitybelow.Location.Y + entitybelow.ActualHeight * VerticesY[i]);
plaux.AddVertexAt(i, pnt, 0, 0, 0);
}
pl.Closed = true;
plaux.Closed = true;
Point3dCollection IntPnt = new Point3dCollection();
pl.IntersectWith(plaux, Intersect.OnBothOperands, IntPnt, (int)IntPtr.Zero, (int)IntPtr.Zero);
pl.Dispose();
plaux.Dispose();
if (IntPnt.Count > 0)
{
IntPnt.Dispose();
return true;
}
else
{
IntPnt.Dispose();
return false;
}
}
I am getting a weird error when using Entity.IntersectWith() method with two polylines. I have already use this code in VB.NET, but in this new proyect in C# i am getting this error:
Error: eInvalidInput en Acdbmgd , at Autodesk.AutoCAD.DatabaseServices.Entity.IntersectWith(Entity entityPointer, Intersect intersectType, Point3dCollection points, IntPtr thisGraphicSystemMarker, IntPtr otherGraphicSystemMarker)
My VB.NET code that already works is as following:
Private Function IsTextBelow(ByVal tx As MText, ByVal entitybelow As MText) As Boolean
Try
Dim pl As Polyline = New Polyline
Dim VerticesX = New Integer() {0, 1, 1, 0}
Dim VerticesY = New Integer() {0, 0, -1, -1}
For i As Integer = 0 To VerticesX.Count - 1
Dim pnt As Point2d = New Point2d(tx.Location.X + tx.ActualWidth * VerticesX(i), tx.Location.Y + (tx.ActualHeight + tx.TextHeight) * VerticesY(i))
pl.AddVertexAt(i, pnt, 0, 0, 0)
Next
Dim plaux As Polyline = New Polyline
For i As Integer = 0 To VerticesX.Count - 1
Dim pnt As Point2d = New Point2d(entitybelow.Location.X + entitybelow.ActualWidth * VerticesX(i), entitybelow.Location.Y + (entitybelow.ActualHeight) * VerticesY(i))
plaux.AddVertexAt(i, pnt, 0, 0, 0)
Next
plaux.Closed = True
pl.Closed = True
Dim IntPnt As Point3dCollection = New Point3dCollection
pl.IntersectWith(plaux, Intersect.OnBothOperands, IntPnt, New IntPtr(0), New IntPtr(0))
plaux.Dispose()
pl.Dispose()
If IntPnt.Count > 0 Then
Return True
Else
Return False
End If
Catch ex As System.Exception
ed.WriteMessage("error al encontrar el texto inferior")
Return False
End Try
End Function
any clue about what may be happening?
Thanks in advance.
Solved! Go to Solution.