I am getting the Exception above when running an overrule to display raster images in a per viewport basis. I am using Kean example:
https://www.keanw.com/2015/10/displaying-different-entities-in-autocad-viewports-using-net.html to simulate the same behavior but for raster images. Here is my viewport draw where the issue is happening.
public override void ViewportDraw(Drawable drawable, ViewportDraw vd)
{
try
{
if (!IsVisible(vd.Viewport.AcadWindowId))
return;
var pd = new PassthroughDraw(vd);
if (!base.WorldDraw(drawable, pd))
{
try
{
base.ViewportDraw(drawable, vd);
} catch(Exception ex)
{
Console.WriteLine(ex);
}
}
} catch
{
// ignored
}
}
here is the passthroughDraw class
public class PassthroughDraw : WorldDraw
{
private readonly PassthroughGeometry _pg;
private readonly ViewportDraw _vd;
/// <summary>
/// Constructor
/// </summary>
/// <param name="vd"></param>
public PassthroughDraw(ViewportDraw vd)
{
_vd = vd;
_pg = new PassthroughGeometry(vd.Geometry);
}
/// <summary>
/// WorldDraw protocol
/// </summary>
public override WorldGeometry Geometry => _pg;
/// <summary>
/// CommonDraw protocol
/// </summary>
public override Context Context => _vd.Context;
public override bool IsDragging => _vd.IsDragging;
public override int NumberOfIsolines => _vd.NumberOfIsolines;
public override Geometry RawGeometry => _vd.RawGeometry;
public override bool RegenAbort => _vd.RegenAbort;
public override RegenType RegenType => _vd.RegenType;
public override SubEntityTraits SubEntityTraits => _vd.SubEntityTraits;
public override double Deviation(DeviationType deviationType, Point3d pointOnCurve)
{
return _vd.Deviation(deviationType, pointOnCurve);
}
}
Here is the PassthroughGeometry class
private readonly ViewportGeometry _vg;
/// <summary>
/// ctor
/// </summary>
/// <param name="vg"></param>
public PassthroughGeometry(ViewportGeometry vg)
{
_vg = vg;
}
public override void SetExtents(Extents3d extents) { }
public override void StartAttributesSegment() { }
/// <summary>
/// Geometry protocol
/// </summary>
public override Matrix3d ModelToWorldTransform => _vg.ModelToWorldTransform;
public override Matrix3d WorldToModelTransform => _vg.WorldToModelTransform;
public override bool Circle(Point3d center, double radius, Vector3d normal) => _vg.Circle(center, radius, normal);
public override bool Circle(Point3d firstPoint, Point3d secondPoint, Point3d thirdPoint) => _vg.Circle(firstPoint, secondPoint, thirdPoint);
public override bool CircularArc(Point3d start, Point3d point, Point3d endingPoint, ArcType arcType) => _vg.CircularArc(start, point, endingPoint, arcType);
public override bool CircularArc(Point3d center, double radius, Vector3d normal, Vector3d startVector, double sweepAngle, ArcType arcType) => _vg.CircularArc(center, radius, normal, startVector, sweepAngle, arcType);
public override bool Draw(Drawable value) => _vg.Draw(value);
public override bool Edge(Curve2dCollection e) => _vg.Edge(e);
public override bool EllipticalArc(Point3d center, Vector3d normal, double majorAxisLength, double minorAxisLength, double startDegreeInRads, double endDegreeInRads, double tiltDegreeInRads, ArcType arcType) => _vg.EllipticalArc(center, normal, majorAxisLength, minorAxisLength, startDegreeInRads, endDegreeInRads, tiltDegreeInRads, arcType);
public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v) => _vg.Image(imageSource, position, u, v);
public override bool Image(ImageBGRA32 imageSource, Point3d position, Vector3d u, Vector3d v, TransparencyMode transparencyMode) => _vg.Image(imageSource, position, u, v, transparencyMode);
public override bool Mesh(int rows, int columns, Point3dCollection points, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals) => _vg.Mesh(rows, columns, points, edgeData, faceData, vertexData, bAutoGenerateNormals);
public override bool OwnerDraw(GdiDrawObject gdiDrawObject, Point3d position, Vector3d u, Vector3d v) => _vg.OwnerDraw(gdiDrawObject, position, u, v);
public override bool Polygon(Point3dCollection points) => _vg.Polygon(points);
public override bool Polyline(AcGi.Polyline polylineObj) => _vg.Polyline(polylineObj);
public override bool Polyline(AcDb.Polyline value, int fromIndex, int segments) => _vg.Polyline(value, fromIndex, segments);
public override bool Polyline(Point3dCollection points, Vector3d normal, IntPtr subEntityMarker) => _vg.Polyline(points, normal, subEntityMarker);
public override bool Polypoint(Point3dCollection points, Vector3dCollection normals, IntPtrCollection subentityMarkers) => _vg.Polypoint(points, normals, subentityMarkers);
public override bool PolyPolygon(UInt32Collection numPolygonPositions, Point3dCollection polygonPositions, UInt32Collection numPolygonPoints, Point3dCollection polygonPoints, EntityColorCollection outlineColors, LinetypeCollection outlineTypes, EntityColorCollection fillColors, TransparencyCollection fillOpacities) => _vg.PolyPolygon(numPolygonPoints, polygonPoints, numPolygonPoints, polygonPoints, outlineColors, outlineTypes, fillColors, fillOpacities);
public override bool PolyPolyline(PolylineCollection polylineCollection) => _vg.PolyPolyline(polylineCollection);
public override void PopClipBoundary() => _vg.PopClipBoundary();
public override bool PopModelTransform() => _vg.PopModelTransform();
public override bool PushClipBoundary(ClipBoundary boundary) => _vg.PushClipBoundary(boundary);
public override bool PushModelTransform(Matrix3d matrix) => _vg.PushModelTransform(matrix);
public override bool PushModelTransform(Vector3d normal) => _vg.PushModelTransform(normal);
public override Matrix3d PushOrientationTransform(OrientationBehavior behavior) => _vg.PushOrientationTransform(behavior);
public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point2d offset) => _vg.PushPositionTransform(behavior, offset);
public override Matrix3d PushPositionTransform(PositionBehavior behavior, Point3d offset) => _vg.PushPositionTransform(behavior, offset);
public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point2d extents) => _vg.PushScaleTransform(behavior, extents);
public override Matrix3d PushScaleTransform(ScaleBehavior behavior, Point3d extents) => _vg.PushScaleTransform(behavior, extents);
public override bool Ray(Point3d point1, Point3d point2) => _vg.Ray(point1, point2);
public override bool RowOfDots(int count, Point3d start, Vector3d step) => _vg.RowOfDots(count, start, step);
public override bool Shell(Point3dCollection points, IntegerCollection faces, EdgeData edgeData, FaceData faceData, VertexData vertexData, bool bAutoGenerateNormals)
{
// To avoid a null argument exception, faces need to be transfered across to a new collection
var faces2 = new IntegerCollection(faces.Count);
foreach (int face in faces)
faces2.Add(face);
return _vg.Shell(points, faces2, edgeData, faceData, vertexData, bAutoGenerateNormals);
}
public override bool Text(Point3d position, Vector3d normal, Vector3d direction, string message, bool raw, TextStyle textStyle) => _vg.Text(position, normal, direction, message, raw, textStyle);
public override bool Text(Point3d position, Vector3d normal, Vector3d direction, double height, double width, double oblique, string message) => _vg.Text(position, normal, direction, height, width, oblique, message);
public override bool WorldLine(Point3d startPoint, Point3d endPoint) => _vg.WorldLine(startPoint, endPoint);
public override bool Xline(Point3d point1, Point3d point2) => _vg.Xline(point1, point2);
}
Here is how I am adding the overrule:
public void Add()
{
AddOverrule(GetClass(typeof(RasterImage)), this, false);
Overruling = true;
}
public void Remove()
{
RemoveOverrule(GetClass(typeof(RasterImage)), this);
Dispose();
}
Any ideas on why this my be happening?
UPDATE: GOT IT TO WORK BUT IT IS NOT WORKING FOR DIFFERENT VISUAL STYLES, ONLY FOR 2D WIREFRAME, ANY IDEAS?