.NET

Reply
*Mark Johnston
Message 1 of 8 (134 Views)

Activity during drag

134 Views, 7 Replies
07-25-2006 01:22 PM
I'm writing a simple (I hope) C#.NET dll that will work with AutoCAD 2007
VBA.
The dll provides jig/ghost functionality.
What I have seems to work fine except that the object that is being dragged
flickers alot. It doesn't look like the native AutoCAD drag. This happens
even when the cursor is not being moved at all.
Also not everything shows for example attribute text.

Is there a trick to displaying the "ghosted" entities like AutoCAD native
commands do?

=Mark
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 2 of 8 (134 Views)

Re: Activity during drag

07-25-2006 03:34 PM in reply to: *Mark Johnston
Post your code. It sounds like you are not checking whether the cursor has moved.

Regards - Nathan
*Mark Johnston
Message 3 of 8 (134 Views)

Re: Activity during drag

07-25-2006 04:49 PM in reply to: *Mark Johnston
Here is the code. Some of it is borrowed from various examples.
I have a function that checks for cursor movement. The original
CursorHasMoved function didn't have a Tolerance argument.
The object didn't behave like I wanted so I added the "Tolerance" argument
to try to get the cursor to stop twitching when I wasn't moving it.
That didn't work. The objects twitched regardless of the Tolerance value
although it did not move until the Tolerance was met.

// HERE IS THE CODE
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;

[assembly: CommandClass(typeof(ClassLibrary.DragByID))]

namespace ClassLibrary
{
///
/// Summary description for WestClass.
///


public class DragByID
{
[ComVisible(true)]
public long myObjectID;
public double x;
public double y;
public double z;

public DragByID()
{
x = 0;
y = 0;
z = 0;
}

public bool DragIt()
{
if (myObjectID == 0) return false;
Point3d myPoint = new Point3d(x, y, z);
myJig oDrag = new myJig();
oDrag.DragDropObject(myObjectID, myPoint);
return true;
}

[ComVisible(false)]
public class myJig : DrawJig
{
#region private member fields
private Point3d previousCursorPosition;
private Point3d currentCursorPosition;
#endregion

public string entID;
private Entity entityToDrag;

public void DragDropObject(long oID, Point3d iPnt)
{
//Initialize cursor position
previousCursorPosition = iPnt; // new Point3d(x, y, z);
Database db =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Editor ed =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
db.TransactionManager;
using (Transaction aTran = tm.StartTransaction())
{
entityToDrag = (Entity)tm.GetObject(new
ObjectId((int)oID), OpenMode.ForWrite);
ed.Drag(this);
aTran.Commit();
}
}

protected override SamplerStatus Sampler(JigPrompts prompts)
{
//Get the current cursor position
PromptPointResult userFeedback = prompts.AcquirePoint();
currentCursorPosition = userFeedback.Value;

if (CursorHasMoved(1))
{
Vector3d displacementVector =
currentCursorPosition.GetVectorTo(previousCursorPosition);

displacementVector = displacementVector.MultiplyBy(-1);
entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));

previousCursorPosition = currentCursorPosition;

return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}

protected override bool WorldDraw(WorldDraw draw)
{
draw.Geometry.Draw(entityToDrag);
return true;
}

private bool CursorHasMoved(double Tolerance)
{
double xDiff;
double yDiff;
double zDiff;
xDiff = currentCursorPosition.X - previousCursorPosition.X;
yDiff = currentCursorPosition.Y - previousCursorPosition.Y;
zDiff = currentCursorPosition.Z - previousCursorPosition.Z;
if (xDiff < 0) xDiff = xDiff * -1;
if (yDiff < 0) yDiff = yDiff * -1;
if (zDiff < 0) zDiff = zDiff * -1;
return ((xDiff + yDiff + zDiff) > Tolerance);
}
}
}
}
// END OF THE CODE

wrote in message news:5248331@discussion.autodesk.com...
Post your code. It sounds like you are not checking whether the cursor has
moved.

Regards - Nathan
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 4 of 8 (134 Views)

Re: Activity during drag

07-25-2006 06:06 PM in reply to: *Mark Johnston
I can't see anything wrong with your code. I haven't tried yours but I have a VB block insert example that does not twitch. Checking a tolerance should be unnecessary.

Regards - Nathan
*Mark Johnston
Message 5 of 8 (134 Views)

Re: Activity during drag

07-26-2006 10:15 AM in reply to: *Mark Johnston
Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan
*Bobby C. Jones
Message 6 of 8 (134 Views)

Re: Activity during drag

