I already had a thread about my attempts at GripOverrule's but that question was answered so I figured I would keep this new question separate.
I have a GripOverrule working for BlockReferences, the custom grip points display on the block and I can grab them. Now I'm trying to figure out how to react to one of those points being moved.
There is the MoveGripPointsAt() method to override, but it appears that that method gets called continuously while the point is selected and being moved.
I would like to wait until the grip has been clicked somewhere to then react to where that grip moved.
How would I go about this?
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
How your custom grip created with GripOverrule behave is defined in your GripData drived custom GripData class, not in the GripOverrule.
For example, in your case, you may expect user to click your custom grip and move the mouse to another location and click there, then the block reference is moved to the new location.
In this case, you need to do is to override the GripData.OnHotGrip() method, where you simply call whatever action you want to happen, for example:
public override ReturnValue OnHotGrip(ObjectId entityId, Context contextFlags)
{
var dwg = CadApp.DocumentManager.MdiActiveDocument;
using (dwg.LockDocument())
{
MoveEntity(entityId, GridpPoint, dwg.Editor);
}
return ReturnValue.GetNewGripPoints;
}
private void MoveEntity(ObjectId entId, Point3d basePoint, Editor ed)
{
var opt=new PromptPointOption("\nSelect position to move to:");
opt.UseBasePoint = true;
opt.BasePoint=basePoint;
opt.UserDashedLine=true;
var res=ed.GetPoint(opt);
if (res.Stats != Prompt.OK) return;
var mt=Matrix3d.Displacement(basePoint.GetVectorTo(res.Value));
// now use this Matrix to transform the entity
... ...
}
Norman Yuan
Thank you @norman.yuan, I think this will definitely help. One small question if you don't mind; When is it necessary to Lock a document, and is it important to prevent something from going wrong?
AutoCAD locks document when a command is called (as long as the command is not flagged as Session command). So, in most cases, our .NET code runs inside a CommandMethod does not not need to lock document. However, with the code being executed in event handler, or in this GridData.OnHotGrip(), you need lock the document if the code changes database (in this case, an entity in database), or AutoCAD would throw eLockException. It is AutoCAD's way to keep the database' integration. For us, it is just we need to get execution going without getting eLockException error, thus the need to call Document.LockDocument().
Norman Yuan
Can't find what you're looking for? Ask the community or share your knowledge.