I have an OsnapOverrule working quite nicely, except when a command or entry needs to use an ObjectSnap known as a "deferred osnap", such as when issuing the Circle command with the TTR option. At this point, no osnaps are in place so the command gets stuck in a loop asking for the first tangent point. I should note that this code was derived from code found online by both Kean Walmsley and n.yuan, without whose help I wouldn't have made it this far.
So my question is, how can I pass the "deferred osnap" through my Overrrule? Or, how can I temporarily disable my overrule until it can actually be used?
When stepping through the code, the snapmode variable is set to ObjectSnapModes.ModeTangent during a normal Tangent call and passes through (the overrule only is used for Perpendicular osnaps) correctly. However, when the deferred tangent osnap should be used, the snapmode variable is set to "ObjectSnapModes.ModeEnd|ObjectSnapModes.ModePerpendicular" which does not pass through to the base.GetObjectSnapPoints() correctly...at least it does not function correctly in the drawing.
public class PerpOverrule : OsnapOverrule { private bool _overruling; private ObjectId _entId = ObjectId.Null; public PerpOverrule() { _overruling = Overruling; Overruling = true; Overrule.AddOverrule(RXClass.GetClass(typeof(Curve)), this, true); } public void Terminate() { Overrule.RemoveOverrule(RXClass.GetClass(typeof(Curve)), this); Overruling = _overruling; } public override void GetObjectSnapPoints(AcDb.Entity entity, ObjectSnapModes snapMode, IntPtr gsSelectionMark, Point3d pickPoint, Point3d lastPoint, Matrix3d viewTransform, Point3dCollection snapPoints, IntegerCollection geometryIds) { if (snapMode == ObjectSnapModes.ModePerpendicular) { Point3d pt1 = new Point3d(pickPoint.X, pickPoint.Y, 0); Point3d pt2 = new Point3d(lastPoint.X, lastPoint.Y, 0); Curve poly = (Curve)entity; Curve flattenedpoly = (Curve)poly.GetOrthoProjectedCurve(new Plane(new Point3d(0, 0, 0), Vector3d.ZAxis)); //some C3D objects derive from Curve but do not support the following line. try { base.GetObjectSnapPoints(flattenedpoly, snapMode, gsSelectionMark, pt1, pt2, viewTransform, snapPoints, geometryIds); } catch { } } else //it's any snapmode other than perpendicular { try { base.GetObjectSnapPoints(entity, snapMode, gsSelectionMark, pickPoint, lastPoint, viewTransform, snapPoints, geometryIds); } catch { } } } } public class PerpOverrideToggle { public static PerpOverrule perpoverride = null; [CommandMethod("Perp2dtoggle", CommandFlags.Transparent)] public void perptestcommand() { if (perpoverride == null) { perpoverride = new PerpOverrule(); Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n***Perpendicular set to 2d snapping only!***"); } else { perpoverride.Terminate(); Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n***Perpendicular set to default of 3d snapping!***"); perpoverride = null; } } }
Hi Jeff
ObjectSnapModes.ModeEnd|ObjectSnapModes.ModePerpendicular is correct, when you create a circle with TTR, automatically tangent snap is created and
ModeEnd +ModePerpendicular is tangent snap
ModeEnd = 1,
ModeMid = 2,
ModeCenter = 3,
ModeNode = 4,
ModeQuad = 5,
ModeIns = 7,
ModePerpendicular = 8,
ModeTangent = 9,
ModeNear = 10,
I'm working on this, with your overrule, I get following error only in case of circle with TTR.
*Requires a TAN object-snap and selection of Circle, Arc, or Line.
The problem is subjected to this particular context , I'm couldn't find a way to suspend the overrule for this context as it is difficult to isolate the behavior.
I 'll give it try for sometime.
Following code too behaves same, I'm not testing for snapmodes here, directly delegating to base class, which in case of circle-ttr goes for a toss.
public override void GetObjectSnapPoints(Entity entity, ObjectSnapModes snapMode, IntPtr gsSelectionMark, Point3d pickPoint, Point3d lastPoint, Matrix3d viewTransform, Point3dCollection snapPoints, IntegerCollection geometryIds) { base.GetObjectSnapPoints(entity, snapMode, gsSelectionMark, pickPoint, lastPoint, viewTransform, snapPoints, geometryIds);
@moogalm thank you for testing and the update. Yes, you are seeing the same thing I found. Additionaly, if you attempt to draw a line perpendicular FROM a line (so you are invoking the Deferred Perpendicular Osnap), it will not allow a point to be selected on the desired object as it does when the overrule is not active.
Looking forward to a possible solution to this issue.
Hi Jeff,
I tried to check with perpendicular osnap, I couldn't find a workflow to get deferred osnap [Osnap Icon underlined with ellipsis]
For the workflow I tried, I was able to get perpenicular osnaps correctly with your code.
@swaywood, I used same code available in this post above., if you have different requirement please a post a new question, we will try to address.
Hi,
Can you please tell me what is the name of you screen recorder? it looks so cool!
Thank you.
天涯海角的山姆
您认为此帖子是否有用?欢迎为此帖点赞。
您的问题是否已得到解答?请点击“接受解答”按钮。
Can't find what you're looking for? Ask the community or share your knowledge.