- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Whenever I try to override the WorldDraw function for my custom grip points, my debugging sessions freezes then crashes. Even when I use this code, which seems really basic?
public override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, double dGripSize)
{
return base.WorldDraw(worldDraw, entityId, type, imageGripPoint, dGripSize);
}
I have been using this solution from online as a general guide (ignore that its in VB). This is how they did their WorldDraw override (its in VB but I can get the gist for C#)
Public Overrides Function WorldDraw(wd As WorldDraw, entityId As ObjectId, type As DrawType, imageGripPoint As Point3d?, dGripSize As Double) As Boolean
Try : DrawDirection(wd, type, dGripSize)
Catch
End Try
Return True
End Function
#End Region
Private Sub DrawDirection(wd As WorldDraw, dt As DrawType, size As Double)
Dim a As Double = _GripDirection.GetAngleTo(Vector3d.XAxis)
If _GripDirection.Y < 0 Then a = Math.PI * 2 - a
Using pts As New Point3dCollection
Dim v As Vector3d = Me.GripPoint.GetAsVector() - New Vector3d(1.5# * size, 0#, 0#)
pts.Add(New Point3d(0, 0, 0) + v)
pts.Add(New Point3d(1.5 * size, 1.5 * size, 0) + v)
pts.Add(New Point3d(1.5 * size, 0.65 * size, 0) + v)
pts.Add(New Point3d(3 * size, 0.65 * size, 0) + v)
pts.Add(New Point3d(3 * size, -0.65 * size, 0) + v)
pts.Add(New Point3d(1.5 * size, -0.65 * size, 0) + v)
pts.Add(New Point3d(1.5 * size, -1.5 * size, 0) + v)
For index As Integer = 0 To pts.Count - 1
pts(index) = pts(index).RotateBy(a, Vector3d.ZAxis, Me.GripPoint)
Next
wd.SubEntityTraits.Color = If(dt = DrawType.WarmGrip, 82, 11)
wd.SubEntityTraits.FillType = FillType.FillAlways
wd.Geometry.Polygon(pts)
wd.SubEntityTraits.Color = If(dt = DrawType.WarmGrip, 3, 1)
wd.SubEntityTraits.FillType = FillType.FillNever
wd.Geometry.Polygon(pts)
End Using
End Sub
I have also been looking at this from Ken Walmsley and this is how they do their ViewportDraw, which I'm assuming is close enough
public override bool ViewportDraw(
ViewportDraw worldDraw,
ObjectId entityId,
GripData.DrawType type,
Point3d? imageGripPoint,
int gripSizeInPixels
)
{
// Calculate the size of the glyph in WCS
Point2d glyphSize =
worldDraw.Viewport.GetNumPixelsInUnitSquare(this.GripPoint);
Double glyphHeight = (gripSizeInPixels / glyphSize.Y);
// Transform to viewport
Matrix3d e2w = worldDraw.Viewport.EyeToWorldTransform;
Point3d pt = this.GripPoint.TransformBy(e2w);
// Draw a glyph
Point3dCollection pnts = new Point3dCollection();
pnts.Add(
new Point3d(pt.X - glyphHeight, pt.Y + glyphHeight, pt.Z)
);
pnts.Add(new Point3d(pt.X, pt.Y - glyphHeight, pt.Z));
pnts.Add(
new Point3d(pt.X + glyphHeight, pt.Y + glyphHeight, pt.Z)
);
pnts.Add(
new Point3d(pt.X - glyphHeight, pt.Y + glyphHeight, pt.Z)
);
worldDraw.Geometry.DeviceContextPolygon(pnts);
return false;
}
}
There are some references to other methods they wrote in the above. But the gist that I am seeing from both are they make some edit to the worldDraw parameter and then returning. Though one example is returning a false, and the other is returning a true?
When I return a false I get no freeze and crash, but I dont get the custom grips to render. But when I return true I still get the crash.
Solved! Go to Solution.