Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Can not override WorldDraw for GripData

nshupeFMPE3
Advocate

Can not override WorldDraw for GripData

nshupeFMPE3
Advocate
Advocate

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.  

0 Likes
Reply
Accepted solutions (1)
500 Views
3 Replies
Replies (3)

nshupeFMPE3
Advocate
Advocate

I have also tried something like 

WorldDraw.SubEntities.Color = 10;

then passing the now edited WordDraw object to the base method, with no success.

0 Likes

nshupeFMPE3
Advocate
Advocate

Ok the problem keeps getting weirder

Very strange behavior. When I added an override for ViewPortDraw() by itself, no WorldDraw() override, there was no crash. No crashes when looking at the block in model space, or through a Viewport. But the grips dont render now.

But when I also added back in the WorldDraw() override, with the ViewportDraw() override, there was no more crashing! No crashing in model space or through a viewport! But like before the grips are no longer rendering.

And if I remove the override for both of these methods, the grips render as normal??

 

public override bool ViewportDraw(Autodesk.AutoCAD.GraphicsInterface.ViewportDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, int gripSizeInPixels)
        {
            try
            {
                return base.ViewportDraw(worldDraw, entityId, type, imageGripPoint, gripSizeInPixels);
            }
            catch
            {
                return false;
            }
        }

        public override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, double dGripSize)
        {
            try
            {
                return base.WorldDraw(worldDraw, entityId, type, imageGripPoint, dGripSize);
            }
            catch (System.Exception e)
            {
                return false;
            }
        }

 

0 Likes

nshupeFMPE3
Advocate
Advocate
Accepted solution

I guess it turned out that WorldDraw() was not the method I needed to override. I'm not sure what it does at this point. All I know is that ViewportDraw() is the method that I needed to override. Once I did that and adjusted the geometry accordingly, everything worked fine. 

I figured ViewportDraw() was just for when your looking at the overriden thing through a viewport in modelspace, but I guess that is not the case.

0 Likes