我正在为C# .NET AutoCAD使用AutoCAD API。我有一个用于GripData的派生类
class PanelMidGrips : GripData
{
private readonly PanelPerimeterLine _line;
public PanelMidGrips(PanelPerimeterLine line)
{
this.GripPoint = line.TranslateToWCS(line.MidPoint);//GripPoint comes from GripData
_line = line;
}
}TranslateToWCS()不应该很重要。它获取块的OCS中的一个点,并将其转换为模型空间中的一个点,这样就可以在块上正确地呈现抓地点。
我的问题是当我试图覆盖WorldDraw() AutoCAD崩溃时。
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);
}当我使用返回基上的断点进行调试时……行我可以看到基本方法运行。但是,当方法退出时,当我继续执行时,我的AutoCAD会冻结大约10秒,然后崩溃,没有提供StackTrace或信息。
编辑0:我尝试添加一个try/catch块,以查看是否会发生任何不同的事情。但是同样的事情发生了,基本方法返回一个false,当该方法结束我的IDE和AutoCAD冻结,然后崩溃。
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(Autodesk.AutoCAD.Runtime.Exception e)
{
return false;
}
}编辑1:非常奇怪的行为。当我为ViewPortDraw()本身添加一个覆盖时,没有WorldDraw()覆盖,就没有崩溃。在模型空间中或通过Viewport查看块时,不会发生崩溃。但握把现在不能渲染。
但是,当我还在WorldDraw()覆盖中添加时,使用ViewportDraw()覆盖,就不会再有崩溃了!不要在模型空间或通过视口崩溃!但是和以前一样,握把不再呈现。
如果我删除了这两种方法的覆盖,抓手就会正常呈现??
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;
}
}发布于 2022-10-21 21:41:00
我想结果是WorldDraw()不是我需要重写的方法。我不知道它在这点上做了什么。我只知道ViewportDraw()是我需要重写的方法。一旦我这样做,并相应地调整几何学,一切都很好。
我认为ViewportDraw()只是当您在纸空间中通过一个视口查看过度的东西时使用的,但我想情况并非如此。如果您也在模型空间中,它也是有效的。
这就是我用来画一个盒子作为握把点的东西
public override bool ViewportDraw(Autodesk.AutoCAD.GraphicsInterface.ViewportDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, int gripSizeInPixels)
{
try
{
Point2d glyphSize = worldDraw.Viewport.GetNumPixelsInUnitSquare(this.GripPoint);
Double glyphHeight = (gripSizeInPixels / glyphSize.Y);
Matrix3d e2w = worldDraw.Viewport.EyeToWorldTransform;
Point3d pt = this.GripPoint.TransformBy(e2w);
Point3dCollection pnts = new Point3dCollection
{
new Point3d(pt.X - glyphHeight, pt.Y + (glyphHeight), pt.Z),
new Point3d(pt.X - glyphHeight, pt.Y - (glyphHeight), pt.Z),
new Point3d(pt.X + glyphHeight, pt.Y - (glyphHeight), pt.Z),
new Point3d(pt.X + glyphHeight, pt.Y + (glyphHeight), pt.Z),
new Point3d(pt.X - glyphHeight, pt.Y + (glyphHeight), pt.Z)
};
worldDraw.Geometry.DeviceContextPolygon(pnts);
return false;
}
catch
{
return base.ViewportDraw(worldDraw, entityId, type, imageGripPoint, gripSizeInPixels);
}
}https://stackoverflow.com/questions/74128262
复制相似问题