07-26-2006 11:54 AM in reply to: *Mark Johnston
Hey Mark,
I'm no Tony, but maybe I can help.

You are transforming a database resident object with each move of the mouse.
Your jig should be working with non db resident objects. Check out this
example http://www.theswamp.org/index.php?topic=8198.0, just note that I
never did finish this to my liking. Run it and move your mouse out of the
drawing area to see what I mean.

However, since you are targeting 2007, you can use the overloaded Drag
method that wraps acedDragGen().

public class EntityDragger
{
private Point3d m_basePoint;
[CommandMethod("dragSS")]
public void SsDragger()
{
Editor currentEditor = acadApp.DocumentManager.MdiActiveDocument.Editor;
//Create a new selection set options object
PromptSelectionOptions ssOptions = new PromptSelectionOptions();
ssOptions.AllowDuplicates = true;
ssOptions.MessageForAdding = "Select objects to copy: ";
//Get a selection from the user
PromptSelectionResult ssResult = currentEditor.GetSelection(ssOptions);
if (ssResult.Status != PromptStatus.OK)
{
return;
}
//Get a base point from the user
PromptPointResult pointResult = currentEditor.GetPoint("\nSelect base point:
");
if (pointResult.Status != PromptStatus.OK)
{
return;
}
m_basePoint = pointResult.Value;
//Initiate the drag callback delegate
DragCallback dragCallbackDelegate = this.FollowCursor;
//Start the drag operation
PromptDragOptions dragOptions = new PromptDragOptions(ssResult.Value,
"\nSelect destination point: ", dragCallbackDelegate);
PromptPointResult destinationPointResult = currentEditor.Drag(dragOptions);
if (destinationPointResult.Status != PromptStatus.OK)
{
return;
}
//Determine the final displacement matrix
Matrix3d transMat =
Matrix3d.Displacement(m_basePoint.GetVectorTo(destinationPointResult.Value));
//transform the ss to the new location
this.TransformSelectionSet(ssResult.Value, transMat);
}

//DragCallback Delegate
public SamplerStatus FollowCursor(Point3d currentPoint, ref Matrix3d
transMat)
{
transMat = Matrix3d.Displacement(m_basePoint.GetVectorTo(currentPoint));
return SamplerStatus.OK;
}
}

Also note that they fixed the GetVectorTo() method in 07; this:

Vector3d displacementVector =
currentCursorPosition.GetVectorTo(previousCursorPosition);
displacementVector = displacementVector.MultiplyBy(-1);

can be replaced with this:
Vector3d displacementVector =
previousCursorPosition.GetVectorTo(currentCursorPosition);

p.s. - I just saw that you posted over in the swamp. I'll post this code
there so you can see it with some formatting.
--
Bobby C. Jones


"Mark Johnston" wrote in message
news:5249253@discussion.autodesk.com...
Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan
*Tony Tanzillo
Message 7 of 8 (134 Views)

Re: Activity during drag

07-26-2006 08:52 PM in reply to: *Mark Johnston
Hi Mark - If you can post a complete working project (including
the code needed to select the objects, and do the dragging),
I might be able to take a look at it, but what you posted is
not a complete working sample, and it would require coding
to test.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Mark Johnston" wrote in message news:5249253@discussion.autodesk.com...
Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan
*Mark Johnston
Message 8 of 8 (134 Views)

Re: Activity during drag

07-27-2006 11:15 AM in reply to: *Mark Johnston
Attached is the .NET project along with a VBA module to add to a VBA
project.
I'm not doing an on-screen select of objects but am creating them in VBA.
You will need to have a TestBlock.dwg file on C: or change the hard-coded
path in the VBA module.

Thanks


"Tony Tanzillo" wrote in message
news:5249916@discussion.autodesk.com...
Hi Mark - If you can post a complete working project (including
the code needed to select the objects, and do the dragging),
I might be able to take a look at it, but what you posted is
not a complete working sample, and it would require coding
to test.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Mark Johnston" wrote in message
news:5249253@discussion.autodesk.com...
Thanks Nathan,
I did see your VB example. I was hoping to do this in C# but I may just
build on your example. I agree that checking for amount of movement should
be unnecessary. It was something I did just to see what would happen.
(hoping for a clue)

Maybe a reader with experience in C# can point me in the right direction.
(hint Tony)

wrote in message news:5248434@discussion.autodesk.com...
I can't see anything wrong with your code. I haven't tried yours but I have
a VB block insert example that does not twitch. Checking a tolerance should
be unnecessary.

Regards - Nathan

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community