GripOverrule problem
Hi,I have written own GripOverrule and GripData with custom grip points. Every thing is worikng in programic way. But I'm stuck with one thing. I have requirement to set stretch point by typing delta X and delta Y (as it is presented on attached picture). I have tried to use GetHotGripDimensionData in similar way as in jig but it doesn't work and after command autocad present critical error. Does anybody have idei how to achive desire functionality?
Thanks You will need to post some code so people can review it for errors and/or omissions .
Do you mean Stretch point(ie rescale)or Move point ? ... you may also need to clarify your intent. it's ok guys, i'll take the lead on this one #include
AcadApplication.AcadPreferences.AcadPreferencesSelection;
method properties loop array :: endl;
system("pause");
Well, I am not filo327, but I have the exact same question so I'll continue this discussion. Hopefully, since I'm giving some sample code, I will get a more direct response.
This sample overrides the base Line Grips with a single grip on the line's endpoint. I need to be able to allow the user to enter the movement in the X and/or Y directions when DynamicInput is on. Similar to how this ADN c++ example does for a circle. I'm thinking it will need 2 dynamic dimensions (X & Y) that update as the grip is stretched but also allow the user to input a value for either one. Unfortunately, I'm drawing a blank on HOW to achieve this in c#. (Note - Code below started life as an example on the ADN blog, used as a guide by user CivilReminders for use in a commercial product, then stripped down to use for this inquiry.)
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
namespace Test_Commands.GripTest
{
public class GripTest
{
private static bool ShouldBeOn = false;
public void griptestCommand()
{
if (ShouldBeOn)
{
ShouldBeOn = false;
RemoveOverrule();
}
else
{
ShouldBeOn = true;
AddOverrule();
}
}
// Added for grips for line
public static TestGripsOverrule mGripOverrule;
public static void AddOverrule()
{
if (ShouldBeOn)
{
// Instantiate our global Overrule and set it to overrule lines with my data attached
mGripOverrule = new TestGripsOverrule();
Overrule.AddOverrule(RXObject.GetClass(typeof(Line)), mGripOverrule, false);
//Turn overruling on
Overrule.Overruling = true;
}
}
public static void RemoveOverrule()
{
if (!ShouldBeOn)
{
Overrule.RemoveOverrule(RXObject.GetClass(typeof(Line)), mGripOverrule);
mGripOverrule = null;
}
}
}
//Grip overrule to add our custom grips to the profile view
public class TestGripsOverrule : GripOverrule
{
public static short gripcolor { get; set; }
//Our custom grip class
//(Could have derived one class for each grip, but we'll use member data (Ordinal property) to distinguish grips instead)
public class MyGrip : GripData
{
private int mGripNum;
public int Ordinal
{
get { return mGripNum; }
set { mGripNum = value; }
}
public override bool ViewportDraw(ViewportDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, int gripSizeInPixels)
{
Point2d unit = worldDraw.Viewport.GetNumPixelsInUnitSquare(GripPoint);
var gripPolygonPts = new Point3dCollection();
double lengthVal = 1.20 * gripSizeInPixels / unit.X;
gripPolygonPts.Add(new Point3d(GripPoint.X, GripPoint.Y + lengthVal, 0));
gripPolygonPts.Add(new Point3d(GripPoint.X + lengthVal, GripPoint.Y, 0));
gripPolygonPts.Add(new Point3d(GripPoint.X, GripPoint.Y - lengthVal, 0));
gripPolygonPts.Add(new Point3d(GripPoint.X - lengthVal, GripPoint.Y, 0));
// Polygon properties
worldDraw.SubEntityTraits.Color = gripcolor;
worldDraw.SubEntityTraits.FillType = FillType.FillAlways;
worldDraw.Geometry.Polygon(gripPolygonPts);
return true;
}
}
//Array to hold our grip
public GripData[] mGripData = new GripData;
public override void GetGripPoints(Autodesk.AutoCAD.DatabaseServices.Entity entity, Autodesk.AutoCAD.DatabaseServices.GripDataCollection grips, double curViewUnitSize, int gripSize, Autodesk.AutoCAD.Geometry.Vector3d curViewDir, Autodesk.AutoCAD.DatabaseServices.GetGripPointsFlags bitFlags)
{
//We assume entity is a profile view
Line line = entity as Line;
if (line == null)
return;
gripcolor = (short)Application.GetSystemVariable("GRIPHOT");
// Set point at end of line
MyGrip grip = new MyGrip();
grip.Ordinal = 0;
mGripData = grip;
UpdateGripLocations(line);
//Add our grips to the list
foreach (MyGrip g in mGripData)
{
grips.Add(g);
}
//Get the standard line grip points as well, but not wanted for this test
//base.GetGripPoints(entity, grips, curViewUnitSize, gripSize, curViewDir, bitFlags);
}
public override void MoveGripPointsAt(Autodesk.AutoCAD.DatabaseServices.Entity entity, GripDataCollection grips,
Vector3d offset, MoveGripPointsFlags bitFlags)
{
//We only takeaction when we get this call on a database resident entity
//Dragging operation makes shallow clone of line, and setting clomeMeForDragging to false is generally a bad idea.
//(If you do set clone me for dragging to false, then don't call base class overriden methods).
try
{
if (entity.Id.IsValid)
{
var line = entity as Line;
//Iterate through list of all grips being moved
foreach (GripData g in grips)
{
if (g is MyGrip)
{
MyGrip grip = g as MyGrip;
//Cast to our grip type
double newX = g.GripPoint.X + offset.X;
double newY = g.GripPoint.Y + offset.Y;
switch (grip.Ordinal)
{
case 0:
line.EndPoint = new Point3d(newX, newY, line.EndPoint.Z);
break;
default:
break;
}
//Tell grip to move itself long the line
UpdateGripLocations(line);
}
}
}
}
catch (System.Exception)
{
}
}
private void UpdateGripLocations(Line line)
{
Point3d pt = new Point3d(line.EndPoint.X, line.EndPoint.Y, 0);
mGripData.GripPoint = pt;
}
}
}
I would think that support for Dynamic Dimensions requires a Jig, because only there is a way designated to tell AutoCAD about them:
virtual DynamicDimensionDataCollection GetDynamicDimensionData(double dimScale)
页:
[1]